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
: '',
44 _NumericDataTypesList
= ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN']
47 gDynamicPcd
= [TAB_PCDS_DYNAMIC
, TAB_PCDS_DYNAMIC_DEFAULT
, TAB_PCDS_DYNAMIC_VPD
, TAB_PCDS_DYNAMIC_HII
]
49 ## Dynamic-ex PCD types
50 gDynamicExPcd
= [TAB_PCDS_DYNAMIC_EX
, TAB_PCDS_DYNAMIC_EX_DEFAULT
, TAB_PCDS_DYNAMIC_EX_VPD
, TAB_PCDS_DYNAMIC_EX_HII
]
53 gDatumSizeStringDatabase
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOLEAN','VOID*':'8'}
54 gDatumSizeStringDatabaseH
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'BOOL','VOID*':'PTR'}
55 gDatumSizeStringDatabaseLib
= {'UINT8':'8','UINT16':'16','UINT32':'32','UINT64':'64','BOOLEAN':'Bool','VOID*':'Ptr'}
57 ## AutoGen File Header Templates
58 gAutoGenHeaderString
= TemplateString("""\
64 Abstract: Auto-generated ${FileName} for building module or library.
68 gAutoGenHPrologueString
= TemplateString("""
69 #ifndef _${File}_${Guid}
70 #define _${File}_${Guid}
74 gAutoGenHCppPrologueString
= """\
81 gAutoGenHEpilogueString
= """
90 ## PEI Core Entry Point Templates
91 gPeiCoreEntryPointPrototype
= TemplateString("""
96 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
97 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
103 gPeiCoreEntryPointString
= TemplateString("""
107 ProcessModuleEntryPointList (
108 IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
109 IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
114 ${Function} (SecCoreData, PpiList, Context);
120 ## DXE Core Entry Point Templates
121 gDxeCoreEntryPointPrototype
= TemplateString("""
131 gDxeCoreEntryPointString
= TemplateString("""
135 ProcessModuleEntryPointList (
140 ${Function} (HobStart);
145 ## PEIM Entry Point Templates
146 gPeimEntryPointPrototype
= TemplateString("""
151 IN EFI_PEI_FILE_HANDLE FileHandle,
152 IN CONST EFI_PEI_SERVICES **PeiServices
157 gPeimEntryPointString
= [
159 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
163 ProcessModuleEntryPointList (
164 IN EFI_PEI_FILE_HANDLE FileHandle,
165 IN CONST EFI_PEI_SERVICES **PeiServices
173 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
177 ProcessModuleEntryPointList (
178 IN EFI_PEI_FILE_HANDLE FileHandle,
179 IN CONST EFI_PEI_SERVICES **PeiServices
183 return ${Function} (FileHandle, PeiServices);
188 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = ${PiSpecVersion};
192 ProcessModuleEntryPointList (
193 IN EFI_PEI_FILE_HANDLE FileHandle,
194 IN CONST EFI_PEI_SERVICES **PeiServices
199 EFI_STATUS CombinedStatus;
201 CombinedStatus = EFI_LOAD_ERROR;
203 Status = ${Function} (FileHandle, PeiServices);
204 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
205 CombinedStatus = Status;
208 return CombinedStatus;
213 ## SMM_CORE Entry Point Templates
214 gSmmCoreEntryPointPrototype
= TemplateString("""
219 IN EFI_HANDLE ImageHandle,
220 IN EFI_SYSTEM_TABLE *SystemTable
225 gSmmCoreEntryPointString
= TemplateString("""
227 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
228 const UINT32 _gDxeRevision = ${PiSpecVersion};
232 ProcessModuleEntryPointList (
233 IN EFI_HANDLE ImageHandle,
234 IN EFI_SYSTEM_TABLE *SystemTable
237 return ${Function} (ImageHandle, SystemTable);
242 ## MM_CORE_STANDALONE Entry Point Templates
243 gMmCoreStandaloneEntryPointPrototype
= TemplateString("""
253 gMmCoreStandaloneEntryPointString
= TemplateString("""
255 const UINT32 _gMmRevision = ${PiSpecVersion};
259 ProcessModuleEntryPointList (
263 ${Function} (HobStart);
268 ## MM_STANDALONE Entry Point Templates
269 gMmStandaloneEntryPointPrototype
= TemplateString("""
274 IN EFI_HANDLE ImageHandle,
275 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
280 gMmStandaloneEntryPointString
= [
282 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
286 ProcessModuleEntryPointList (
287 IN EFI_HANDLE ImageHandle,
288 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
296 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
300 ProcessModuleEntryPointList (
301 IN EFI_HANDLE ImageHandle,
302 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
306 return ${Function} (ImageHandle, MmSystemTable);
311 GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = ${PiSpecVersion};
315 ProcessModuleEntryPointList (
316 IN EFI_HANDLE ImageHandle,
317 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
322 EFI_STATUS CombinedStatus;
324 CombinedStatus = EFI_LOAD_ERROR;
326 Status = ${Function} (ImageHandle, MmSystemTable);
327 if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
328 CombinedStatus = Status;
331 return CombinedStatus;
336 ## DXE SMM Entry Point Templates
337 gDxeSmmEntryPointPrototype
= TemplateString("""
342 IN EFI_HANDLE ImageHandle,
343 IN EFI_SYSTEM_TABLE *SystemTable
348 gDxeSmmEntryPointString
= [
350 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
351 const UINT32 _gDxeRevision = ${PiSpecVersion};
355 ProcessModuleEntryPointList (
356 IN EFI_HANDLE ImageHandle,
357 IN EFI_SYSTEM_TABLE *SystemTable
365 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
366 const UINT32 _gDxeRevision = ${PiSpecVersion};
368 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
369 static EFI_STATUS mDriverEntryPointStatus;
377 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
378 mDriverEntryPointStatus = Status;
380 LongJump (&mJumpContext, (UINTN)-1);
386 ProcessModuleEntryPointList (
387 IN EFI_HANDLE ImageHandle,
388 IN EFI_SYSTEM_TABLE *SystemTable
391 mDriverEntryPointStatus = EFI_LOAD_ERROR;
394 if (SetJump (&mJumpContext) == 0) {
395 ExitDriver (${Function} (ImageHandle, SystemTable));
400 return mDriverEntryPointStatus;
405 ## UEFI Driver Entry Point Templates
406 gUefiDriverEntryPointPrototype
= TemplateString("""
411 IN EFI_HANDLE ImageHandle,
412 IN EFI_SYSTEM_TABLE *SystemTable
417 gUefiDriverEntryPointString
= [
419 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
420 const UINT32 _gDxeRevision = ${PiSpecVersion};
424 ProcessModuleEntryPointList (
425 IN EFI_HANDLE ImageHandle,
426 IN EFI_SYSTEM_TABLE *SystemTable
433 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
434 const UINT32 _gDxeRevision = ${PiSpecVersion};
439 ProcessModuleEntryPointList (
440 IN EFI_HANDLE ImageHandle,
441 IN EFI_SYSTEM_TABLE *SystemTable
445 return ${Function} (ImageHandle, SystemTable);
454 if (EFI_ERROR (Status)) {
455 ProcessLibraryDestructorList (gImageHandle, gST);
457 gBS->Exit (gImageHandle, Status, 0, NULL);
461 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
462 const UINT32 _gDxeRevision = ${PiSpecVersion};
464 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
465 static EFI_STATUS mDriverEntryPointStatus;
469 ProcessModuleEntryPointList (
470 IN EFI_HANDLE ImageHandle,
471 IN EFI_SYSTEM_TABLE *SystemTable
474 mDriverEntryPointStatus = EFI_LOAD_ERROR;
476 if (SetJump (&mJumpContext) == 0) {
477 ExitDriver (${Function} (ImageHandle, SystemTable));
481 return mDriverEntryPointStatus;
490 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
491 mDriverEntryPointStatus = Status;
493 LongJump (&mJumpContext, (UINTN)-1);
500 ## UEFI Application Entry Point Templates
501 gUefiApplicationEntryPointPrototype
= TemplateString("""
506 IN EFI_HANDLE ImageHandle,
507 IN EFI_SYSTEM_TABLE *SystemTable
512 gUefiApplicationEntryPointString
= [
514 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
518 ProcessModuleEntryPointList (
519 IN EFI_HANDLE ImageHandle,
520 IN EFI_SYSTEM_TABLE *SystemTable
527 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
532 ProcessModuleEntryPointList (
533 IN EFI_HANDLE ImageHandle,
534 IN EFI_SYSTEM_TABLE *SystemTable
538 return ${Function} (ImageHandle, SystemTable);
547 if (EFI_ERROR (Status)) {
548 ProcessLibraryDestructorList (gImageHandle, gST);
550 gBS->Exit (gImageHandle, Status, 0, NULL);
554 const UINT32 _gUefiDriverRevision = ${UefiSpecVersion};
558 ProcessModuleEntryPointList (
559 IN EFI_HANDLE ImageHandle,
560 IN EFI_SYSTEM_TABLE *SystemTable
565 if (SetJump (&mJumpContext) == 0) {
566 ExitDriver (${Function} (ImageHandle, SystemTable));
570 return mDriverEntryPointStatus;
573 static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
574 static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
582 if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
583 mDriverEntryPointStatus = Status;
585 LongJump (&mJumpContext, (UINTN)-1);
591 ## UEFI Unload Image Templates
592 gUefiUnloadImagePrototype
= TemplateString("""
597 IN EFI_HANDLE ImageHandle
602 gUefiUnloadImageString
= [
604 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
608 ProcessModuleUnloadList (
609 IN EFI_HANDLE ImageHandle
616 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
621 ProcessModuleUnloadList (
622 IN EFI_HANDLE ImageHandle
625 return ${Function} (ImageHandle);
630 GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = ${Count};
634 ProcessModuleUnloadList (
635 IN EFI_HANDLE ImageHandle
640 Status = EFI_SUCCESS;
642 if (EFI_ERROR (Status)) {
643 ${Function} (ImageHandle);
645 Status = ${Function} (ImageHandle);
653 gLibraryStructorPrototype
= {
654 'BASE' : TemplateString("""${BEGIN}
662 'PEI' : TemplateString("""${BEGIN}
666 IN EFI_PEI_FILE_HANDLE FileHandle,
667 IN CONST EFI_PEI_SERVICES **PeiServices
671 'DXE' : TemplateString("""${BEGIN}
675 IN EFI_HANDLE ImageHandle,
676 IN EFI_SYSTEM_TABLE *SystemTable
680 'MM' : TemplateString("""${BEGIN}
684 IN EFI_HANDLE ImageHandle,
685 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
690 gLibraryStructorCall
= {
691 'BASE' : TemplateString("""${BEGIN}
692 Status = ${Function} ();
693 ASSERT_EFI_ERROR (Status);${END}
696 'PEI' : TemplateString("""${BEGIN}
697 Status = ${Function} (FileHandle, PeiServices);
698 ASSERT_EFI_ERROR (Status);${END}
701 'DXE' : TemplateString("""${BEGIN}
702 Status = ${Function} (ImageHandle, SystemTable);
703 ASSERT_EFI_ERROR (Status);${END}
706 'MM' : TemplateString("""${BEGIN}
707 Status = ${Function} (ImageHandle, MmSystemTable);
708 ASSERT_EFI_ERROR (Status);${END}
712 ## Library Constructor and Destructor Templates
714 'BASE' : TemplateString("""
715 ${BEGIN}${FunctionPrototype}${END}
719 ProcessLibrary${Type}List (
723 ${BEGIN} EFI_STATUS Status;
724 ${FunctionCall}${END}
728 'PEI' : TemplateString("""
729 ${BEGIN}${FunctionPrototype}${END}
733 ProcessLibrary${Type}List (
734 IN EFI_PEI_FILE_HANDLE FileHandle,
735 IN CONST EFI_PEI_SERVICES **PeiServices
738 ${BEGIN} EFI_STATUS Status;
739 ${FunctionCall}${END}
743 'DXE' : TemplateString("""
744 ${BEGIN}${FunctionPrototype}${END}
748 ProcessLibrary${Type}List (
749 IN EFI_HANDLE ImageHandle,
750 IN EFI_SYSTEM_TABLE *SystemTable
753 ${BEGIN} EFI_STATUS Status;
754 ${FunctionCall}${END}
758 'MM' : TemplateString("""
759 ${BEGIN}${FunctionPrototype}${END}
763 ProcessLibrary${Type}List (
764 IN EFI_HANDLE ImageHandle,
765 IN EFI_SMM_SYSTEM_TABLE2 *MmSystemTable
768 ${BEGIN} EFI_STATUS Status;
769 ${FunctionCall}${END}
774 gBasicHeaderFile
= "Base.h"
776 gModuleTypeHeaderFile
= {
777 "BASE" : [gBasicHeaderFile
],
778 "SEC" : ["PiPei.h", "Library/DebugLib.h"],
779 "PEI_CORE" : ["PiPei.h", "Library/DebugLib.h", "Library/PeiCoreEntryPoint.h"],
780 "PEIM" : ["PiPei.h", "Library/DebugLib.h", "Library/PeimEntryPoint.h"],
781 "DXE_CORE" : ["PiDxe.h", "Library/DebugLib.h", "Library/DxeCoreEntryPoint.h"],
782 "DXE_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
783 "DXE_SMM_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
784 "DXE_RUNTIME_DRIVER": ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
785 "DXE_SAL_DRIVER" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
786 "UEFI_DRIVER" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiDriverEntryPoint.h"],
787 "UEFI_APPLICATION" : ["Uefi.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiBootServicesTableLib.h", "Library/UefiApplicationEntryPoint.h"],
788 "SMM_CORE" : ["PiDxe.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/UefiDriverEntryPoint.h"],
789 "MM_STANDALONE" : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmDriverStandaloneEntryPoint.h"],
790 "MM_CORE_STANDALONE" : ["PiSmm.h", "Library/BaseLib.h", "Library/DebugLib.h", "Library/SmmCoreStandaloneEntryPoint.h"],
791 "USER_DEFINED" : [gBasicHeaderFile
]
794 ## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
795 # the TokenName and Guid comparison to avoid define name collisions.
797 # @param Info The ModuleAutoGen object
798 # @param AutoGenH The TemplateString object for header file
801 def DynExPcdTokenNumberMapping(Info
, AutoGenH
):
802 ExTokenCNameList
= []
804 # Even it is the Library, the PCD is saved in the ModulePcdList
805 PcdList
= Info
.ModulePcdList
807 if Pcd
.Type
in gDynamicExPcd
:
808 ExTokenCNameList
.append(Pcd
.TokenCName
)
809 PcdExList
.append(Pcd
)
810 if len(ExTokenCNameList
) == 0:
812 AutoGenH
.Append('\n#define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1))\n')
813 # AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
814 # Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
815 # Use the Guid pointer to see if it matches any of the token space GUIDs.
817 for TokenCName
in ExTokenCNameList
:
818 if TokenCName
in TokenCNameList
:
821 Count
= ExTokenCNameList
.count(TokenCName
)
822 for Pcd
in PcdExList
:
823 RealTokenCName
= Pcd
.TokenCName
824 for PcdItem
in GlobalData
.MixedPcd
:
825 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
826 RealTokenCName
= PcdItem
[0]
828 if Pcd
.TokenCName
== TokenCName
:
831 AutoGenH
.Append('\n#define __PCD_%s_ADDR_CMP(GuidPtr) (' % (RealTokenCName
))
832 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
833 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
835 AutoGenH
.Append('\\\n (GuidPtr == &%s) ? _PCD_TOKEN_%s_%s:'
836 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
838 AutoGenH
.Append('0 \\\n )\n')
839 TokenCNameList
.append(TokenCName
)
842 for TokenCName
in ExTokenCNameList
:
843 if TokenCName
in TokenCNameList
:
846 Count
= ExTokenCNameList
.count(TokenCName
)
847 for Pcd
in PcdExList
:
848 RealTokenCName
= Pcd
.TokenCName
849 for PcdItem
in GlobalData
.MixedPcd
:
850 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
851 RealTokenCName
= PcdItem
[0]
853 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenCName
== TokenCName
:
856 AutoGenH
.Append('\n#define __PCD_%s_VAL_CMP(GuidPtr) (' % (RealTokenCName
))
857 AutoGenH
.Append('\\\n (GuidPtr == NULL) ? 0:')
858 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
859 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
861 AutoGenH
.Append('\\\n COMPAREGUID (GuidPtr, &%s) ? _PCD_TOKEN_%s_%s:'
862 % (Pcd
.TokenSpaceGuidCName
, Pcd
.TokenSpaceGuidCName
, RealTokenCName
))
864 AutoGenH
.Append('0 \\\n )\n')
865 # Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
866 # Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
867 # can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
868 # COMPAREGUID() will only be used if the Guid passed in is local to the module.
869 AutoGenH
.Append('#define _PCD_TOKEN_EX_%s(GuidPtr) __PCD_%s_ADDR_CMP(GuidPtr) ? __PCD_%s_ADDR_CMP(GuidPtr) : __PCD_%s_VAL_CMP(GuidPtr) \n'
870 % (RealTokenCName
, RealTokenCName
, RealTokenCName
, RealTokenCName
))
871 TokenCNameList
.append(TokenCName
)
874 if Pcd
.DatumType
not in _NumericDataTypesList
:
875 Value
= Pcd
.DefaultValue
876 if Value
in [None, '']:
878 elif Value
[0] == 'L':
879 return (len(Value
) - 2) * 2
880 elif Value
[0] == '{':
881 return len(Value
.split(','))
883 return len(Value
) - 1
884 if Pcd
.DatumType
== 'UINT64':
886 if Pcd
.DatumType
== 'UINT32':
888 if Pcd
.DatumType
== 'UINT16':
890 if Pcd
.DatumType
== 'UINT8':
892 if Pcd
.DatumType
== 'BOOLEAN':
895 return Pcd
.MaxDatumSize
898 ## Create code for module PCDs
900 # @param Info The ModuleAutoGen object
901 # @param AutoGenC The TemplateString object for C code
902 # @param AutoGenH The TemplateString object for header file
903 # @param Pcd The PCD object
905 def CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
906 TokenSpaceGuidValue
= Pcd
.TokenSpaceGuidValue
#Info.GuidList[Pcd.TokenSpaceGuidCName]
907 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
911 TokenCName
= Pcd
.TokenCName
912 for PcdItem
in GlobalData
.MixedPcd
:
913 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
914 TokenCName
= PcdItem
[0]
916 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
917 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
918 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
919 PatchPcdMaxSizeVariable
= '_gPcd_BinaryPatch_MaxSize_' + TokenCName
920 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
921 FixedPcdSizeVariableName
= '_gPcd_FixedAtBuild_Size_' + TokenCName
923 if Pcd
.PcdValueFromComm
:
924 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
926 if Pcd
.Type
in gDynamicExPcd
:
927 TokenNumber
= int(Pcd
.TokenValue
, 0)
928 # Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
929 # different Guids but same TokenCName
930 PcdExTokenName
= '_PCD_TOKEN_' + Pcd
.TokenSpaceGuidCName
+ '_' + TokenCName
931 AutoGenH
.Append('\n#define %s %dU\n' % (PcdExTokenName
, TokenNumber
))
933 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
934 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
935 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
936 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
937 # report warning message notify the PI that they are attempting to build a module
938 # that must be included in a flash image in order to be functional. These Dynamic PCD
939 # will not be added into the Database unless it is used by other modules that are
940 # included in the FDF file.
941 # In this case, just assign an invalid token number to make it pass build.
942 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
945 EdkLogger
.error("build", AUTOGEN_ERROR
,
946 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
947 ExtraData
="[%s]" % str(Info
))
949 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
950 AutoGenH
.Append('\n#define %s %dU\n' % (PcdTokenName
, TokenNumber
))
952 EdkLogger
.debug(EdkLogger
.DEBUG_3
, "Creating code for " + TokenCName
+ "." + Pcd
.TokenSpaceGuidCName
)
953 if Pcd
.Type
not in gItemTypeStringDatabase
:
954 EdkLogger
.error("build", AUTOGEN_ERROR
,
955 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
956 ExtraData
="[%s]" % str(Info
))
958 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
['VOID*']
959 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
['VOID*']
960 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
961 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
962 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_S_' + TokenCName
963 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
966 if Pcd
.Type
in gDynamicExPcd
:
968 PcdList
= Info
.LibraryPcdList
970 PcdList
= Info
.ModulePcdList
971 for PcdModule
in PcdList
:
972 if PcdModule
.Type
in gDynamicExPcd
:
973 PcdExCNameList
.append(PcdModule
.TokenCName
)
974 # Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
975 # If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
976 # If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
977 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
978 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')
979 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
980 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
981 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
982 if Pcd
.DatumType
not in _NumericDataTypesList
:
983 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
984 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
986 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
987 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
989 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
990 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
991 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
992 if Pcd
.DatumType
not in _NumericDataTypesList
:
993 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
994 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
996 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
997 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
998 elif Pcd
.Type
in gDynamicPcd
:
1001 PcdList
.extend(Info
.LibraryPcdList
)
1002 PcdList
.extend(Info
.ModulePcdList
)
1003 for PcdModule
in PcdList
:
1004 if PcdModule
.Type
in gDynamicPcd
:
1005 PcdCNameList
.append(PcdModule
.TokenCName
)
1006 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1007 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
))
1009 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1010 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1011 if Pcd
.DatumType
not in _NumericDataTypesList
:
1012 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1013 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1015 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1016 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1018 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1020 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1024 Value
= Pcd
.DefaultValue
1028 if Pcd
.DatumType
== 'BOOLEAN':
1029 BoolValue
= Value
.upper()
1030 if BoolValue
== 'TRUE' or BoolValue
== '1':
1032 elif BoolValue
== 'FALSE' or BoolValue
== '0':
1035 if Pcd
.DatumType
in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
1037 if Value
.upper().endswith('L'):
1039 ValueNumber
= int (Value
, 0)
1041 EdkLogger
.error("build", AUTOGEN_ERROR
,
1042 "PCD value is not valid dec or hex number for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1043 ExtraData
="[%s]" % str(Info
))
1044 if Pcd
.DatumType
== 'UINT64':
1046 EdkLogger
.error("build", AUTOGEN_ERROR
,
1047 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1048 ExtraData
="[%s]" % str(Info
))
1049 elif ValueNumber
>= 0x10000000000000000:
1050 EdkLogger
.error("build", AUTOGEN_ERROR
,
1051 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1052 ExtraData
="[%s]" % str(Info
))
1053 if not Value
.endswith('ULL'):
1055 elif Pcd
.DatumType
== 'UINT32':
1057 EdkLogger
.error("build", AUTOGEN_ERROR
,
1058 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1059 ExtraData
="[%s]" % str(Info
))
1060 elif ValueNumber
>= 0x100000000:
1061 EdkLogger
.error("build", AUTOGEN_ERROR
,
1062 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1063 ExtraData
="[%s]" % str(Info
))
1064 if not Value
.endswith('U'):
1066 elif Pcd
.DatumType
== 'UINT16':
1068 EdkLogger
.error("build", AUTOGEN_ERROR
,
1069 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1070 ExtraData
="[%s]" % str(Info
))
1071 elif ValueNumber
>= 0x10000:
1072 EdkLogger
.error("build", AUTOGEN_ERROR
,
1073 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1074 ExtraData
="[%s]" % str(Info
))
1075 if not Value
.endswith('U'):
1077 elif Pcd
.DatumType
== 'UINT8':
1079 EdkLogger
.error("build", AUTOGEN_ERROR
,
1080 "PCD can't be set to negative value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1081 ExtraData
="[%s]" % str(Info
))
1082 elif ValueNumber
>= 0x100:
1083 EdkLogger
.error("build", AUTOGEN_ERROR
,
1084 "Too large PCD value for datum type [%s] of PCD %s.%s" % (Pcd
.DatumType
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1085 ExtraData
="[%s]" % str(Info
))
1086 if not Value
.endswith('U'):
1088 if Pcd
.DatumType
not in _NumericDataTypesList
:
1089 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
1090 EdkLogger
.error("build", AUTOGEN_ERROR
,
1091 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1092 ExtraData
="[%s]" % str(Info
))
1094 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1100 Value
= Value
.lstrip('L') #.strip('"')
1101 Value
= eval(Value
) # translate escape character
1103 for Index
in range(0,len(Value
)):
1105 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x10000) + ', '
1107 NewValue
= NewValue
+ str(ord(Value
[Index
]) % 0x100) + ', '
1109 ArraySize
= ArraySize
/ 2;
1111 if ArraySize
< (len(Value
) + 1):
1112 if Pcd
.MaxSizeUserSet
:
1113 EdkLogger
.error("build", AUTOGEN_ERROR
,
1114 "The maximum size of VOID* type PCD '%s.%s' is less than its actual size occupied." % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1115 ExtraData
="[%s]" % str(Info
))
1117 ArraySize
= GetPcdSize(Pcd
)
1119 ArraySize
= ArraySize
/ 2
1120 Value
= NewValue
+ '0 }'
1121 Array
= '[%d]' % ArraySize
1123 # skip casting for fixed at build since it breaks ARM assembly.
1124 # Long term we need PCD macros that work in assembly
1126 elif Pcd
.Type
!= TAB_PCDS_FIXED_AT_BUILD
and Pcd
.DatumType
in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1127 Value
= "((%s)%s)" % (Pcd
.DatumType
, Value
)
1129 if Pcd
.DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1130 # handle structure PCD
1131 if Pcd
.MaxDatumSize
is None or Pcd
.MaxDatumSize
== '':
1132 EdkLogger
.error("build", AUTOGEN_ERROR
,
1133 "Unknown [MaxDatumSize] of PCD [%s.%s]" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1134 ExtraData
="[%s]" % str(Info
))
1136 ArraySize
= int(Pcd
.MaxDatumSize
, 0)
1137 Array
= '[%d]' % ArraySize
1139 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1140 PcdValueName
= '_PCD_PATCHABLE_VALUE_' + TokenCName
1142 PcdValueName
= '_PCD_VALUE_' + TokenCName
1144 if Pcd
.DatumType
not in _NumericDataTypesList
:
1146 # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
1148 AutoGenH
.Append('#define %s %s%s\n' %(PcdValueName
, Type
, PcdVariableName
))
1150 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1151 AutoGenH
.Append('extern %s UINT16 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1153 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s;\n' % (Const
, PcdVariableName
, Array
, Value
))
1154 AutoGenH
.Append('extern %s UINT8 %s%s;\n' %(Const
, PcdVariableName
, Array
))
1155 AutoGenH
.Append('#define %s %s%s\n' %(GetModeName
, Type
, PcdVariableName
))
1157 PcdDataSize
= GetPcdSize(Pcd
)
1158 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
1159 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1160 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1161 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (FixedPcdSizeVariableName
,PcdDataSize
))
1162 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1163 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, Pcd
.MaxDatumSize
))
1164 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1165 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1166 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1167 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s;\n' % (PatchPcdMaxSizeVariable
,Pcd
.MaxDatumSize
))
1168 elif Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1169 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1170 AutoGenC
.Append('volatile %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1171 AutoGenH
.Append('extern volatile %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1172 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1174 PcdDataSize
= GetPcdSize(Pcd
)
1175 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1177 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1178 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1179 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s;\n' % (PatchPcdSizeVariableName
,PcdDataSize
))
1181 PcdDataSize
= GetPcdSize(Pcd
)
1182 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1183 AutoGenH
.Append('#define %s %s \n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1185 AutoGenH
.Append('#define %s %s\n' %(PcdValueName
, Value
))
1186 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s;\n' %(Const
, Pcd
.DatumType
, PcdVariableName
, PcdValueName
))
1187 AutoGenH
.Append('extern %s %s %s%s;\n' % (Const
, Pcd
.DatumType
, PcdVariableName
, Array
))
1188 AutoGenH
.Append('#define %s %s%s\n' % (GetModeName
, Type
, PcdVariableName
))
1190 if Pcd
.Type
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1191 if Pcd
.DatumType
not in _NumericDataTypesList
:
1192 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
))
1193 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
))
1195 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1196 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS) \n' % (SetModeStatusName
, PcdVariableName
))
1198 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1200 ## Create code for library module PCDs
1202 # @param Info The ModuleAutoGen object
1203 # @param AutoGenC The TemplateString object for C code
1204 # @param AutoGenH The TemplateString object for header file
1205 # @param Pcd The PCD object
1207 def CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
):
1208 PcdTokenNumber
= Info
.PlatformInfo
.PcdTokenNumber
1209 TokenSpaceGuidCName
= Pcd
.TokenSpaceGuidCName
1210 TokenCName
= Pcd
.TokenCName
1211 for PcdItem
in GlobalData
.MixedPcd
:
1212 if (TokenCName
, TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
1213 TokenCName
= PcdItem
[0]
1215 PcdTokenName
= '_PCD_TOKEN_' + TokenCName
1216 FixPcdSizeTokenName
= '_PCD_SIZE_' + TokenCName
1217 PatchPcdSizeTokenName
= '_PCD_PATCHABLE_' + TokenCName
+'_SIZE'
1218 PatchPcdSizeVariableName
= '_gPcd_BinaryPatch_Size_' + TokenCName
1219 PatchPcdMaxSizeVariable
= '_gPcd_BinaryPatch_MaxSize_' + TokenCName
1220 FixedPcdSizeVariableName
= '_gPcd_FixedAtBuild_Size_' + TokenCName
1222 if Pcd
.PcdValueFromComm
:
1223 Pcd
.DefaultValue
= Pcd
.PcdValueFromComm
1227 if Pcd
.Type
in gDynamicExPcd
:
1228 TokenNumber
= int(Pcd
.TokenValue
, 0)
1230 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) not in PcdTokenNumber
:
1231 # If one of the Source built modules listed in the DSC is not listed in FDF modules,
1232 # and the INF lists a PCD can only use the PcdsDynamic access method (it is only
1233 # listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
1234 # report warning message notify the PI that they are attempting to build a module
1235 # that must be included in a flash image in order to be functional. These Dynamic PCD
1236 # will not be added into the Database unless it is used by other modules that are
1237 # included in the FDF file.
1238 # In this case, just assign an invalid token number to make it pass build.
1239 if Pcd
.Type
in PCD_DYNAMIC_TYPE_LIST
:
1242 EdkLogger
.error("build", AUTOGEN_ERROR
,
1243 "No generated token number for %s.%s\n" % (Pcd
.TokenSpaceGuidCName
, TokenCName
),
1244 ExtraData
="[%s]" % str(Info
))
1246 TokenNumber
= PcdTokenNumber
[Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
]
1248 if Pcd
.Type
not in gItemTypeStringDatabase
:
1249 EdkLogger
.error("build", AUTOGEN_ERROR
,
1250 "Unknown PCD type [%s] of PCD %s.%s" % (Pcd
.Type
, Pcd
.TokenSpaceGuidCName
, TokenCName
),
1251 ExtraData
="[%s]" % str(Info
))
1253 DatumType
= Pcd
.DatumType
1254 DatumSize
= gDatumSizeStringDatabase
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabase
else gDatumSizeStringDatabase
['VOID*']
1255 DatumSizeLib
= gDatumSizeStringDatabaseLib
[Pcd
.DatumType
] if Pcd
.DatumType
in gDatumSizeStringDatabaseLib
else gDatumSizeStringDatabaseLib
['VOID*']
1256 GetModeName
= '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
1257 SetModeName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_' + TokenCName
1258 SetModeStatusName
= '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
[Pcd
.DatumType
] + '_S_' + TokenCName
if Pcd
.DatumType
in gDatumSizeStringDatabaseH
else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH
['VOID*'] + '_S_' + TokenCName
1259 GetModeSizeName
= '_PCD_GET_MODE_SIZE' + '_' + TokenCName
1263 if Pcd
.DatumType
not in _NumericDataTypesList
:
1264 if Pcd
.DefaultValue
[0]== '{':
1267 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
1277 for PcdModule
in PcdList
:
1278 if PcdModule
.Type
in gDynamicExPcd
:
1279 PcdExCNameList
.append(PcdModule
.TokenCName
)
1280 # Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
1281 # If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
1282 # If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
1283 if PcdExCNameList
.count(Pcd
.TokenCName
) > 1:
1284 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')
1285 AutoGenH
.Append('// #define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1286 AutoGenH
.Append('// #define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1287 AutoGenH
.Append('// #define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1288 if Pcd
.DatumType
not in _NumericDataTypesList
:
1289 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1290 AutoGenH
.Append('// #define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1292 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1293 AutoGenH
.Append('// #define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1295 AutoGenH
.Append('#define %s %s\n' % (PcdTokenName
, PcdExTokenName
))
1296 AutoGenH
.Append('#define %s LibPcdGetEx%s(&%s, %s)\n' % (GetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1297 AutoGenH
.Append('#define %s LibPcdGetExSize(&%s, %s)\n' % (GetModeSizeName
,Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1298 if Pcd
.DatumType
not in _NumericDataTypesList
:
1299 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1300 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSetEx%sS(&%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1302 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%s(&%s, %s, (Value))\n' % (SetModeName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1303 AutoGenH
.Append('#define %s(Value) LibPcdSetEx%sS(&%s, %s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, Pcd
.TokenSpaceGuidCName
, PcdTokenName
))
1305 AutoGenH
.Append('#define _PCD_TOKEN_%s %dU\n' % (TokenCName
, TokenNumber
))
1306 if PcdItemType
in gDynamicPcd
:
1309 PcdList
.extend(Info
.LibraryPcdList
)
1310 PcdList
.extend(Info
.ModulePcdList
)
1311 for PcdModule
in PcdList
:
1312 if PcdModule
.Type
in gDynamicPcd
:
1313 PcdCNameList
.append(PcdModule
.TokenCName
)
1314 if PcdCNameList
.count(Pcd
.TokenCName
) > 1:
1315 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
))
1317 AutoGenH
.Append('#define %s LibPcdGet%s(%s)\n' % (GetModeName
, DatumSizeLib
, PcdTokenName
))
1318 AutoGenH
.Append('#define %s LibPcdGetSize(%s)\n' % (GetModeSizeName
, PcdTokenName
))
1319 if DatumType
not in _NumericDataTypesList
:
1320 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%s(%s, (SizeOfBuffer), (Buffer))\n' %(SetModeName
, DatumSizeLib
, PcdTokenName
))
1321 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPcdSet%sS(%s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1323 AutoGenH
.Append('#define %s(Value) LibPcdSet%s(%s, (Value))\n' % (SetModeName
, DatumSizeLib
, PcdTokenName
))
1324 AutoGenH
.Append('#define %s(Value) LibPcdSet%sS(%s, (Value))\n' % (SetModeStatusName
, DatumSizeLib
, PcdTokenName
))
1325 if PcdItemType
== TAB_PCDS_PATCHABLE_IN_MODULE
:
1326 GetModeMaxSizeName
= '_PCD_GET_MODE_MAXSIZE' + '_' + TokenCName
1327 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[TAB_PCDS_PATCHABLE_IN_MODULE
] + '_' + TokenCName
1328 if DatumType
not in _NumericDataTypesList
:
1329 if DatumType
== 'VOID*' and Array
== '[]':
1330 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1333 AutoGenH
.Append('extern %s _gPcd_BinaryPatch_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1335 AutoGenH
.Append('extern volatile %s %s%s;\n' % (DatumType
, PcdVariableName
, Array
))
1336 AutoGenH
.Append('#define %s %s_gPcd_BinaryPatch_%s\n' %(GetModeName
, Type
, TokenCName
))
1337 PcdDataSize
= GetPcdSize(Pcd
)
1338 if Pcd
.DatumType
not in _NumericDataTypesList
:
1339 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeName
, TokenCName
, PatchPcdSizeVariableName
, PatchPcdMaxSizeVariable
))
1340 AutoGenH
.Append('#define %s(SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_%s, &%s, %s, (SizeOfBuffer), (Buffer))\n' % (SetModeStatusName
, TokenCName
, PatchPcdSizeVariableName
, PatchPcdMaxSizeVariable
))
1341 AutoGenH
.Append('#define %s %s\n' % (GetModeMaxSizeName
, PatchPcdMaxSizeVariable
))
1342 AutoGenH
.Append('extern const UINTN %s; \n' % PatchPcdMaxSizeVariable
)
1344 AutoGenH
.Append('#define %s(Value) (%s = (Value))\n' % (SetModeName
, PcdVariableName
))
1345 AutoGenH
.Append('#define %s(Value) ((%s = (Value)), RETURN_SUCCESS)\n' % (SetModeStatusName
, PcdVariableName
))
1346 AutoGenH
.Append('#define %s %s\n' % (PatchPcdSizeTokenName
, PcdDataSize
))
1348 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,PatchPcdSizeVariableName
))
1349 AutoGenH
.Append('extern UINTN %s; \n' % PatchPcdSizeVariableName
)
1351 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
or PcdItemType
== TAB_PCDS_FEATURE_FLAG
:
1352 key
= ".".join((Pcd
.TokenSpaceGuidCName
,Pcd
.TokenCName
))
1353 PcdVariableName
= '_gPcd_' + gItemTypeStringDatabase
[Pcd
.Type
] + '_' + TokenCName
1354 if DatumType
== 'VOID*' and Array
== '[]':
1355 DatumType
= ['UINT8', 'UINT16'][Pcd
.DefaultValue
[0] == 'L']
1356 if DatumType
not in ['UINT8', 'UINT16', 'UINT32', 'UINT64', 'BOOLEAN', 'VOID*']:
1358 AutoGenH
.Append('extern const %s _gPcd_FixedAtBuild_%s%s;\n' %(DatumType
, TokenCName
, Array
))
1359 AutoGenH
.Append('#define %s %s_gPcd_FixedAtBuild_%s\n' %(GetModeName
, Type
, TokenCName
))
1360 AutoGenH
.Append('//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\n' % SetModeName
)
1362 ConstFixedPcd
= False
1363 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
and (key
in Info
.ConstPcd
or (Info
.IsLibrary
and not Info
._ReferenceModules
)):
1364 ConstFixedPcd
= True
1365 if key
in Info
.ConstPcd
:
1366 Pcd
.DefaultValue
= Info
.ConstPcd
[key
]
1367 if Pcd
.DatumType
not in _NumericDataTypesList
:
1368 AutoGenH
.Append('#define _PCD_VALUE_%s %s%s\n' %(TokenCName
, Type
, PcdVariableName
))
1370 AutoGenH
.Append('#define _PCD_VALUE_%s %s\n' %(TokenCName
, Pcd
.DefaultValue
))
1371 PcdDataSize
= GetPcdSize(Pcd
)
1372 if PcdItemType
== TAB_PCDS_FIXED_AT_BUILD
:
1373 if Pcd
.DatumType
not in _NumericDataTypesList
:
1375 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1376 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1378 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixedPcdSizeVariableName
))
1379 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
,FixedPcdSizeVariableName
))
1380 AutoGenH
.Append('extern const UINTN %s; \n' % FixedPcdSizeVariableName
)
1382 AutoGenH
.Append('#define %s %s\n' % (FixPcdSizeTokenName
, PcdDataSize
))
1383 AutoGenH
.Append('#define %s %s\n' % (GetModeSizeName
,FixPcdSizeTokenName
))
1385 ## Create code for library constructor
1387 # @param Info The ModuleAutoGen object
1388 # @param AutoGenC The TemplateString object for C code
1389 # @param AutoGenH The TemplateString object for header file
1391 def CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
):
1393 # Library Constructors
1395 ConstructorPrototypeString
= TemplateString()
1396 ConstructorCallingString
= TemplateString()
1398 DependentLibraryList
= [Info
.Module
]
1400 DependentLibraryList
= Info
.DependentLibraryList
1401 for Lib
in DependentLibraryList
:
1402 if len(Lib
.ConstructorList
) <= 0:
1404 Dict
= {'Function':Lib
.ConstructorList
}
1405 if Lib
.ModuleType
in ['BASE', 'SEC']:
1406 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1407 ConstructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1408 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1409 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1410 ConstructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1411 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1412 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1413 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1414 ConstructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1415 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1416 ConstructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1417 ConstructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1419 if str(ConstructorPrototypeString
) == '':
1420 ConstructorPrototypeList
= []
1422 ConstructorPrototypeList
= [str(ConstructorPrototypeString
)]
1423 if str(ConstructorCallingString
) == '':
1424 ConstructorCallingList
= []
1426 ConstructorCallingList
= [str(ConstructorCallingString
)]
1429 'Type' : 'Constructor',
1430 'FunctionPrototype' : ConstructorPrototypeList
,
1431 'FunctionCall' : ConstructorCallingList
1434 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1436 if Info
.ModuleType
in ['BASE', 'SEC']:
1437 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1438 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1439 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1440 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1441 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1442 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1443 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1444 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1446 ## Create code for library destructor
1448 # @param Info The ModuleAutoGen object
1449 # @param AutoGenC The TemplateString object for C code
1450 # @param AutoGenH The TemplateString object for header file
1452 def CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
):
1454 # Library Destructors
1456 DestructorPrototypeString
= TemplateString()
1457 DestructorCallingString
= TemplateString()
1459 DependentLibraryList
= [Info
.Module
]
1461 DependentLibraryList
= Info
.DependentLibraryList
1462 for Index
in range(len(DependentLibraryList
)-1, -1, -1):
1463 Lib
= DependentLibraryList
[Index
]
1464 if len(Lib
.DestructorList
) <= 0:
1466 Dict
= {'Function':Lib
.DestructorList
}
1467 if Lib
.ModuleType
in ['BASE', 'SEC']:
1468 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['BASE'].Replace(Dict
))
1469 DestructorCallingString
.Append(gLibraryStructorCall
['BASE'].Replace(Dict
))
1470 elif Lib
.ModuleType
in ['PEI_CORE','PEIM']:
1471 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['PEI'].Replace(Dict
))
1472 DestructorCallingString
.Append(gLibraryStructorCall
['PEI'].Replace(Dict
))
1473 elif Lib
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1474 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION', 'SMM_CORE']:
1475 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['DXE'].Replace(Dict
))
1476 DestructorCallingString
.Append(gLibraryStructorCall
['DXE'].Replace(Dict
))
1477 elif Lib
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1478 DestructorPrototypeString
.Append(gLibraryStructorPrototype
['MM'].Replace(Dict
))
1479 DestructorCallingString
.Append(gLibraryStructorCall
['MM'].Replace(Dict
))
1481 if str(DestructorPrototypeString
) == '':
1482 DestructorPrototypeList
= []
1484 DestructorPrototypeList
= [str(DestructorPrototypeString
)]
1485 if str(DestructorCallingString
) == '':
1486 DestructorCallingList
= []
1488 DestructorCallingList
= [str(DestructorCallingString
)]
1491 'Type' : 'Destructor',
1492 'FunctionPrototype' : DestructorPrototypeList
,
1493 'FunctionCall' : DestructorCallingList
1496 AutoGenH
.Append("${BEGIN}${FunctionPrototype}${END}", Dict
)
1498 if Info
.ModuleType
in ['BASE', 'SEC']:
1499 AutoGenC
.Append(gLibraryString
['BASE'].Replace(Dict
))
1500 elif Info
.ModuleType
in ['PEI_CORE','PEIM']:
1501 AutoGenC
.Append(gLibraryString
['PEI'].Replace(Dict
))
1502 elif Info
.ModuleType
in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER',
1503 'DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION','SMM_CORE']:
1504 AutoGenC
.Append(gLibraryString
['DXE'].Replace(Dict
))
1505 elif Info
.ModuleType
in ['MM_STANDALONE','MM_CORE_STANDALONE']:
1506 AutoGenC
.Append(gLibraryString
['MM'].Replace(Dict
))
1509 ## Create code for ModuleEntryPoint
1511 # @param Info The ModuleAutoGen object
1512 # @param AutoGenC The TemplateString object for C code
1513 # @param AutoGenH The TemplateString object for header file
1515 def CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
):
1516 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1519 # Module Entry Points
1521 NumEntryPoints
= len(Info
.Module
.ModuleEntryPointList
)
1522 if 'PI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1523 PiSpecVersion
= Info
.Module
.Specification
['PI_SPECIFICATION_VERSION']
1525 PiSpecVersion
= '0x00000000'
1526 if 'UEFI_SPECIFICATION_VERSION' in Info
.Module
.Specification
:
1527 UefiSpecVersion
= Info
.Module
.Specification
['UEFI_SPECIFICATION_VERSION']
1529 UefiSpecVersion
= '0x00000000'
1531 'Function' : Info
.Module
.ModuleEntryPointList
,
1532 'PiSpecVersion' : PiSpecVersion
+ 'U',
1533 'UefiSpecVersion': UefiSpecVersion
+ 'U'
1536 if Info
.ModuleType
in ['PEI_CORE', 'DXE_CORE', 'SMM_CORE', 'MM_CORE_STANDALONE']:
1537 if Info
.SourceFileList
<> None and Info
.SourceFileList
<> []:
1538 if NumEntryPoints
!= 1:
1542 '%s must have exactly one entry point' % Info
.ModuleType
,
1544 ExtraData
= ", ".join(Info
.Module
.ModuleEntryPointList
)
1546 if Info
.ModuleType
== 'PEI_CORE':
1547 AutoGenC
.Append(gPeiCoreEntryPointString
.Replace(Dict
))
1548 AutoGenH
.Append(gPeiCoreEntryPointPrototype
.Replace(Dict
))
1549 elif Info
.ModuleType
== 'DXE_CORE':
1550 AutoGenC
.Append(gDxeCoreEntryPointString
.Replace(Dict
))
1551 AutoGenH
.Append(gDxeCoreEntryPointPrototype
.Replace(Dict
))
1552 elif Info
.ModuleType
== 'SMM_CORE':
1553 AutoGenC
.Append(gSmmCoreEntryPointString
.Replace(Dict
))
1554 AutoGenH
.Append(gSmmCoreEntryPointPrototype
.Replace(Dict
))
1555 elif Info
.ModuleType
== 'MM_CORE_STANDALONE':
1556 AutoGenC
.Append(gMmCoreStandaloneEntryPointString
.Replace(Dict
))
1557 AutoGenH
.Append(gMmCoreStandaloneEntryPointPrototype
.Replace(Dict
))
1558 elif Info
.ModuleType
== 'PEIM':
1559 if NumEntryPoints
< 2:
1560 AutoGenC
.Append(gPeimEntryPointString
[NumEntryPoints
].Replace(Dict
))
1562 AutoGenC
.Append(gPeimEntryPointString
[2].Replace(Dict
))
1563 AutoGenH
.Append(gPeimEntryPointPrototype
.Replace(Dict
))
1564 elif Info
.ModuleType
in ['DXE_RUNTIME_DRIVER','DXE_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER']:
1565 if NumEntryPoints
< 2:
1566 AutoGenC
.Append(gUefiDriverEntryPointString
[NumEntryPoints
].Replace(Dict
))
1568 AutoGenC
.Append(gUefiDriverEntryPointString
[2].Replace(Dict
))
1569 AutoGenH
.Append(gUefiDriverEntryPointPrototype
.Replace(Dict
))
1570 elif Info
.ModuleType
== 'DXE_SMM_DRIVER':
1571 if NumEntryPoints
== 0:
1572 AutoGenC
.Append(gDxeSmmEntryPointString
[0].Replace(Dict
))
1574 AutoGenC
.Append(gDxeSmmEntryPointString
[1].Replace(Dict
))
1575 AutoGenH
.Append(gDxeSmmEntryPointPrototype
.Replace(Dict
))
1576 elif Info
.ModuleType
== 'MM_STANDALONE':
1577 if NumEntryPoints
< 2:
1578 AutoGenC
.Append(gMmStandaloneEntryPointString
[NumEntryPoints
].Replace(Dict
))
1580 AutoGenC
.Append(gMmStandaloneEntryPointString
[2].Replace(Dict
))
1581 AutoGenH
.Append(gMmStandaloneEntryPointPrototype
.Replace(Dict
))
1582 elif Info
.ModuleType
== 'UEFI_APPLICATION':
1583 if NumEntryPoints
< 2:
1584 AutoGenC
.Append(gUefiApplicationEntryPointString
[NumEntryPoints
].Replace(Dict
))
1586 AutoGenC
.Append(gUefiApplicationEntryPointString
[2].Replace(Dict
))
1587 AutoGenH
.Append(gUefiApplicationEntryPointPrototype
.Replace(Dict
))
1589 ## Create code for ModuleUnloadImage
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 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
):
1596 if Info
.IsLibrary
or Info
.ModuleType
in ['USER_DEFINED', 'SEC']:
1599 # Unload Image Handlers
1601 NumUnloadImage
= len(Info
.Module
.ModuleUnloadImageList
)
1602 Dict
= {'Count':str(NumUnloadImage
) + 'U', 'Function':Info
.Module
.ModuleUnloadImageList
}
1603 if NumUnloadImage
< 2:
1604 AutoGenC
.Append(gUefiUnloadImageString
[NumUnloadImage
].Replace(Dict
))
1606 AutoGenC
.Append(gUefiUnloadImageString
[2].Replace(Dict
))
1607 AutoGenH
.Append(gUefiUnloadImagePrototype
.Replace(Dict
))
1609 ## Create code for GUID
1611 # @param Info The ModuleAutoGen object
1612 # @param AutoGenC The TemplateString object for C code
1613 # @param AutoGenH The TemplateString object for header file
1615 def CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1616 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1619 GuidType
= "EFI_GUID"
1622 if not Info
.IsLibrary
:
1623 AutoGenC
.Append("\n// Guids\n")
1624 AutoGenH
.Append("\n// Guids\n")
1628 for Key
in Info
.GuidList
:
1629 if not Info
.IsLibrary
:
1630 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.GuidList
[Key
]))
1631 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1633 ## Create code for protocol
1635 # @param Info The ModuleAutoGen object
1636 # @param AutoGenC The TemplateString object for C code
1637 # @param AutoGenH The TemplateString object for header file
1639 def CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1640 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1643 GuidType
= "EFI_GUID"
1645 if Info
.ProtocolList
:
1646 if not Info
.IsLibrary
:
1647 AutoGenC
.Append("\n// Protocols\n")
1648 AutoGenH
.Append("\n// Protocols\n")
1652 for Key
in Info
.ProtocolList
:
1653 if not Info
.IsLibrary
:
1654 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.ProtocolList
[Key
]))
1655 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1657 ## Create code for PPI
1659 # @param Info The ModuleAutoGen object
1660 # @param AutoGenC The TemplateString object for C code
1661 # @param AutoGenH The TemplateString object for header file
1663 def CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
):
1664 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1667 GuidType
= "EFI_GUID"
1670 if not Info
.IsLibrary
:
1671 AutoGenC
.Append("\n// PPIs\n")
1672 AutoGenH
.Append("\n// PPIs\n")
1676 for Key
in Info
.PpiList
:
1677 if not Info
.IsLibrary
:
1678 AutoGenC
.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s;\n' % (GuidType
, Key
, Info
.PpiList
[Key
]))
1679 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Key
))
1681 ## Create code for PCD
1683 # @param Info The ModuleAutoGen object
1684 # @param AutoGenC The TemplateString object for C code
1685 # @param AutoGenH The TemplateString object for header file
1687 def CreatePcdCode(Info
, AutoGenC
, AutoGenH
):
1689 # Collect Token Space GUIDs used by DynamicEc PCDs
1691 for Pcd
in Info
.ModulePcdList
:
1692 if Pcd
.Type
in gDynamicExPcd
and Pcd
.TokenSpaceGuidCName
not in TokenSpaceList
:
1693 TokenSpaceList
+= [Pcd
.TokenSpaceGuidCName
]
1695 SkuMgr
= Info
.Workspace
.Platform
.SkuIdMgr
1696 AutoGenH
.Append("\n// Definition of SkuId Array\n")
1697 AutoGenH
.Append("extern UINT64 _gPcd_SkuId_Array[];\n")
1698 # Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
1699 if TokenSpaceList
<> []:
1700 AutoGenH
.Append("\n// Definition of PCD Token Space GUIDs used in this module\n\n")
1701 if Info
.ModuleType
in ["USER_DEFINED", "BASE"]:
1704 GuidType
= "EFI_GUID"
1705 for Item
in TokenSpaceList
:
1706 AutoGenH
.Append('extern %s %s;\n' % (GuidType
, Item
))
1709 if Info
.ModulePcdList
:
1710 AutoGenH
.Append("\n// PCD definitions\n")
1711 for Pcd
in Info
.ModulePcdList
:
1712 CreateLibraryPcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1713 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1715 AutoGenC
.Append("\n// Definition of SkuId Array\n")
1716 AutoGenC
.Append("GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s;\n" % SkuMgr
.DumpSkuIdArrary())
1717 if Info
.ModulePcdList
:
1718 AutoGenH
.Append("\n// Definition of PCDs used in this module\n")
1719 AutoGenC
.Append("\n// Definition of PCDs used in this module\n")
1720 for Pcd
in Info
.ModulePcdList
:
1721 CreateModulePcdCode(Info
, AutoGenC
, AutoGenH
, Pcd
)
1722 DynExPcdTokenNumberMapping (Info
, AutoGenH
)
1723 if Info
.LibraryPcdList
:
1724 AutoGenH
.Append("\n// Definition of PCDs used in libraries is in AutoGen.c\n")
1725 AutoGenC
.Append("\n// Definition of PCDs used in libraries\n")
1726 for Pcd
in Info
.LibraryPcdList
:
1727 CreateModulePcdCode(Info
, AutoGenC
, AutoGenC
, Pcd
)
1728 CreatePcdDatabaseCode(Info
, AutoGenC
, AutoGenH
)
1730 ## Create code for unicode string definition
1732 # @param Info The ModuleAutoGen object
1733 # @param AutoGenC The TemplateString object for C code
1734 # @param AutoGenH The TemplateString object for header file
1735 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
1736 # @param UniGenBinBuffer Buffer to store uni string package data
1738 def CreateUnicodeStringCode(Info
, AutoGenC
, AutoGenH
, UniGenCFlag
, UniGenBinBuffer
):
1739 WorkingDir
= os
.getcwd()
1740 os
.chdir(Info
.WorkspaceDir
)
1742 IncList
= [Info
.MetaFile
.Dir
]
1743 # Get all files under [Sources] section in inf file for EDK-II module
1745 SrcList
= [F
for F
in Info
.SourceFileList
]
1746 if Info
.AutoGenVersion
< 0x00010005:
1748 # Get all files under the module directory for EDK-I module
1750 os
.chdir(Info
.MetaFile
.Dir
)
1751 for Root
, Dirs
, Files
in os
.walk("."):
1757 File
= PathClass(os
.path
.join(Root
, File
), Info
.MetaFile
.Dir
)
1760 SrcList
.append(File
)
1763 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-c') > -1:
1764 CompatibleMode
= True
1766 CompatibleMode
= False
1769 # -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
1771 if 'BUILD' in Info
.BuildOption
and Info
.BuildOption
['BUILD']['FLAGS'].find('-s') > -1:
1773 EdkLogger
.error("build", AUTOGEN_ERROR
,
1774 "-c and -s build options should be used exclusively",
1775 ExtraData
="[%s]" % str(Info
))
1780 #RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
1782 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.RFCLanguages
]
1784 FilterInfo
= [EDK2Module
] + [Info
.PlatformInfo
.Platform
.ISOLanguages
]
1785 Header
, Code
= GetStringFiles(Info
.UnicodeFileList
, SrcList
, IncList
, Info
.IncludePathList
, ['.uni', '.inf'], Info
.Name
, CompatibleMode
, ShellMode
, UniGenCFlag
, UniGenBinBuffer
, FilterInfo
)
1786 if CompatibleMode
or UniGenCFlag
:
1787 AutoGenC
.Append("\n//\n//Unicode String Pack Definition\n//\n")
1788 AutoGenC
.Append(Code
)
1789 AutoGenC
.Append("\n")
1790 AutoGenH
.Append("\n//\n//Unicode String ID\n//\n")
1791 AutoGenH
.Append(Header
)
1792 if CompatibleMode
or UniGenCFlag
:
1793 AutoGenH
.Append("\n#define STRING_ARRAY_NAME %sStrings\n" % Info
.Name
)
1794 os
.chdir(WorkingDir
)
1796 def CreateIdfFileCode(Info
, AutoGenC
, StringH
, IdfGenCFlag
, IdfGenBinBuffer
):
1797 if len(Info
.IdfFileList
) > 0:
1798 ImageFiles
= IdfFileClassObject(sorted (Info
.IdfFileList
))
1799 if ImageFiles
.ImageFilesDict
:
1802 IncList
= [Info
.MetaFile
.Dir
]
1803 SrcList
= [F
for F
in Info
.SourceFileList
]
1804 SkipList
= ['.jpg', '.png', '.bmp', '.inf', '.idf']
1805 FileList
= GetFileList(SrcList
, IncList
, SkipList
)
1807 StringH
.Append("\n//\n//Image ID\n//\n")
1809 PaletteInfoOffset
= 0
1810 ImageBuffer
= pack('x')
1811 PaletteBuffer
= pack('x')
1815 for Idf
in ImageFiles
.ImageFilesDict
:
1816 if ImageFiles
.ImageFilesDict
[Idf
]:
1817 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1818 for sourcefile
in Info
.SourceFileList
:
1819 if FileObj
.FileName
== sourcefile
.File
:
1820 if not sourcefile
.Ext
.upper() in ['.PNG', '.BMP', '.JPG']:
1821 EdkLogger
.error("build", AUTOGEN_ERROR
, "The %s's postfix must be one of .bmp, .jpg, .png" % (FileObj
.FileName
), ExtraData
="[%s]" % str(Info
))
1822 FileObj
.File
= sourcefile
1825 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
))
1827 for FileObj
in ImageFiles
.ImageFilesDict
[Idf
]:
1828 ID
= FileObj
.ImageID
1830 if not os
.path
.exists(File
.Path
) or not os
.path
.isfile(File
.Path
):
1831 EdkLogger
.error("build", FILE_NOT_FOUND
, ExtraData
=File
.Path
)
1832 SearchImageID (FileObj
, FileList
)
1833 if FileObj
.Referenced
:
1834 if (ValueStartPtr
- len(DEFINE_STR
+ ID
)) <= 0:
1835 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' + DecToHexStr(Index
, 4) + '\n'
1837 Line
= DEFINE_STR
+ ' ' + ID
+ ' ' * (ValueStartPtr
- len(DEFINE_STR
+ ID
)) + DecToHexStr(Index
, 4) + '\n'
1839 if File
not in FileDict
:
1840 FileDict
[File
] = Index
1842 DuplicateBlock
= pack('B', EFI_HII_IIBT_DUPLICATE
)
1843 DuplicateBlock
+= pack('H', FileDict
[File
])
1844 ImageBuffer
+= DuplicateBlock
1845 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1846 TempBufferList
= AscToHexList(DuplicateBlock
)
1847 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1848 StringH
.Append(Line
)
1852 TmpFile
= open(File
.Path
, 'rb')
1853 Buffer
= TmpFile
.read()
1855 if File
.Ext
.upper() == '.PNG':
1856 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_PNG
)
1857 TempBuffer
+= pack('I', len(Buffer
))
1858 TempBuffer
+= Buffer
1859 elif File
.Ext
.upper() == '.JPG':
1860 ImageType
, = struct
.unpack('4s', Buffer
[6:10])
1861 if ImageType
!= 'JFIF':
1862 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard JPG file." % File
.Path
)
1863 TempBuffer
= pack('B', EFI_HII_IIBT_IMAGE_JPEG
)
1864 TempBuffer
+= pack('I', len(Buffer
))
1865 TempBuffer
+= Buffer
1866 elif File
.Ext
.upper() == '.BMP':
1867 TempBuffer
, TempPalette
= BmpImageDecoder(File
, Buffer
, PaletteIndex
, FileObj
.TransParent
)
1868 if len(TempPalette
) > 1:
1870 NewPalette
= pack('H', len(TempPalette
))
1871 NewPalette
+= TempPalette
1872 PaletteBuffer
+= NewPalette
1873 PaletteStr
= WriteLine(PaletteStr
, '// %s: %s: %s' % (DecToHexStr(PaletteIndex
- 1, 4), ID
, DecToHexStr(PaletteIndex
- 1, 4)))
1874 TempPaletteList
= AscToHexList(NewPalette
)
1875 PaletteStr
= WriteLine(PaletteStr
, CreateArrayItem(TempPaletteList
, 16) + '\n')
1876 ImageBuffer
+= TempBuffer
1877 BufferStr
= WriteLine(BufferStr
, '// %s: %s: %s' % (DecToHexStr(Index
, 4), ID
, DecToHexStr(Index
, 4)))
1878 TempBufferList
= AscToHexList(TempBuffer
)
1879 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(TempBufferList
, 16) + '\n')
1881 StringH
.Append(Line
)
1884 BufferStr
= WriteLine(BufferStr
, '// End of the Image Info')
1885 BufferStr
= WriteLine(BufferStr
, CreateArrayItem(DecToHexList(EFI_HII_IIBT_END
, 2)) + '\n')
1886 ImageEnd
= pack('B', EFI_HII_IIBT_END
)
1887 ImageBuffer
+= ImageEnd
1889 if len(ImageBuffer
) > 1:
1890 ImageInfoOffset
= 12
1891 if len(PaletteBuffer
) > 1:
1892 PaletteInfoOffset
= 12 + len(ImageBuffer
) - 1 # -1 is for the first empty pad byte of ImageBuffer
1894 IMAGE_PACKAGE_HDR
= pack('=II', ImageInfoOffset
, PaletteInfoOffset
)
1895 # PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
1896 if len(PaletteBuffer
) > 1:
1897 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1 + 2 + len(PaletteBuffer
) - 1
1899 PACKAGE_HEADER_Length
= 4 + 4 + 4 + len(ImageBuffer
) - 1
1900 if PaletteIndex
> 1:
1901 PALETTE_INFO_HEADER
= pack('H', PaletteIndex
- 1)
1902 # EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
1903 Hex_Length
= '%06X' % PACKAGE_HEADER_Length
1904 if PACKAGE_HEADER_Length
> 0xFFFFFF:
1905 EdkLogger
.error("build", AUTOGEN_ERROR
, "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value", ExtraData
="[%s]" % str(Info
))
1906 PACKAGE_HEADER
= pack('=HBB', int('0x' + Hex_Length
[2:], 16), int('0x' + Hex_Length
[0:2], 16), EFI_HII_PACKAGE_IMAGES
)
1908 IdfGenBinBuffer
.write(PACKAGE_HEADER
)
1909 IdfGenBinBuffer
.write(IMAGE_PACKAGE_HDR
)
1910 if len(ImageBuffer
) > 1 :
1911 IdfGenBinBuffer
.write(ImageBuffer
[1:])
1912 if PaletteIndex
> 1:
1913 IdfGenBinBuffer
.write(PALETTE_INFO_HEADER
)
1914 if len(PaletteBuffer
) > 1:
1915 IdfGenBinBuffer
.write(PaletteBuffer
[1:])
1918 TotalLength
= EFI_HII_ARRAY_SIZE_LENGTH
+ PACKAGE_HEADER_Length
1919 AutoGenC
.Append("\n//\n//Image Pack Definition\n//\n")
1920 AllStr
= WriteLine('', CHAR_ARRAY_DEFIN
+ ' ' + Info
.Module
.BaseName
+ 'Images' + '[] = {\n')
1921 AllStr
= WriteLine(AllStr
, '// STRGATHER_OUTPUT_HEADER')
1922 AllStr
= WriteLine(AllStr
, CreateArrayItem(DecToHexList(TotalLength
)) + '\n')
1923 AllStr
= WriteLine(AllStr
, '// Image PACKAGE HEADER\n')
1924 IMAGE_PACKAGE_HDR_List
= AscToHexList(PACKAGE_HEADER
)
1925 IMAGE_PACKAGE_HDR_List
+= AscToHexList(IMAGE_PACKAGE_HDR
)
1926 AllStr
= WriteLine(AllStr
, CreateArrayItem(IMAGE_PACKAGE_HDR_List
, 16) + '\n')
1927 AllStr
= WriteLine(AllStr
, '// Image DATA\n')
1929 AllStr
= WriteLine(AllStr
, BufferStr
)
1931 AllStr
= WriteLine(AllStr
, '// Palette Header\n')
1932 PALETTE_INFO_HEADER_List
= AscToHexList(PALETTE_INFO_HEADER
)
1933 AllStr
= WriteLine(AllStr
, CreateArrayItem(PALETTE_INFO_HEADER_List
, 16) + '\n')
1934 AllStr
= WriteLine(AllStr
, '// Palette Data\n')
1935 AllStr
= WriteLine(AllStr
, PaletteStr
)
1936 AllStr
= WriteLine(AllStr
, '};')
1937 AutoGenC
.Append(AllStr
)
1938 AutoGenC
.Append("\n")
1939 StringH
.Append('\nextern unsigned char ' + Info
.Module
.BaseName
+ 'Images[];\n')
1940 StringH
.Append("\n#define IMAGE_ARRAY_NAME %sImages\n" % Info
.Module
.BaseName
)
1942 # typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
1943 # EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
1944 # UINT32 ImageInfoOffset;
1945 # UINT32 PaletteInfoOffset;
1946 # } EFI_HII_IMAGE_PACKAGE_HDR;
1952 # } EFI_HII_PACKAGE_HEADER;
1954 # typedef struct _EFI_HII_IMAGE_BLOCK {
1956 # UINT8 BlockBody[];
1957 # } EFI_HII_IMAGE_BLOCK;
1959 def BmpImageDecoder(File
, Buffer
, PaletteIndex
, TransParent
):
1960 ImageType
, = struct
.unpack('2s', Buffer
[0:2])
1961 if ImageType
!= 'BM': # BMP file type is 'BM'
1962 EdkLogger
.error("build", FILE_TYPE_MISMATCH
, "The file %s is not a standard BMP file." % File
.Path
)
1963 BMP_IMAGE_HEADER
= collections
.namedtuple('BMP_IMAGE_HEADER', ['bfSize','bfReserved1','bfReserved2','bfOffBits','biSize','biWidth','biHeight','biPlanes','biBitCount', 'biCompression', 'biSizeImage','biXPelsPerMeter','biYPelsPerMeter','biClrUsed','biClrImportant'])
1964 BMP_IMAGE_HEADER_STRUCT
= struct
.Struct('IHHIIIIHHIIIIII')
1965 BmpHeader
= BMP_IMAGE_HEADER
._make
(BMP_IMAGE_HEADER_STRUCT
.unpack_from(Buffer
[2:]))
1967 # Doesn't support compress.
1969 if BmpHeader
.biCompression
!= 0:
1970 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The compress BMP file %s is not support." % File
.Path
)
1972 # The Width and Height is UINT16 type in Image Package
1973 if BmpHeader
.biWidth
> 0xFFFF:
1974 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Width is exceed 0xFFFF." % File
.Path
)
1975 if BmpHeader
.biHeight
> 0xFFFF:
1976 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "The BMP file %s Height is exceed 0xFFFF." % File
.Path
)
1978 PaletteBuffer
= pack('x')
1979 if BmpHeader
.biBitCount
== 1:
1981 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT_TRANS
)
1983 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_1BIT
)
1984 ImageBuffer
+= pack('B', PaletteIndex
)
1985 Width
= (BmpHeader
.biWidth
+ 7)/8
1986 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1987 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1988 elif BmpHeader
.biBitCount
== 4:
1990 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT_TRANS
)
1992 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_4BIT
)
1993 ImageBuffer
+= pack('B', PaletteIndex
)
1994 Width
= (BmpHeader
.biWidth
+ 1)/2
1995 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
1996 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
1997 elif BmpHeader
.biBitCount
== 8:
1999 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT_TRANS
)
2001 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_8BIT
)
2002 ImageBuffer
+= pack('B', PaletteIndex
)
2003 Width
= BmpHeader
.biWidth
2004 if BmpHeader
.bfOffBits
> BMP_IMAGE_HEADER_STRUCT
.size
+ 2:
2005 PaletteBuffer
= Buffer
[BMP_IMAGE_HEADER_STRUCT
.size
+ 2 : BmpHeader
.bfOffBits
]
2006 elif BmpHeader
.biBitCount
== 24:
2008 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT_TRANS
)
2010 ImageBuffer
= pack('B', EFI_HII_IIBT_IMAGE_24BIT
)
2011 Width
= BmpHeader
.biWidth
* 3
2013 EdkLogger
.error("build", FORMAT_NOT_SUPPORTED
, "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files.", ExtraData
="[%s]" % str(File
.Path
))
2015 ImageBuffer
+= pack('H', BmpHeader
.biWidth
)
2016 ImageBuffer
+= pack('H', BmpHeader
.biHeight
)
2017 Start
= BmpHeader
.bfOffBits
2018 End
= BmpHeader
.bfSize
- 1
2019 for Height
in range(0, BmpHeader
.biHeight
):
2021 Start
= End
+ (Width
% 4) - 4 - Width
2024 ImageBuffer
+= Buffer
[Start
+ 1 : Start
+ Width
+ 1]
2027 # 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
2028 if PaletteBuffer
and len(PaletteBuffer
) > 1:
2029 PaletteTemp
= pack('x')
2030 for Index
in range(0, len(PaletteBuffer
)):
2033 PaletteTemp
+= PaletteBuffer
[Index
]
2034 PaletteBuffer
= PaletteTemp
[1:]
2035 return ImageBuffer
, PaletteBuffer
2037 ## Create common code
2039 # @param Info The ModuleAutoGen object
2040 # @param AutoGenC The TemplateString object for C code
2041 # @param AutoGenH The TemplateString object for header file
2043 def CreateHeaderCode(Info
, AutoGenC
, AutoGenH
):
2045 AutoGenH
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.h'}))
2046 # header file Prologue
2047 AutoGenH
.Append(gAutoGenHPrologueString
.Replace({'File':'AUTOGENH','Guid':Info
.Guid
.replace('-','_')}))
2048 AutoGenH
.Append(gAutoGenHCppPrologueString
)
2049 if Info
.AutoGenVersion
>= 0x00010005:
2050 # header files includes
2051 AutoGenH
.Append("#include <%s>\n" % gBasicHeaderFile
)
2052 if Info
.ModuleType
in gModuleTypeHeaderFile \
2053 and gModuleTypeHeaderFile
[Info
.ModuleType
][0] != gBasicHeaderFile
:
2054 AutoGenH
.Append("#include <%s>\n" % gModuleTypeHeaderFile
[Info
.ModuleType
][0])
2056 # if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
2057 # As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
2059 if 'PcdLib' in Info
.Module
.LibraryClasses
or Info
.Module
.Pcds
:
2060 AutoGenH
.Append("#include <Library/PcdLib.h>\n")
2062 AutoGenH
.Append('\nextern GUID gEfiCallerIdGuid;')
2063 AutoGenH
.Append('\nextern CHAR8 *gEfiCallerBaseName;\n\n')
2068 AutoGenH
.Append("#define EFI_CALLER_ID_GUID \\\n %s\n" % GuidStringToGuidStructureString(Info
.Guid
))
2073 AutoGenC
.Append(gAutoGenHeaderString
.Replace({'FileName':'AutoGen.c'}))
2074 if Info
.AutoGenVersion
>= 0x00010005:
2075 # C file header files includes
2076 if Info
.ModuleType
in gModuleTypeHeaderFile
:
2077 for Inc
in gModuleTypeHeaderFile
[Info
.ModuleType
]:
2078 AutoGenC
.Append("#include <%s>\n" % Inc
)
2080 AutoGenC
.Append("#include <%s>\n" % gBasicHeaderFile
)
2083 # Publish the CallerId Guid
2085 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s;\n' % GuidStringToGuidStructureString(Info
.Guid
))
2086 AutoGenC
.Append('\nGLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = "%s";\n' % Info
.Name
)
2088 ## Create common code for header file
2090 # @param Info The ModuleAutoGen object
2091 # @param AutoGenC The TemplateString object for C code
2092 # @param AutoGenH The TemplateString object for header file
2094 def CreateFooterCode(Info
, AutoGenC
, AutoGenH
):
2095 AutoGenH
.Append(gAutoGenHEpilogueString
)
2097 ## Create code for a module
2099 # @param Info The ModuleAutoGen object
2100 # @param AutoGenC The TemplateString object for C code
2101 # @param AutoGenH The TemplateString object for header file
2102 # @param StringH The TemplateString object for header file
2103 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
2104 # @param UniGenBinBuffer Buffer to store uni string package data
2105 # @param StringIdf The TemplateString object for header file
2106 # @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
2107 # @param IdfGenBinBuffer Buffer to store Idf string package data
2109 def CreateCode(Info
, AutoGenC
, AutoGenH
, StringH
, UniGenCFlag
, UniGenBinBuffer
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
):
2110 CreateHeaderCode(Info
, AutoGenC
, AutoGenH
)
2112 if Info
.AutoGenVersion
>= 0x00010005:
2113 CreateGuidDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2114 CreateProtocolDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2115 CreatePpiDefinitionCode(Info
, AutoGenC
, AutoGenH
)
2116 CreatePcdCode(Info
, AutoGenC
, AutoGenH
)
2117 CreateLibraryConstructorCode(Info
, AutoGenC
, AutoGenH
)
2118 CreateLibraryDestructorCode(Info
, AutoGenC
, AutoGenH
)
2119 CreateModuleEntryPointCode(Info
, AutoGenC
, AutoGenH
)
2120 CreateModuleUnloadImageCode(Info
, AutoGenC
, AutoGenH
)
2122 if Info
.UnicodeFileList
:
2123 FileName
= "%sStrDefs.h" % Info
.Name
2124 StringH
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2125 StringH
.Append(gAutoGenHPrologueString
.Replace({'File':'STRDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2126 CreateUnicodeStringCode(Info
, AutoGenC
, StringH
, UniGenCFlag
, UniGenBinBuffer
)
2129 for Guid
in Info
.Module
.Guids
:
2130 if Guid
in Info
.Module
.GetGuidsUsedByPcd():
2132 GuidMacros
.append('#define %s %s' % (Guid
, Info
.Module
.Guids
[Guid
]))
2133 for Guid
, Value
in Info
.Module
.Protocols
.items() + Info
.Module
.Ppis
.items():
2134 GuidMacros
.append('#define %s %s' % (Guid
, Value
))
2135 # supports FixedAtBuild usage in VFR file
2136 if Info
.VfrFileList
and Info
.ModulePcdList
:
2137 GuidMacros
.append('#define %s %s' % ('FixedPcdGetBool(TokenName)', '_PCD_VALUE_##TokenName'))
2138 GuidMacros
.append('#define %s %s' % ('FixedPcdGet8(TokenName)', '_PCD_VALUE_##TokenName'))
2139 GuidMacros
.append('#define %s %s' % ('FixedPcdGet16(TokenName)', '_PCD_VALUE_##TokenName'))
2140 GuidMacros
.append('#define %s %s' % ('FixedPcdGet32(TokenName)', '_PCD_VALUE_##TokenName'))
2141 GuidMacros
.append('#define %s %s' % ('FixedPcdGet64(TokenName)', '_PCD_VALUE_##TokenName'))
2142 for Pcd
in Info
.ModulePcdList
:
2143 if Pcd
.Type
== TAB_PCDS_FIXED_AT_BUILD
:
2144 TokenCName
= Pcd
.TokenCName
2145 Value
= Pcd
.DefaultValue
2146 if Pcd
.DatumType
== 'BOOLEAN':
2147 BoolValue
= Value
.upper()
2148 if BoolValue
== 'TRUE':
2150 elif BoolValue
== 'FALSE':
2152 for PcdItem
in GlobalData
.MixedPcd
:
2153 if (Pcd
.TokenCName
, Pcd
.TokenSpaceGuidCName
) in GlobalData
.MixedPcd
[PcdItem
]:
2154 TokenCName
= PcdItem
[0]
2156 GuidMacros
.append('#define %s %s' % ('_PCD_VALUE_'+TokenCName
, Value
))
2158 if Info
.IdfFileList
:
2159 GuidMacros
.append('#include "%sImgDefs.h"' % Info
.Name
)
2162 StringH
.Append('\n#ifdef VFRCOMPILE\n%s\n#endif\n' % '\n'.join(GuidMacros
))
2164 StringH
.Append("\n#endif\n")
2165 AutoGenH
.Append('#include "%s"\n' % FileName
)
2167 if Info
.IdfFileList
:
2168 FileName
= "%sImgDefs.h" % Info
.Name
2169 StringIdf
.Append(gAutoGenHeaderString
.Replace({'FileName':FileName
}))
2170 StringIdf
.Append(gAutoGenHPrologueString
.Replace({'File':'IMAGEDEFS', 'Guid':Info
.Guid
.replace('-','_')}))
2171 CreateIdfFileCode(Info
, AutoGenC
, StringIdf
, IdfGenCFlag
, IdfGenBinBuffer
)
2173 StringIdf
.Append("\n#endif\n")
2174 AutoGenH
.Append('#include "%s"\n' % FileName
)
2176 CreateFooterCode(Info
, AutoGenC
, AutoGenH
)
2178 # no generation of AutoGen.c for Edk modules without unicode file
2179 if Info
.AutoGenVersion
< 0x00010005 and len(Info
.UnicodeFileList
) == 0:
2180 AutoGenC
.String
= ''
2182 ## Create the code file
2184 # @param FilePath The path of code file
2185 # @param Content The content of code file
2186 # @param IsBinaryFile The flag indicating if the file is binary file or not
2188 # @retval True If file content is changed or file doesn't exist
2189 # @retval False If the file exists and the content is not changed
2191 def Generate(FilePath
, Content
, IsBinaryFile
):
2192 return SaveFileOnChange(FilePath
, Content
, IsBinaryFile
)