2014-01-27 05:23:15 +00:00
## @file
# Routines for generating AutoGen.h and AutoGen.c
#
2018-03-14 16:51:04 +08:00
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
2019-04-03 16:03:11 -07:00
# SPDX-License-Identifier: BSD-2-Clause-Patent
2014-01-27 05:23:15 +00:00
#
## Import Modules
#
2018-10-15 08:27:53 +08:00
from __future__ import absolute_import
2014-01-27 05:23:15 +00:00
import string
2016-09-21 10:39:11 +08:00
import collections
import struct
2014-01-27 05:23:15 +00:00
from Common import EdkLogger
2019-01-10 03:00:41 +08:00
from Common import GlobalData
2014-01-27 05:23:15 +00:00
from Common.BuildToolError import *
from Common.DataType import *
from Common.Misc import *
2018-05-19 18:50:25 +08:00
from Common.StringUtils import StringToArray
2018-07-13 18:18:37 +08:00
from .StrGather import *
from .GenPcdDb import CreatePcdDatabaseCode
from .IdfClassObject import *
2014-01-27 05:23:15 +00:00
2024-06-14 14:07:33 -07:00
import json
import secrets
2014-01-27 05:23:15 +00:00
## PCD type string
gItemTypeStringDatabase = {
2018-04-27 00:57:55 +08:00
TAB_PCDS_FEATURE_FLAG : TAB_PCDS_FIXED_AT_BUILD ,
TAB_PCDS_FIXED_AT_BUILD : TAB_PCDS_FIXED_AT_BUILD ,
2014-01-27 05:23:15 +00:00
TAB_PCDS_PATCHABLE_IN_MODULE : 'BinaryPatch' ,
TAB_PCDS_DYNAMIC : '' ,
TAB_PCDS_DYNAMIC_DEFAULT : '' ,
TAB_PCDS_DYNAMIC_VPD : '' ,
TAB_PCDS_DYNAMIC_HII : '' ,
TAB_PCDS_DYNAMIC_EX : '' ,
TAB_PCDS_DYNAMIC_EX_DEFAULT : '' ,
TAB_PCDS_DYNAMIC_EX_VPD : '' ,
TAB_PCDS_DYNAMIC_EX_HII : '' ,
}
## Datum size
2018-04-11 09:14:05 -07:00
gDatumSizeStringDatabase = { TAB_UINT8 : '8' , TAB_UINT16 : '16' , TAB_UINT32 : '32' , TAB_UINT64 : '64' , 'BOOLEAN' : 'BOOLEAN' , TAB_VOID : '8' }
gDatumSizeStringDatabaseH = { TAB_UINT8 : '8' , TAB_UINT16 : '16' , TAB_UINT32 : '32' , TAB_UINT64 : '64' , 'BOOLEAN' : 'BOOL' , TAB_VOID : 'PTR' }
gDatumSizeStringDatabaseLib = { TAB_UINT8 : '8' , TAB_UINT16 : '16' , TAB_UINT32 : '32' , TAB_UINT64 : '64' , 'BOOLEAN' : 'Bool' , TAB_VOID : 'Ptr' }
2014-01-27 05:23:15 +00:00
## AutoGen File Header Templates
gAutoGenHeaderString = TemplateString ( """ \
/**
DO NOT EDIT
FILE auto-generated
Module name:
$ {FileName}
Abstract: Auto-generated $ {FileName} for building module or library.
**/
""" )
gAutoGenHPrologueString = TemplateString ( """
#ifndef _$ {File} _$ {Guid}
#define _$ {File} _$ {Guid}
""" )
gAutoGenHCppPrologueString = """ \
#ifdef __cplusplus
extern "C" {
#endif
"""
gAutoGenHEpilogueString = """
#ifdef __cplusplus
}
#endif
#endif
"""
## PEI Core Entry Point Templates
gPeiCoreEntryPointPrototype = TemplateString ( """
$ {BEGIN}
VOID
EFIAPI
$ {Function} (
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
IN VOID *Context
);
$ {END}
""" )
gPeiCoreEntryPointString = TemplateString ( """
$ {BEGIN}
VOID
EFIAPI
ProcessModuleEntryPointList (
IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,
IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,
IN VOID *Context
)
{
$ {Function} (SecCoreData, PpiList, Context);
}
$ {END}
""" )
## DXE Core Entry Point Templates
gDxeCoreEntryPointPrototype = TemplateString ( """
$ {BEGIN}
VOID
EFIAPI
$ {Function} (
IN VOID *HobStart
);
$ {END}
""" )
gDxeCoreEntryPointString = TemplateString ( """
$ {BEGIN}
VOID
EFIAPI
ProcessModuleEntryPointList (
IN VOID *HobStart
)
{
$ {Function} (HobStart);
}
$ {END}
""" )
## PEIM Entry Point Templates
gPeimEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
);
$ {END}
""" )
gPeimEntryPointString = [
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = $ {PiSpecVersion} ;
$ {BEGIN}
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
return $ {Function} (FileHandle, PeiServices);
}
$ {END}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gPeimRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
EFI_STATUS CombinedStatus;
CombinedStatus = EFI_LOAD_ERROR;
$ {BEGIN}
Status = $ {Function} (FileHandle, PeiServices);
if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
CombinedStatus = Status;
}
$ {END}
return CombinedStatus;
}
""" )
]
## SMM_CORE Entry Point Templates
gSmmCoreEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
$ {END}
""" )
gSmmCoreEntryPointString = TemplateString ( """
$ {BEGIN}
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return $ {Function} (ImageHandle, SystemTable);
}
$ {END}
""" )
2017-06-27 00:47:39 +08:00
## MM_CORE_STANDALONE Entry Point Templates
gMmCoreStandaloneEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN VOID *HobStart
);
$ {END}
""" )
gMmCoreStandaloneEntryPointString = TemplateString ( """
$ {BEGIN}
const UINT32 _gMmRevision = $ {PiSpecVersion} ;
VOID
EFIAPI
ProcessModuleEntryPointList (
IN VOID *HobStart
)
{
$ {Function} (HobStart);
}
$ {END}
""" )
## MM_STANDALONE Entry Point Templates
gMmStandaloneEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
);
$ {END}
""" )
gMmStandaloneEntryPointString = [
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = $ {PiSpecVersion} ;
$ {BEGIN}
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
)
{
return $ {Function} (ImageHandle, MmSystemTable);
}
$ {END}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT32 _gMmRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
)
{
EFI_STATUS Status;
EFI_STATUS CombinedStatus;
CombinedStatus = EFI_LOAD_ERROR;
$ {BEGIN}
Status = $ {Function} (ImageHandle, MmSystemTable);
if (!EFI_ERROR (Status) || EFI_ERROR (CombinedStatus)) {
CombinedStatus = Status;
}
$ {END}
return CombinedStatus;
}
""" )
]
2014-01-27 05:23:15 +00:00
## DXE SMM Entry Point Templates
gDxeSmmEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
$ {END}
""" )
gDxeSmmEntryPointString = [
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
static EFI_STATUS mDriverEntryPointStatus;
VOID
EFIAPI
ExitDriver (
IN EFI_STATUS Status
)
{
if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
mDriverEntryPointStatus = Status;
}
LongJump (&mJumpContext, (UINTN)-1);
ASSERT (FALSE);
}
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
mDriverEntryPointStatus = EFI_LOAD_ERROR;
$ {BEGIN}
if (SetJump (&mJumpContext) == 0) {
ExitDriver ($ {Function} (ImageHandle, SystemTable));
ASSERT (FALSE);
}
$ {END}
return mDriverEntryPointStatus;
}
""" )
]
## UEFI Driver Entry Point Templates
gUefiDriverEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
$ {END}
""" )
gUefiDriverEntryPointString = [
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
$ {BEGIN}
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return $ {Function} (ImageHandle, SystemTable);
}
$ {END}
VOID
EFIAPI
ExitDriver (
IN EFI_STATUS Status
)
{
if (EFI_ERROR (Status)) {
ProcessLibraryDestructorList (gImageHandle, gST);
}
gBS->Exit (gImageHandle, Status, 0, NULL);
}
""" ),
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
const UINT32 _gDxeRevision = $ {PiSpecVersion} ;
static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
static EFI_STATUS mDriverEntryPointStatus;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
mDriverEntryPointStatus = EFI_LOAD_ERROR;
$ {BEGIN}
if (SetJump (&mJumpContext) == 0) {
ExitDriver ($ {Function} (ImageHandle, SystemTable));
ASSERT (FALSE);
}
$ {END}
return mDriverEntryPointStatus;
}
VOID
EFIAPI
ExitDriver (
IN EFI_STATUS Status
)
{
if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
mDriverEntryPointStatus = Status;
}
LongJump (&mJumpContext, (UINTN)-1);
ASSERT (FALSE);
}
""" )
]
## UEFI Application Entry Point Templates
gUefiApplicationEntryPointPrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
$ {END}
""" )
gUefiApplicationEntryPointString = [
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
$ {BEGIN}
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return $ {Function} (ImageHandle, SystemTable);
}
$ {END}
VOID
EFIAPI
ExitDriver (
IN EFI_STATUS Status
)
{
if (EFI_ERROR (Status)) {
ProcessLibraryDestructorList (gImageHandle, gST);
}
gBS->Exit (gImageHandle, Status, 0, NULL);
}
""" ),
TemplateString ( """
const UINT32 _gUefiDriverRevision = $ {UefiSpecVersion} ;
EFI_STATUS
EFIAPI
ProcessModuleEntryPointList (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
$ {BEGIN}
if (SetJump (&mJumpContext) == 0) {
ExitDriver ($ {Function} (ImageHandle, SystemTable));
ASSERT (FALSE);
}
$ {END}
return mDriverEntryPointStatus;
}
static BASE_LIBRARY_JUMP_BUFFER mJumpContext;
static EFI_STATUS mDriverEntryPointStatus = EFI_LOAD_ERROR;
VOID
EFIAPI
ExitDriver (
IN EFI_STATUS Status
)
{
if (!EFI_ERROR (Status) || EFI_ERROR (mDriverEntryPointStatus)) {
mDriverEntryPointStatus = Status;
}
LongJump (&mJumpContext, (UINTN)-1);
ASSERT (FALSE);
}
""" )
]
## UEFI Unload Image Templates
gUefiUnloadImagePrototype = TemplateString ( """
$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle
);
$ {END}
""" )
gUefiUnloadImageString = [
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = $ {Count} ;
EFI_STATUS
EFIAPI
ProcessModuleUnloadList (
IN EFI_HANDLE ImageHandle
)
{
return EFI_SUCCESS;
}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = $ {Count} ;
$ {BEGIN}
EFI_STATUS
EFIAPI
ProcessModuleUnloadList (
IN EFI_HANDLE ImageHandle
)
{
return $ {Function} (ImageHandle);
}
$ {END}
""" ),
TemplateString ( """
GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gDriverUnloadImageCount = $ {Count} ;
EFI_STATUS
EFIAPI
ProcessModuleUnloadList (
IN EFI_HANDLE ImageHandle
)
{
EFI_STATUS Status;
Status = EFI_SUCCESS;
$ {BEGIN}
if (EFI_ERROR (Status)) {
$ {Function} (ImageHandle);
} else {
Status = $ {Function} (ImageHandle);
}
$ {END}
return Status;
}
""" )
]
gLibraryStructorPrototype = {
2018-04-27 00:57:53 +08:00
SUP_MODULE_BASE : TemplateString ( """$ {BEGIN}
2014-01-27 05:23:15 +00:00
RETURN_STATUS
EFIAPI
$ {Function} (
VOID
);$ {END}
""" ),
'PEI' : TemplateString ( """$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
);$ {END}
""" ),
'DXE' : TemplateString ( """$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);$ {END}
""" ),
2017-06-27 00:47:39 +08:00
'MM' : TemplateString ( """$ {BEGIN}
EFI_STATUS
EFIAPI
$ {Function} (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
);$ {END}
""" ),
2014-01-27 05:23:15 +00:00
}
gLibraryStructorCall = {
2018-04-27 00:57:53 +08:00
SUP_MODULE_BASE : TemplateString ( """$ {BEGIN}
2014-01-27 05:23:15 +00:00
Status = $ {Function} ();
2019-02-20 19:33:18 +08:00
ASSERT_RETURN_ERROR (Status);$ {END}
2014-01-27 05:23:15 +00:00
""" ),
'PEI' : TemplateString ( """$ {BEGIN}
Status = $ {Function} (FileHandle, PeiServices);
ASSERT_EFI_ERROR (Status);$ {END}
""" ),
'DXE' : TemplateString ( """$ {BEGIN}
Status = $ {Function} (ImageHandle, SystemTable);
ASSERT_EFI_ERROR (Status);$ {END}
""" ),
2017-06-27 00:47:39 +08:00
'MM' : TemplateString ( """$ {BEGIN}
Status = $ {Function} (ImageHandle, MmSystemTable);
ASSERT_EFI_ERROR (Status);$ {END}
""" ),
2014-01-27 05:23:15 +00:00
}
## Library Constructor and Destructor Templates
gLibraryString = {
2018-04-27 00:57:53 +08:00
SUP_MODULE_BASE : TemplateString ( """
2014-01-27 05:23:15 +00:00
$ {BEGIN} $ {FunctionPrototype} $ {END}
VOID
EFIAPI
ProcessLibrary$ {Type} List (
VOID
)
{
2019-02-20 19:33:18 +08:00
$ {BEGIN} RETURN_STATUS Status;
2014-01-27 05:23:15 +00:00
$ {FunctionCall} $ {END}
}
""" ),
'PEI' : TemplateString ( """
$ {BEGIN} $ {FunctionPrototype} $ {END}
VOID
EFIAPI
ProcessLibrary$ {Type} List (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
$ {BEGIN} EFI_STATUS Status;
$ {FunctionCall} $ {END}
}
""" ),
'DXE' : TemplateString ( """
$ {BEGIN} $ {FunctionPrototype} $ {END}
VOID
EFIAPI
ProcessLibrary$ {Type} List (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
$ {BEGIN} EFI_STATUS Status;
$ {FunctionCall} $ {END}
}
""" ),
2017-06-27 00:47:39 +08:00
'MM' : TemplateString ( """
$ {BEGIN} $ {FunctionPrototype} $ {END}
VOID
EFIAPI
ProcessLibrary$ {Type} List (
IN EFI_HANDLE ImageHandle,
2018-07-03 18:00:35 +08:00
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
2017-06-27 00:47:39 +08:00
)
{
$ {BEGIN} EFI_STATUS Status;
$ {FunctionCall} $ {END}
}
""" ),
2014-01-27 05:23:15 +00:00
}
gBasicHeaderFile = "Base.h"
gModuleTypeHeaderFile = {
2019-02-20 19:33:18 +08:00
SUP_MODULE_BASE : [ gBasicHeaderFile , "Library/DebugLib.h" ],
2018-04-27 00:57:53 +08:00
SUP_MODULE_SEC : [ "PiPei.h" , "Library/DebugLib.h" ],
SUP_MODULE_PEI_CORE : [ "PiPei.h" , "Library/DebugLib.h" , "Library/PeiCoreEntryPoint.h" ],
SUP_MODULE_PEIM : [ "PiPei.h" , "Library/DebugLib.h" , "Library/PeimEntryPoint.h" ],
SUP_MODULE_DXE_CORE : [ "PiDxe.h" , "Library/DebugLib.h" , "Library/DxeCoreEntryPoint.h" ],
SUP_MODULE_DXE_DRIVER : [ "PiDxe.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiBootServicesTableLib.h" , "Library/UefiDriverEntryPoint.h" ],
SUP_MODULE_DXE_SMM_DRIVER : [ "PiDxe.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiBootServicesTableLib.h" , "Library/UefiDriverEntryPoint.h" ],
SUP_MODULE_DXE_RUNTIME_DRIVER : [ "PiDxe.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiBootServicesTableLib.h" , "Library/UefiDriverEntryPoint.h" ],
SUP_MODULE_UEFI_DRIVER : [ "Uefi.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiBootServicesTableLib.h" , "Library/UefiDriverEntryPoint.h" ],
SUP_MODULE_UEFI_APPLICATION : [ "Uefi.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiBootServicesTableLib.h" , "Library/UefiApplicationEntryPoint.h" ],
SUP_MODULE_SMM_CORE : [ "PiDxe.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/UefiDriverEntryPoint.h" ],
2018-07-03 18:00:35 +08:00
SUP_MODULE_MM_STANDALONE : [ "PiMm.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/StandaloneMmDriverEntryPoint.h" ],
SUP_MODULE_MM_CORE_STANDALONE : [ "PiMm.h" , "Library/BaseLib.h" , "Library/DebugLib.h" , "Library/StandaloneMmCoreEntryPoint.h" ],
2019-07-01 06:19:13 +00:00
SUP_MODULE_USER_DEFINED : [ gBasicHeaderFile , "Library/DebugLib.h" ],
SUP_MODULE_HOST_APPLICATION : [ gBasicHeaderFile , "Library/DebugLib.h" ]
2014-01-27 05:23:15 +00:00
}
2018-07-05 17:40:04 +08:00
## Autogen internal worker macro to define DynamicEx PCD name includes both the TokenSpaceGuidName
2014-01-27 05:23:15 +00:00
# the TokenName and Guid comparison to avoid define name collisions.
#
# @param Info The ModuleAutoGen object
# @param AutoGenH The TemplateString object for header file
#
#
def DynExPcdTokenNumberMapping ( Info , AutoGenH ):
ExTokenCNameList = []
PcdExList = []
2017-03-21 17:06:47 +08:00
# Even it is the Library, the PCD is saved in the ModulePcdList
PcdList = Info . ModulePcdList
2014-01-27 05:23:15 +00:00
for Pcd in PcdList :
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET :
2014-01-27 05:23:15 +00:00
ExTokenCNameList . append ( Pcd . TokenCName )
PcdExList . append ( Pcd )
if len ( ExTokenCNameList ) == 0 :
return
AutoGenH . Append ( ' \n #define COMPAREGUID(Guid1, Guid2) (BOOLEAN)(*(CONST UINT64*)Guid1 == *(CONST UINT64*)Guid2 && *((CONST UINT64*)Guid1 + 1) == *((CONST UINT64*)Guid2 + 1)) \n ' )
# AutoGen for each PCD listed in a [PcdEx] section of a Module/Lib INF file.
2018-07-05 17:40:04 +08:00
# Auto generate a macro for each TokenName that takes a Guid pointer as a parameter.
2014-01-27 05:23:15 +00:00
# Use the Guid pointer to see if it matches any of the token space GUIDs.
2018-04-11 07:17:24 +08:00
TokenCNameList = set ()
2014-01-27 05:23:15 +00:00
for TokenCName in ExTokenCNameList :
if TokenCName in TokenCNameList :
continue
Index = 0
Count = ExTokenCNameList . count ( TokenCName )
for Pcd in PcdExList :
2016-04-12 10:31:55 +08:00
RealTokenCName = Pcd . TokenCName
for PcdItem in GlobalData . MixedPcd :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) in GlobalData . MixedPcd [ PcdItem ]:
RealTokenCName = PcdItem [ 0 ]
break
2014-01-27 05:23:15 +00:00
if Pcd . TokenCName == TokenCName :
Index = Index + 1
if Index == 1 :
2016-04-12 10:31:55 +08:00
AutoGenH . Append ( ' \n #define __PCD_ %s _ADDR_CMP(GuidPtr) (' % ( RealTokenCName ))
2018-07-05 17:40:04 +08:00
AutoGenH . Append ( ' \\\n (GuidPtr == & %s ) ? _PCD_TOKEN_ %s _ %s :'
2016-04-12 10:31:55 +08:00
% ( Pcd . TokenSpaceGuidCName , Pcd . TokenSpaceGuidCName , RealTokenCName ))
2014-01-27 05:23:15 +00:00
else :
2018-07-05 17:40:04 +08:00
AutoGenH . Append ( ' \\\n (GuidPtr == & %s ) ? _PCD_TOKEN_ %s _ %s :'
2016-04-12 10:31:55 +08:00
% ( Pcd . TokenSpaceGuidCName , Pcd . TokenSpaceGuidCName , RealTokenCName ))
2014-01-27 05:23:15 +00:00
if Index == Count :
AutoGenH . Append ( '0 \\\n ) \n ' )
2018-04-11 07:17:24 +08:00
TokenCNameList . add ( TokenCName )
2018-07-05 17:40:04 +08:00
2018-04-11 07:17:24 +08:00
TokenCNameList = set ()
2014-01-27 05:23:15 +00:00
for TokenCName in ExTokenCNameList :
if TokenCName in TokenCNameList :
continue
Index = 0
Count = ExTokenCNameList . count ( TokenCName )
for Pcd in PcdExList :
2016-04-12 10:31:55 +08:00
RealTokenCName = Pcd . TokenCName
for PcdItem in GlobalData . MixedPcd :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) in GlobalData . MixedPcd [ PcdItem ]:
RealTokenCName = PcdItem [ 0 ]
break
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd . TokenCName == TokenCName :
2014-01-27 05:23:15 +00:00
Index = Index + 1
if Index == 1 :
2016-04-12 10:31:55 +08:00
AutoGenH . Append ( ' \n #define __PCD_ %s _VAL_CMP(GuidPtr) (' % ( RealTokenCName ))
2015-08-24 05:00:05 +00:00
AutoGenH . Append ( ' \\\n (GuidPtr == NULL) ? 0:' )
2018-07-05 17:40:04 +08:00
AutoGenH . Append ( ' \\\n COMPAREGUID (GuidPtr, & %s ) ? _PCD_TOKEN_ %s _ %s :'
2016-04-12 10:31:55 +08:00
% ( Pcd . TokenSpaceGuidCName , Pcd . TokenSpaceGuidCName , RealTokenCName ))
2014-01-27 05:23:15 +00:00
else :
2018-07-05 17:40:04 +08:00
AutoGenH . Append ( ' \\\n COMPAREGUID (GuidPtr, & %s ) ? _PCD_TOKEN_ %s _ %s :'
2016-04-12 10:31:55 +08:00
% ( Pcd . TokenSpaceGuidCName , Pcd . TokenSpaceGuidCName , RealTokenCName ))
2014-01-27 05:23:15 +00:00
if Index == Count :
AutoGenH . Append ( '0 \\\n ) \n ' )
2018-07-05 17:40:04 +08:00
# Autogen internal worker macro to compare GUIDs. Guid1 is a pointer to a GUID.
2014-01-27 05:23:15 +00:00
# Guid2 is a C name for a GUID. Compare pointers first because optimizing compiler
# can do this at build time on CONST GUID pointers and optimize away call to COMPAREGUID().
# COMPAREGUID() will only be used if the Guid passed in is local to the module.
AutoGenH . Append ( '#define _PCD_TOKEN_EX_ %s (GuidPtr) __PCD_ %s _ADDR_CMP(GuidPtr) ? __PCD_ %s _ADDR_CMP(GuidPtr) : __PCD_ %s _VAL_CMP(GuidPtr) \n '
2016-04-12 10:31:55 +08:00
% ( RealTokenCName , RealTokenCName , RealTokenCName , RealTokenCName ))
2018-04-11 07:17:24 +08:00
TokenCNameList . add ( TokenCName )
2014-01-27 05:23:15 +00:00
## Create code for module PCDs
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
# @param Pcd The PCD object
#
def CreateModulePcdCode ( Info , AutoGenC , AutoGenH , Pcd ):
TokenSpaceGuidValue = Pcd . TokenSpaceGuidValue #Info.GuidList[Pcd.TokenSpaceGuidCName]
PcdTokenNumber = Info . PlatformInfo . PcdTokenNumber
#
# Write PCDs
#
2016-04-12 10:31:55 +08:00
TokenCName = Pcd . TokenCName
for PcdItem in GlobalData . MixedPcd :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) in GlobalData . MixedPcd [ PcdItem ]:
TokenCName = PcdItem [ 0 ]
break
PcdTokenName = '_PCD_TOKEN_' + TokenCName
PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName + '_SIZE'
PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName
2018-03-14 20:20:23 +08:00
PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName
2016-04-12 10:31:55 +08:00
FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName
2018-03-13 22:44:01 +08:00
FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName
2016-04-12 10:31:55 +08:00
2018-03-08 13:56:21 +08:00
if Pcd . PcdValueFromComm :
Pcd . DefaultValue = Pcd . PcdValueFromComm
2018-06-22 17:14:13 +08:00
elif Pcd . PcdValueFromFdf :
Pcd . DefaultValue = Pcd . PcdValueFromFdf
2018-07-05 17:40:04 +08:00
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET :
2014-01-27 05:23:15 +00:00
TokenNumber = int ( Pcd . TokenValue , 0 )
2018-07-05 17:40:04 +08:00
# Add TokenSpaceGuidValue value to PcdTokenName to discriminate the DynamicEx PCDs with
2014-01-27 05:23:15 +00:00
# different Guids but same TokenCName
2016-04-12 10:31:55 +08:00
PcdExTokenName = '_PCD_TOKEN_' + Pcd . TokenSpaceGuidCName + '_' + TokenCName
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( ' \n #define %s %d U \n ' % ( PcdExTokenName , TokenNumber ))
else :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) not in PcdTokenNumber :
2018-07-05 17:40:04 +08:00
# If one of the Source built modules listed in the DSC is not listed in FDF modules,
# and the INF lists a PCD can only use the PcdsDynamic access method (it is only
# listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
# report warning message notify the PI that they are attempting to build a module
# that must be included in a flash image in order to be functional. These Dynamic PCD
# will not be added into the Database unless it is used by other modules that are
# included in the FDF file.
2014-01-27 05:23:15 +00:00
# In this case, just assign an invalid token number to make it pass build.
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_TYPE_SET :
2014-01-27 05:23:15 +00:00
TokenNumber = 0
else :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"No generated token number for %s . %s \n " % ( Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
else :
TokenNumber = PcdTokenNumber [ Pcd . TokenCName , Pcd . TokenSpaceGuidCName ]
AutoGenH . Append ( ' \n #define %s %d U \n ' % ( PcdTokenName , TokenNumber ))
2016-04-12 10:31:55 +08:00
EdkLogger . debug ( EdkLogger . DEBUG_3 , "Creating code for " + TokenCName + "." + Pcd . TokenSpaceGuidCName )
2014-01-27 05:23:15 +00:00
if Pcd . Type not in gItemTypeStringDatabase :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"Unknown PCD type [ %s ] of PCD %s . %s " % ( Pcd . Type , Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
2018-04-11 09:14:05 -07:00
DatumSize = gDatumSizeStringDatabase [ Pcd . DatumType ] if Pcd . DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase [ TAB_VOID ]
DatumSizeLib = gDatumSizeStringDatabaseLib [ Pcd . DatumType ] if Pcd . DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib [ TAB_VOID ]
GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_' + TokenCName
SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_' + TokenCName
SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_S_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_S_' + TokenCName
2016-04-12 10:31:55 +08:00
GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
2018-07-05 17:40:04 +08:00
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET :
2014-01-27 05:23:15 +00:00
if Info . IsLibrary :
PcdList = Info . LibraryPcdList
else :
2018-10-15 08:27:53 +08:00
PcdList = Info . ModulePcdList + Info . LibraryPcdList
2018-04-11 07:17:24 +08:00
PcdExCNameTest = 0
2014-01-27 05:23:15 +00:00
for PcdModule in PcdList :
2018-04-20 23:51:37 +08:00
if PcdModule . Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd . TokenCName == PcdModule . TokenCName :
2018-04-11 07:17:24 +08:00
PcdExCNameTest += 1
# get out early once we found > 1...
if PcdExCNameTest > 1 :
break
2014-01-27 05:23:15 +00:00
# Be compatible with the current code which using PcdToken and PcdGet/Set for DynamicEx Pcd.
# If only PcdToken and PcdGet/Set used in all Pcds with different CName, it should succeed to build.
# If PcdToken and PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
2018-04-11 07:17:24 +08:00
if PcdExCNameTest > 1 :
2014-01-27 05:23:15 +00:00
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 ' )
AutoGenH . Append ( '// #define %s %s \n ' % ( PcdTokenName , PcdExTokenName ))
AutoGenH . Append ( '// #define %s LibPcdGetEx %s (& %s , %s ) \n ' % ( GetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '// #define %s LibPcdGetExSize(& %s , %s ) \n ' % ( GetModeSizeName , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '// #define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s (& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '// #define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s S(& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '// #define %s (Value) LibPcdSetEx %s (& %s , %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '// #define %s (Value) LibPcdSetEx %s S(& %s , %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define %s %s \n ' % ( PcdTokenName , PcdExTokenName ))
AutoGenH . Append ( '#define %s LibPcdGetEx %s (& %s , %s ) \n ' % ( GetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s LibPcdGetExSize(& %s , %s ) \n ' % ( GetModeSizeName , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s (& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s S(& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define %s (Value) LibPcdSetEx %s (& %s , %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '#define %s (Value) LibPcdSetEx %s S(& %s , %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-04-20 23:51:37 +08:00
elif Pcd . Type in PCD_DYNAMIC_TYPE_SET :
2018-04-11 07:17:24 +08:00
PcdCNameTest = 0
2018-10-15 08:27:53 +08:00
for PcdModule in Info . LibraryPcdList + Info . ModulePcdList :
2018-04-20 23:51:37 +08:00
if PcdModule . Type in PCD_DYNAMIC_TYPE_SET and Pcd . TokenCName == PcdModule . TokenCName :
2018-04-11 07:17:24 +08:00
PcdCNameTest += 1
# get out early once we found > 1...
if PcdCNameTest > 1 :
break
if PcdCNameTest > 1 :
2016-04-12 10:31:55 +08:00
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 ))
2014-01-27 05:23:15 +00:00
else :
2015-11-30 03:40:37 +00:00
AutoGenH . Append ( '#define %s LibPcdGet %s ( %s ) \n ' % ( GetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s LibPcdGetSize( %s ) \n ' % ( GetModeSizeName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2015-11-30 03:40:37 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSet %s ( %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSet %s S( %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , PcdTokenName ))
else :
AutoGenH . Append ( '#define %s (Value) LibPcdSet %s ( %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s (Value) LibPcdSet %s S( %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
2016-04-12 10:31:55 +08:00
PcdVariableName = '_gPcd_' + gItemTypeStringDatabase [ Pcd . Type ] + '_' + TokenCName
2014-01-27 05:23:15 +00:00
Const = 'const'
if Pcd . Type == TAB_PCDS_PATCHABLE_IN_MODULE :
Const = ''
Type = ''
Array = ''
Value = Pcd . DefaultValue
Unicode = False
ValueNumber = 0
if Pcd . DatumType == 'BOOLEAN' :
BoolValue = Value . upper ()
if BoolValue == 'TRUE' or BoolValue == '1' :
Value = '1U'
elif BoolValue == 'FALSE' or BoolValue == '0' :
Value = '0U'
2018-04-11 09:14:05 -07:00
if Pcd . DatumType in TAB_PCD_CLEAN_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
try :
2017-12-26 16:17:13 +08:00
if Value . upper () . endswith ( 'L' ):
Value = Value [: - 1 ]
2019-01-16 20:22:11 +08:00
if Value . startswith ( '0' ) and not Value . lower () . startswith ( '0x' ) and len ( Value ) > 1 and Value . lstrip ( '0' ):
2018-12-16 15:19:42 +08:00
Value = Value . lstrip ( '0' )
2018-03-29 08:02:17 +08:00
ValueNumber = int ( Value , 0 )
2014-01-27 05:23:15 +00:00
except :
2018-10-15 08:27:53 +08:00
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"PCD value is not valid dec or hex number for datum type [ %s ] of PCD %s . %s " % ( Pcd . DatumType , Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
2018-09-27 14:08:15 +08:00
if ValueNumber < 0 :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
"PCD can't be set to negative value for datum type [ %s ] of PCD %s . %s " % ( Pcd . DatumType , Pcd . TokenSpaceGuidCName , TokenCName ),
ExtraData = "[ %s ]" % str ( Info ))
elif ValueNumber > MAX_VAL_TYPE [ Pcd . DatumType ]:
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
"Too large PCD value for datum type [ %s ] of PCD %s . %s " % ( Pcd . DatumType , Pcd . TokenSpaceGuidCName , TokenCName ),
ExtraData = "[ %s ]" % str ( Info ))
if Pcd . DatumType == TAB_UINT64 and not Value . endswith ( 'ULL' ):
Value += 'ULL'
elif Pcd . DatumType != TAB_UINT64 and not Value . endswith ( 'U' ):
Value += 'U'
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2018-05-07 18:26:24 +08:00
if not Pcd . MaxDatumSize :
2014-01-27 05:23:15 +00:00
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"Unknown [MaxDatumSize] of PCD [ %s . %s ]" % ( Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
ArraySize = int ( Pcd . MaxDatumSize , 0 )
if Value [ 0 ] == '{' :
Type = '(VOID *)'
2018-05-07 18:26:24 +08:00
ValueSize = len ( Value . split ( ',' ))
2014-01-27 05:23:15 +00:00
else :
if Value [ 0 ] == 'L' :
Unicode = True
Value = Value . lstrip ( 'L' ) #.strip('"')
Value = eval ( Value ) # translate escape character
2018-05-07 18:26:24 +08:00
ValueSize = len ( Value ) + 1
2014-01-27 05:23:15 +00:00
NewValue = '{'
2018-06-25 18:31:33 +08:00
for Index in range ( 0 , len ( Value )):
2014-01-27 05:23:15 +00:00
if Unicode :
NewValue = NewValue + str ( ord ( Value [ Index ]) % 0x10000 ) + ', '
else :
NewValue = NewValue + str ( ord ( Value [ Index ]) % 0x100 ) + ', '
if Unicode :
2018-12-07 12:34:44 +08:00
ArraySize = ArraySize // 2
2014-01-27 05:23:15 +00:00
Value = NewValue + '0 }'
2018-05-07 18:26:24 +08:00
if ArraySize < ValueSize :
if Pcd . MaxSizeUserSet :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
"The maximum size of VOID* type PCD ' %s . %s ' is less than its actual size occupied." % ( Pcd . TokenSpaceGuidCName , TokenCName ),
ExtraData = "[ %s ]" % str ( Info ))
else :
ArraySize = Pcd . GetPcdSize ()
if Unicode :
2018-12-07 12:34:44 +08:00
ArraySize = ArraySize // 2
2014-01-27 05:23:15 +00:00
Array = '[ %d ]' % ArraySize
#
# skip casting for fixed at build since it breaks ARM assembly.
# Long term we need PCD macros that work in assembly
#
2018-04-11 09:14:05 -07:00
elif Pcd . Type != TAB_PCDS_FIXED_AT_BUILD and Pcd . DatumType in TAB_PCD_NUMERIC_TYPES_VOID :
2014-01-27 05:23:15 +00:00
Value = "(( %s ) %s )" % ( Pcd . DatumType , Value )
if Pcd . Type == TAB_PCDS_PATCHABLE_IN_MODULE :
2016-04-12 10:31:55 +08:00
PcdValueName = '_PCD_PATCHABLE_VALUE_' + TokenCName
2014-01-27 05:23:15 +00:00
else :
2016-04-12 10:31:55 +08:00
PcdValueName = '_PCD_VALUE_' + TokenCName
2018-07-05 17:40:04 +08:00
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
#
# For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
#
2018-04-06 07:14:01 +08:00
AutoGenH . Append ( '#define %s %s%s \n ' % ( PcdValueName , Type , PcdVariableName ))
2014-01-27 05:23:15 +00:00
if Unicode :
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s ; \n ' % ( Const , PcdVariableName , Array , Value ))
AutoGenH . Append ( 'extern %s UINT16 %s%s ; \n ' % ( Const , PcdVariableName , Array ))
else :
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s UINT8 %s%s = %s ; \n ' % ( Const , PcdVariableName , Array , Value ))
AutoGenH . Append ( 'extern %s UINT8 %s%s ; \n ' % ( Const , PcdVariableName , Array ))
2018-04-06 07:14:01 +08:00
AutoGenH . Append ( '#define %s %s%s \n ' % ( GetModeName , Type , PcdVariableName ))
2018-07-05 17:40:04 +08:00
2018-04-28 06:32:32 +08:00
PcdDataSize = Pcd . GetPcdSize ()
2015-08-24 05:01:38 +00:00
if Pcd . Type == TAB_PCDS_FIXED_AT_BUILD :
AutoGenH . Append ( '#define %s %s \n ' % ( FixPcdSizeTokenName , PcdDataSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , FixPcdSizeTokenName ))
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s ; \n ' % ( FixedPcdSizeVariableName , PcdDataSize ))
2015-08-24 05:01:38 +00:00
if Pcd . Type == TAB_PCDS_PATCHABLE_IN_MODULE :
AutoGenH . Append ( '#define %s %s \n ' % ( PatchPcdSizeTokenName , Pcd . MaxDatumSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , PatchPcdSizeVariableName ))
2015-08-24 05:01:38 +00:00
AutoGenH . Append ( 'extern UINTN %s ; \n ' % PatchPcdSizeVariableName )
2018-06-25 18:31:33 +08:00
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s ; \n ' % ( PatchPcdSizeVariableName , PcdDataSize ))
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED const UINTN %s = %s ; \n ' % ( PatchPcdMaxSizeVariable , Pcd . MaxDatumSize ))
2014-01-27 05:23:15 +00:00
elif Pcd . Type == TAB_PCDS_PATCHABLE_IN_MODULE :
AutoGenH . Append ( '#define %s %s \n ' % ( PcdValueName , Value ))
AutoGenC . Append ( 'volatile %s %s %s = %s ; \n ' % ( Const , Pcd . DatumType , PcdVariableName , PcdValueName ))
AutoGenH . Append ( 'extern volatile %s %s %s%s ; \n ' % ( Const , Pcd . DatumType , PcdVariableName , Array ))
AutoGenH . Append ( '#define %s %s%s \n ' % ( GetModeName , Type , PcdVariableName ))
2018-07-05 17:40:04 +08:00
2018-04-28 06:32:32 +08:00
PcdDataSize = Pcd . GetPcdSize ()
2015-08-24 05:01:38 +00:00
AutoGenH . Append ( '#define %s %s \n ' % ( PatchPcdSizeTokenName , PcdDataSize ))
2018-07-05 17:40:04 +08:00
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , PatchPcdSizeVariableName ))
2015-08-24 05:01:38 +00:00
AutoGenH . Append ( 'extern UINTN %s ; \n ' % PatchPcdSizeVariableName )
2018-06-25 18:31:33 +08:00
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED UINTN %s = %s ; \n ' % ( PatchPcdSizeVariableName , PcdDataSize ))
2014-01-27 05:23:15 +00:00
else :
2018-04-28 06:32:32 +08:00
PcdDataSize = Pcd . GetPcdSize ()
2015-08-24 05:01:38 +00:00
AutoGenH . Append ( '#define %s %s \n ' % ( FixPcdSizeTokenName , PcdDataSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , FixPcdSizeTokenName ))
2018-07-05 17:40:04 +08:00
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '#define %s %s \n ' % ( PcdValueName , Value ))
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s %s %s = %s ; \n ' % ( Const , Pcd . DatumType , PcdVariableName , PcdValueName ))
AutoGenH . Append ( 'extern %s %s %s%s ; \n ' % ( Const , Pcd . DatumType , PcdVariableName , Array ))
AutoGenH . Append ( '#define %s %s%s \n ' % ( GetModeName , Type , PcdVariableName ))
if Pcd . Type == TAB_PCDS_PATCHABLE_IN_MODULE :
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2015-08-24 05:02:35 +00:00
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 ))
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 ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define %s (Value) ( %s = (Value)) \n ' % ( SetModeName , PcdVariableName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '#define %s (Value) (( %s = (Value)), RETURN_SUCCESS) \n ' % ( SetModeStatusName , PcdVariableName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD \n ' % SetModeName )
## Create code for library module PCDs
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
# @param Pcd The PCD object
#
def CreateLibraryPcdCode ( Info , AutoGenC , AutoGenH , Pcd ):
PcdTokenNumber = Info . PlatformInfo . PcdTokenNumber
TokenSpaceGuidCName = Pcd . TokenSpaceGuidCName
TokenCName = Pcd . TokenCName
2016-04-12 10:31:55 +08:00
for PcdItem in GlobalData . MixedPcd :
if ( TokenCName , TokenSpaceGuidCName ) in GlobalData . MixedPcd [ PcdItem ]:
TokenCName = PcdItem [ 0 ]
break
2014-01-27 05:23:15 +00:00
PcdTokenName = '_PCD_TOKEN_' + TokenCName
2016-04-12 10:31:55 +08:00
FixPcdSizeTokenName = '_PCD_SIZE_' + TokenCName
PatchPcdSizeTokenName = '_PCD_PATCHABLE_' + TokenCName + '_SIZE'
PatchPcdSizeVariableName = '_gPcd_BinaryPatch_Size_' + TokenCName
2018-03-14 20:20:23 +08:00
PatchPcdMaxSizeVariable = '_gPcd_BinaryPatch_MaxSize_' + TokenCName
2018-03-13 22:44:01 +08:00
FixedPcdSizeVariableName = '_gPcd_FixedAtBuild_Size_' + TokenCName
2016-02-25 16:13:31 +08:00
2018-03-08 13:56:21 +08:00
if Pcd . PcdValueFromComm :
Pcd . DefaultValue = Pcd . PcdValueFromComm
2018-06-22 17:14:13 +08:00
elif Pcd . PcdValueFromFdf :
Pcd . DefaultValue = Pcd . PcdValueFromFdf
2014-01-27 05:23:15 +00:00
#
# Write PCDs
#
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET :
2014-01-27 05:23:15 +00:00
TokenNumber = int ( Pcd . TokenValue , 0 )
else :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) not in PcdTokenNumber :
2018-07-05 17:40:04 +08:00
# If one of the Source built modules listed in the DSC is not listed in FDF modules,
# and the INF lists a PCD can only use the PcdsDynamic access method (it is only
# listed in the DEC file that declares the PCD as PcdsDynamic), then build tool will
# report warning message notify the PI that they are attempting to build a module
# that must be included in a flash image in order to be functional. These Dynamic PCD
# will not be added into the Database unless it is used by other modules that are
# included in the FDF file.
2014-01-27 05:23:15 +00:00
# In this case, just assign an invalid token number to make it pass build.
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_TYPE_SET :
2014-01-27 05:23:15 +00:00
TokenNumber = 0
else :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"No generated token number for %s . %s \n " % ( Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
else :
TokenNumber = PcdTokenNumber [ Pcd . TokenCName , Pcd . TokenSpaceGuidCName ]
if Pcd . Type not in gItemTypeStringDatabase :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
2016-04-12 10:31:55 +08:00
"Unknown PCD type [ %s ] of PCD %s . %s " % ( Pcd . Type , Pcd . TokenSpaceGuidCName , TokenCName ),
2014-01-27 05:23:15 +00:00
ExtraData = "[ %s ]" % str ( Info ))
DatumType = Pcd . DatumType
2018-04-11 09:14:05 -07:00
DatumSize = gDatumSizeStringDatabase [ Pcd . DatumType ] if Pcd . DatumType in gDatumSizeStringDatabase else gDatumSizeStringDatabase [ TAB_VOID ]
DatumSizeLib = gDatumSizeStringDatabaseLib [ Pcd . DatumType ] if Pcd . DatumType in gDatumSizeStringDatabaseLib else gDatumSizeStringDatabaseLib [ TAB_VOID ]
GetModeName = '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_GET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_' + TokenCName
SetModeName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_' + TokenCName
SetModeStatusName = '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ Pcd . DatumType ] + '_S_' + TokenCName if Pcd . DatumType in gDatumSizeStringDatabaseH else '_PCD_SET_MODE_' + gDatumSizeStringDatabaseH [ TAB_VOID ] + '_S_' + TokenCName
2016-04-12 10:31:55 +08:00
GetModeSizeName = '_PCD_GET_MODE_SIZE' + '_' + TokenCName
2014-01-27 05:23:15 +00:00
Type = ''
Array = ''
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2016-01-29 04:46:47 +00:00
if Pcd . DefaultValue [ 0 ] == '{' :
Type = '(VOID *)'
2014-01-27 05:23:15 +00:00
Array = '[]'
PcdItemType = Pcd . Type
2018-04-20 23:51:37 +08:00
if PcdItemType in PCD_DYNAMIC_EX_TYPE_SET :
2016-04-12 10:31:55 +08:00
PcdExTokenName = '_PCD_TOKEN_' + TokenSpaceGuidCName + '_' + TokenCName
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( ' \n #define %s %d U \n ' % ( PcdExTokenName , TokenNumber ))
2018-07-05 17:40:04 +08:00
2014-01-27 05:23:15 +00:00
if Info . IsLibrary :
PcdList = Info . LibraryPcdList
else :
PcdList = Info . ModulePcdList
2018-04-11 07:17:24 +08:00
PcdExCNameTest = 0
2014-01-27 05:23:15 +00:00
for PcdModule in PcdList :
2018-04-20 23:51:37 +08:00
if PcdModule . Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd . TokenCName == PcdModule . TokenCName :
2018-04-11 07:17:24 +08:00
PcdExCNameTest += 1
# get out early once we found > 1...
if PcdExCNameTest > 1 :
break
2014-01-27 05:23:15 +00:00
# Be compatible with the current code which using PcdGet/Set for DynamicEx Pcd.
# If only PcdGet/Set used in all Pcds with different CName, it should succeed to build.
# If PcdGet/Set used in the Pcds with different Guids but same CName, it should failed to build.
2018-04-11 07:17:24 +08:00
if PcdExCNameTest > 1 :
2014-01-27 05:23:15 +00:00
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 ' )
AutoGenH . Append ( '// #define %s %s \n ' % ( PcdTokenName , PcdExTokenName ))
AutoGenH . Append ( '// #define %s LibPcdGetEx %s (& %s , %s ) \n ' % ( GetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '// #define %s LibPcdGetExSize(& %s , %s ) \n ' % ( GetModeSizeName , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '// #define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s (& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '// #define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s S(& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '// #define %s (Value) LibPcdSetEx %s (& %s , %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '// #define %s (Value) LibPcdSetEx %s S(& %s , %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define %s %s \n ' % ( PcdTokenName , PcdExTokenName ))
AutoGenH . Append ( '#define %s LibPcdGetEx %s (& %s , %s ) \n ' % ( GetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s LibPcdGetExSize(& %s , %s ) \n ' % ( GetModeSizeName , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s (& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSetEx %s S(& %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define %s (Value) LibPcdSetEx %s (& %s , %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2015-04-10 06:59:47 +00:00
AutoGenH . Append ( '#define %s (Value) LibPcdSetEx %s S(& %s , %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , Pcd . TokenSpaceGuidCName , PcdTokenName ))
2014-01-27 05:23:15 +00:00
else :
AutoGenH . Append ( '#define _PCD_TOKEN_ %s %d U \n ' % ( TokenCName , TokenNumber ))
2018-04-20 23:51:37 +08:00
if PcdItemType in PCD_DYNAMIC_TYPE_SET :
2015-11-30 03:40:37 +00:00
PcdList = []
PcdCNameList = []
PcdList . extend ( Info . LibraryPcdList )
PcdList . extend ( Info . ModulePcdList )
for PcdModule in PcdList :
2018-04-20 23:51:37 +08:00
if PcdModule . Type in PCD_DYNAMIC_TYPE_SET :
2015-11-30 03:40:37 +00:00
PcdCNameList . append ( PcdModule . TokenCName )
if PcdCNameList . count ( Pcd . TokenCName ) > 1 :
2016-04-12 10:31:55 +08:00
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 ))
2014-01-27 05:23:15 +00:00
else :
2015-11-30 03:40:37 +00:00
AutoGenH . Append ( '#define %s LibPcdGet %s ( %s ) \n ' % ( GetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s LibPcdGetSize( %s ) \n ' % ( GetModeSizeName , PcdTokenName ))
2018-04-11 09:14:05 -07:00
if DatumType not in TAB_PCD_NUMERIC_TYPES :
2015-11-30 03:40:37 +00:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSet %s ( %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPcdSet %s S( %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , DatumSizeLib , PcdTokenName ))
else :
AutoGenH . Append ( '#define %s (Value) LibPcdSet %s ( %s , (Value)) \n ' % ( SetModeName , DatumSizeLib , PcdTokenName ))
AutoGenH . Append ( '#define %s (Value) LibPcdSet %s S( %s , (Value)) \n ' % ( SetModeStatusName , DatumSizeLib , PcdTokenName ))
2014-01-27 05:23:15 +00:00
if PcdItemType == TAB_PCDS_PATCHABLE_IN_MODULE :
PcdVariableName = '_gPcd_' + gItemTypeStringDatabase [ TAB_PCDS_PATCHABLE_IN_MODULE ] + '_' + TokenCName
2018-04-11 09:14:05 -07:00
if DatumType not in TAB_PCD_NUMERIC_TYPES :
if DatumType == TAB_VOID and Array == '[]' :
DatumType = [ TAB_UINT8 , TAB_UINT16 ][ Pcd . DefaultValue [ 0 ] == 'L' ]
2018-03-14 20:20:23 +08:00
else :
2018-04-11 09:14:05 -07:00
DatumType = TAB_UINT8
2016-01-29 04:46:47 +00:00
AutoGenH . Append ( 'extern %s _gPcd_BinaryPatch_ %s%s ; \n ' % ( DatumType , TokenCName , Array ))
else :
AutoGenH . Append ( 'extern volatile %s %s%s ; \n ' % ( DatumType , PcdVariableName , Array ))
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( '#define %s %s _gPcd_BinaryPatch_ %s \n ' % ( GetModeName , Type , TokenCName ))
2018-04-28 06:32:32 +08:00
PcdDataSize = Pcd . GetPcdSize ()
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2018-03-14 20:20:23 +08:00
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSize((VOID *)_gPcd_BinaryPatch_ %s , & %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeName , TokenCName , PatchPcdSizeVariableName , PatchPcdMaxSizeVariable ))
AutoGenH . Append ( '#define %s (SizeOfBuffer, Buffer) LibPatchPcdSetPtrAndSizeS((VOID *)_gPcd_BinaryPatch_ %s , & %s , %s , (SizeOfBuffer), (Buffer)) \n ' % ( SetModeStatusName , TokenCName , PatchPcdSizeVariableName , PatchPcdMaxSizeVariable ))
2018-07-23 11:58:22 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( PatchPcdSizeTokenName , PatchPcdMaxSizeVariable ))
2018-03-14 20:20:23 +08:00
AutoGenH . Append ( 'extern const UINTN %s ; \n ' % PatchPcdMaxSizeVariable )
2015-08-24 05:02:07 +00:00
else :
AutoGenH . Append ( '#define %s (Value) ( %s = (Value)) \n ' % ( SetModeName , PcdVariableName ))
AutoGenH . Append ( '#define %s (Value) (( %s = (Value)), RETURN_SUCCESS) \n ' % ( SetModeStatusName , PcdVariableName ))
2017-05-10 16:35:30 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( PatchPcdSizeTokenName , PcdDataSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , PatchPcdSizeVariableName ))
2015-08-24 05:01:38 +00:00
AutoGenH . Append ( 'extern UINTN %s ; \n ' % PatchPcdSizeVariableName )
2018-07-05 17:40:04 +08:00
2014-01-27 05:23:15 +00:00
if PcdItemType == TAB_PCDS_FIXED_AT_BUILD or PcdItemType == TAB_PCDS_FEATURE_FLAG :
2018-06-25 18:31:33 +08:00
key = "." . join (( Pcd . TokenSpaceGuidCName , Pcd . TokenCName ))
2017-05-11 21:23:29 +08:00
PcdVariableName = '_gPcd_' + gItemTypeStringDatabase [ Pcd . Type ] + '_' + TokenCName
2018-04-11 09:14:05 -07:00
if DatumType == TAB_VOID and Array == '[]' :
DatumType = [ TAB_UINT8 , TAB_UINT16 ][ Pcd . DefaultValue [ 0 ] == 'L' ]
if DatumType not in TAB_PCD_NUMERIC_TYPES_VOID :
DatumType = TAB_UINT8
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( 'extern const %s _gPcd_FixedAtBuild_ %s%s ; \n ' % ( DatumType , TokenCName , Array ))
AutoGenH . Append ( '#define %s %s _gPcd_FixedAtBuild_ %s \n ' % ( GetModeName , Type , TokenCName ))
AutoGenH . Append ( '//#define %s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD \n ' % SetModeName )
2018-07-05 17:40:04 +08:00
2018-03-13 22:44:01 +08:00
ConstFixedPcd = False
2018-08-03 23:11:06 +08:00
if PcdItemType == TAB_PCDS_FIXED_AT_BUILD and ( key in Info . ConstPcd or ( Info . IsLibrary and not Info . ReferenceModules )):
2018-03-13 22:44:01 +08:00
ConstFixedPcd = True
2018-03-14 16:51:04 +08:00
if key in Info . ConstPcd :
Pcd . DefaultValue = Info . ConstPcd [ key ]
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2017-05-11 21:23:29 +08:00
AutoGenH . Append ( '#define _PCD_VALUE_ %s %s%s \n ' % ( TokenCName , Type , PcdVariableName ))
else :
AutoGenH . Append ( '#define _PCD_VALUE_ %s %s \n ' % ( TokenCName , Pcd . DefaultValue ))
2018-04-28 06:32:32 +08:00
PcdDataSize = Pcd . GetPcdSize ()
2015-08-24 05:01:38 +00:00
if PcdItemType == TAB_PCDS_FIXED_AT_BUILD :
2018-04-11 09:14:05 -07:00
if Pcd . DatumType not in TAB_PCD_NUMERIC_TYPES :
2018-03-13 22:44:01 +08:00
if ConstFixedPcd :
AutoGenH . Append ( '#define %s %s \n ' % ( FixPcdSizeTokenName , PcdDataSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , FixPcdSizeTokenName ))
2018-03-13 22:44:01 +08:00
else :
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , FixedPcdSizeVariableName ))
AutoGenH . Append ( '#define %s %s \n ' % ( FixPcdSizeTokenName , FixedPcdSizeVariableName ))
2018-03-13 22:44:01 +08:00
AutoGenH . Append ( 'extern const UINTN %s ; \n ' % FixedPcdSizeVariableName )
else :
AutoGenH . Append ( '#define %s %s \n ' % ( FixPcdSizeTokenName , PcdDataSize ))
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( '#define %s %s \n ' % ( GetModeSizeName , FixPcdSizeTokenName ))
2014-01-27 05:23:15 +00:00
## Create code for library constructor
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateLibraryConstructorCode ( Info , AutoGenC , AutoGenH ):
#
# Library Constructors
#
ConstructorPrototypeString = TemplateString ()
ConstructorCallingString = TemplateString ()
if Info . IsLibrary :
DependentLibraryList = [ Info . Module ]
else :
DependentLibraryList = Info . DependentLibraryList
for Lib in DependentLibraryList :
if len ( Lib . ConstructorList ) <= 0 :
continue
Dict = { 'Function' : Lib . ConstructorList }
2018-04-27 00:57:53 +08:00
if Lib . ModuleType in [ SUP_MODULE_BASE , SUP_MODULE_SEC ]:
ConstructorPrototypeString . Append ( gLibraryStructorPrototype [ SUP_MODULE_BASE ] . Replace ( Dict ))
ConstructorCallingString . Append ( gLibraryStructorCall [ SUP_MODULE_BASE ] . Replace ( Dict ))
2019-07-01 06:19:13 +00:00
if Info . ModuleType not in [ SUP_MODULE_BASE , SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION ]:
2019-02-20 19:33:18 +08:00
if Lib . ModuleType in SUP_MODULE_SET_PEI :
ConstructorPrototypeString . Append ( gLibraryStructorPrototype [ 'PEI' ] . Replace ( Dict ))
ConstructorCallingString . Append ( gLibraryStructorCall [ 'PEI' ] . Replace ( Dict ))
elif Lib . ModuleType in [ SUP_MODULE_DXE_CORE , SUP_MODULE_DXE_DRIVER , SUP_MODULE_DXE_SMM_DRIVER , SUP_MODULE_DXE_RUNTIME_DRIVER ,
2025-09-23 16:37:43 +05:30
SUP_MODULE_UEFI_DRIVER , SUP_MODULE_UEFI_APPLICATION , SUP_MODULE_SMM_CORE ]:
2019-02-20 19:33:18 +08:00
ConstructorPrototypeString . Append ( gLibraryStructorPrototype [ 'DXE' ] . Replace ( Dict ))
ConstructorCallingString . Append ( gLibraryStructorCall [ 'DXE' ] . Replace ( Dict ))
elif Lib . ModuleType in [ SUP_MODULE_MM_STANDALONE , SUP_MODULE_MM_CORE_STANDALONE ]:
ConstructorPrototypeString . Append ( gLibraryStructorPrototype [ 'MM' ] . Replace ( Dict ))
ConstructorCallingString . Append ( gLibraryStructorCall [ 'MM' ] . Replace ( Dict ))
2014-01-27 05:23:15 +00:00
if str ( ConstructorPrototypeString ) == '' :
ConstructorPrototypeList = []
else :
ConstructorPrototypeList = [ str ( ConstructorPrototypeString )]
if str ( ConstructorCallingString ) == '' :
ConstructorCallingList = []
else :
ConstructorCallingList = [ str ( ConstructorCallingString )]
Dict = {
'Type' : 'Constructor' ,
'FunctionPrototype' : ConstructorPrototypeList ,
'FunctionCall' : ConstructorCallingList
}
if Info . IsLibrary :
AutoGenH . Append ( "$ {BEGIN} $ {FunctionPrototype} $ {END} " , Dict )
else :
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_BASE , SUP_MODULE_SEC , SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION ]:
2018-04-27 00:57:53 +08:00
AutoGenC . Append ( gLibraryString [ SUP_MODULE_BASE ] . Replace ( Dict ))
2024-02-24 22:05:04 +01:00
if Info . ModuleType == SUP_MODULE_SEC and Info . AutoGenVersion >= 0x0001001E :
AutoGenH . Append (( " \n "
"// ProcessLibraryConstructorList() declared here because SEC has no standard entry point. \n "
"VOID \n "
"EFIAPI \n "
"ProcessLibraryConstructorList ( \n "
" VOID \n "
" ); \n " ))
2018-04-20 23:51:34 +08:00
elif Info . ModuleType in SUP_MODULE_SET_PEI :
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gLibraryString [ 'PEI' ] . Replace ( Dict ))
2018-06-25 18:31:33 +08:00
elif Info . ModuleType in [ SUP_MODULE_DXE_CORE , SUP_MODULE_DXE_DRIVER , SUP_MODULE_DXE_SMM_DRIVER , SUP_MODULE_DXE_RUNTIME_DRIVER ,
2025-09-23 16:37:43 +05:30
SUP_MODULE_UEFI_DRIVER , SUP_MODULE_UEFI_APPLICATION , SUP_MODULE_SMM_CORE ]:
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gLibraryString [ 'DXE' ] . Replace ( Dict ))
2018-06-25 18:31:33 +08:00
elif Info . ModuleType in [ SUP_MODULE_MM_STANDALONE , SUP_MODULE_MM_CORE_STANDALONE ]:
2017-06-27 00:47:39 +08:00
AutoGenC . Append ( gLibraryString [ 'MM' ] . Replace ( Dict ))
2014-01-27 05:23:15 +00:00
## Create code for library destructor
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateLibraryDestructorCode ( Info , AutoGenC , AutoGenH ):
#
# Library Destructors
#
DestructorPrototypeString = TemplateString ()
DestructorCallingString = TemplateString ()
if Info . IsLibrary :
DependentLibraryList = [ Info . Module ]
else :
DependentLibraryList = Info . DependentLibraryList
for Index in range ( len ( DependentLibraryList ) - 1 , - 1 , - 1 ):
Lib = DependentLibraryList [ Index ]
if len ( Lib . DestructorList ) <= 0 :
continue
Dict = { 'Function' : Lib . DestructorList }
2018-04-27 00:57:53 +08:00
if Lib . ModuleType in [ SUP_MODULE_BASE , SUP_MODULE_SEC ]:
DestructorPrototypeString . Append ( gLibraryStructorPrototype [ SUP_MODULE_BASE ] . Replace ( Dict ))
DestructorCallingString . Append ( gLibraryStructorCall [ SUP_MODULE_BASE ] . Replace ( Dict ))
2019-07-01 06:19:13 +00:00
if Info . ModuleType not in [ SUP_MODULE_BASE , SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION ]:
2019-02-20 19:33:18 +08:00
if Lib . ModuleType in SUP_MODULE_SET_PEI :
DestructorPrototypeString . Append ( gLibraryStructorPrototype [ 'PEI' ] . Replace ( Dict ))
DestructorCallingString . Append ( gLibraryStructorCall [ 'PEI' ] . Replace ( Dict ))
elif Lib . ModuleType in [ SUP_MODULE_DXE_CORE , SUP_MODULE_DXE_DRIVER , SUP_MODULE_DXE_SMM_DRIVER , SUP_MODULE_DXE_RUNTIME_DRIVER ,
2025-09-23 16:37:43 +05:30
SUP_MODULE_UEFI_DRIVER , SUP_MODULE_UEFI_APPLICATION , SUP_MODULE_SMM_CORE ]:
2019-02-20 19:33:18 +08:00
DestructorPrototypeString . Append ( gLibraryStructorPrototype [ 'DXE' ] . Replace ( Dict ))
DestructorCallingString . Append ( gLibraryStructorCall [ 'DXE' ] . Replace ( Dict ))
elif Lib . ModuleType in [ SUP_MODULE_MM_STANDALONE , SUP_MODULE_MM_CORE_STANDALONE ]:
DestructorPrototypeString . Append ( gLibraryStructorPrototype [ 'MM' ] . Replace ( Dict ))
DestructorCallingString . Append ( gLibraryStructorCall [ 'MM' ] . Replace ( Dict ))
2014-01-27 05:23:15 +00:00
if str ( DestructorPrototypeString ) == '' :
DestructorPrototypeList = []
else :
DestructorPrototypeList = [ str ( DestructorPrototypeString )]
if str ( DestructorCallingString ) == '' :
DestructorCallingList = []
else :
DestructorCallingList = [ str ( DestructorCallingString )]
Dict = {
'Type' : 'Destructor' ,
'FunctionPrototype' : DestructorPrototypeList ,
'FunctionCall' : DestructorCallingList
}
if Info . IsLibrary :
AutoGenH . Append ( "$ {BEGIN} $ {FunctionPrototype} $ {END} " , Dict )
else :
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_BASE , SUP_MODULE_SEC , SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION ]:
2018-04-27 00:57:53 +08:00
AutoGenC . Append ( gLibraryString [ SUP_MODULE_BASE ] . Replace ( Dict ))
2018-04-20 23:51:34 +08:00
elif Info . ModuleType in SUP_MODULE_SET_PEI :
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gLibraryString [ 'PEI' ] . Replace ( Dict ))
2018-06-25 18:31:33 +08:00
elif Info . ModuleType in [ SUP_MODULE_DXE_CORE , SUP_MODULE_DXE_DRIVER , SUP_MODULE_DXE_SMM_DRIVER , SUP_MODULE_DXE_RUNTIME_DRIVER ,
2025-09-23 16:37:43 +05:30
SUP_MODULE_UEFI_DRIVER , SUP_MODULE_UEFI_APPLICATION , SUP_MODULE_SMM_CORE ]:
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gLibraryString [ 'DXE' ] . Replace ( Dict ))
2018-06-25 18:31:33 +08:00
elif Info . ModuleType in [ SUP_MODULE_MM_STANDALONE , SUP_MODULE_MM_CORE_STANDALONE ]:
2017-06-27 00:47:39 +08:00
AutoGenC . Append ( gLibraryString [ 'MM' ] . Replace ( Dict ))
2014-01-27 05:23:15 +00:00
## Create code for ModuleEntryPoint
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateModuleEntryPointCode ( Info , AutoGenC , AutoGenH ):
2019-07-01 06:19:13 +00:00
if Info . IsLibrary or Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_SEC ]:
2014-01-27 05:23:15 +00:00
return
#
# Module Entry Points
#
2019-02-25 08:15:25 +08:00
NumEntryPoints = len ( Info . Module . ModuleEntryPointList )
2014-01-27 05:23:15 +00:00
if 'PI_SPECIFICATION_VERSION' in Info . Module . Specification :
PiSpecVersion = Info . Module . Specification [ 'PI_SPECIFICATION_VERSION' ]
else :
PiSpecVersion = '0x00000000'
if 'UEFI_SPECIFICATION_VERSION' in Info . Module . Specification :
UefiSpecVersion = Info . Module . Specification [ 'UEFI_SPECIFICATION_VERSION' ]
else :
UefiSpecVersion = '0x00000000'
Dict = {
2019-02-25 08:15:25 +08:00
'Function' : Info . Module . ModuleEntryPointList ,
2014-01-27 05:23:15 +00:00
'PiSpecVersion' : PiSpecVersion + 'U' ,
'UefiSpecVersion' : UefiSpecVersion + 'U'
}
2018-04-27 00:57:53 +08:00
if Info . ModuleType in [ SUP_MODULE_PEI_CORE , SUP_MODULE_DXE_CORE , SUP_MODULE_SMM_CORE , SUP_MODULE_MM_CORE_STANDALONE ]:
2018-04-13 08:02:10 +08:00
if Info . SourceFileList :
2019-07-30 17:15:31 +08:00
if NumEntryPoints != 1 :
EdkLogger . error (
2014-01-27 05:23:15 +00:00
"build" ,
AUTOGEN_ERROR ,
' %s must have exactly one entry point' % Info . ModuleType ,
File = str ( Info ),
2019-02-25 08:15:25 +08:00
ExtraData = ", " . join ( Info . Module . ModuleEntryPointList )
2014-01-27 05:23:15 +00:00
)
2018-04-27 00:57:53 +08:00
if Info . ModuleType == SUP_MODULE_PEI_CORE :
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gPeiCoreEntryPointString . Replace ( Dict ))
AutoGenH . Append ( gPeiCoreEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_DXE_CORE :
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gDxeCoreEntryPointString . Replace ( Dict ))
AutoGenH . Append ( gDxeCoreEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_SMM_CORE :
2014-01-27 05:23:15 +00:00
AutoGenC . Append ( gSmmCoreEntryPointString . Replace ( Dict ))
AutoGenH . Append ( gSmmCoreEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_MM_CORE_STANDALONE :
2017-06-27 00:47:39 +08:00
AutoGenC . Append ( gMmCoreStandaloneEntryPointString . Replace ( Dict ))
AutoGenH . Append ( gMmCoreStandaloneEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_PEIM :
2014-01-27 05:23:15 +00:00
if NumEntryPoints < 2 :
AutoGenC . Append ( gPeimEntryPointString [ NumEntryPoints ] . Replace ( Dict ))
else :
AutoGenC . Append ( gPeimEntryPointString [ 2 ] . Replace ( Dict ))
AutoGenH . Append ( gPeimEntryPointPrototype . Replace ( Dict ))
2025-09-23 16:37:43 +05:30
elif Info . ModuleType in [ SUP_MODULE_DXE_RUNTIME_DRIVER , SUP_MODULE_DXE_DRIVER , SUP_MODULE_UEFI_DRIVER ]:
2014-01-27 05:23:15 +00:00
if NumEntryPoints < 2 :
AutoGenC . Append ( gUefiDriverEntryPointString [ NumEntryPoints ] . Replace ( Dict ))
else :
AutoGenC . Append ( gUefiDriverEntryPointString [ 2 ] . Replace ( Dict ))
AutoGenH . Append ( gUefiDriverEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_DXE_SMM_DRIVER :
2014-01-27 05:23:15 +00:00
if NumEntryPoints == 0 :
AutoGenC . Append ( gDxeSmmEntryPointString [ 0 ] . Replace ( Dict ))
else :
AutoGenC . Append ( gDxeSmmEntryPointString [ 1 ] . Replace ( Dict ))
2017-06-27 00:47:39 +08:00
AutoGenH . Append ( gDxeSmmEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_MM_STANDALONE :
2017-06-27 00:47:39 +08:00
if NumEntryPoints < 2 :
AutoGenC . Append ( gMmStandaloneEntryPointString [ NumEntryPoints ] . Replace ( Dict ))
else :
AutoGenC . Append ( gMmStandaloneEntryPointString [ 2 ] . Replace ( Dict ))
AutoGenH . Append ( gMmStandaloneEntryPointPrototype . Replace ( Dict ))
2018-04-27 00:57:53 +08:00
elif Info . ModuleType == SUP_MODULE_UEFI_APPLICATION :
2014-01-27 05:23:15 +00:00
if NumEntryPoints < 2 :
AutoGenC . Append ( gUefiApplicationEntryPointString [ NumEntryPoints ] . Replace ( Dict ))
else :
AutoGenC . Append ( gUefiApplicationEntryPointString [ 2 ] . Replace ( Dict ))
AutoGenH . Append ( gUefiApplicationEntryPointPrototype . Replace ( Dict ))
## Create code for ModuleUnloadImage
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateModuleUnloadImageCode ( Info , AutoGenC , AutoGenH ):
2019-07-01 06:19:13 +00:00
if Info . IsLibrary or Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_BASE , SUP_MODULE_SEC ]:
2014-01-27 05:23:15 +00:00
return
#
# Unload Image Handlers
#
2019-02-25 08:15:25 +08:00
NumUnloadImage = len ( Info . Module . ModuleUnloadImageList )
Dict = { 'Count' : str ( NumUnloadImage ) + 'U' , 'Function' : Info . Module . ModuleUnloadImageList }
2014-01-27 05:23:15 +00:00
if NumUnloadImage < 2 :
AutoGenC . Append ( gUefiUnloadImageString [ NumUnloadImage ] . Replace ( Dict ))
else :
AutoGenC . Append ( gUefiUnloadImageString [ 2 ] . Replace ( Dict ))
AutoGenH . Append ( gUefiUnloadImagePrototype . Replace ( Dict ))
## Create code for GUID
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateGuidDefinitionCode ( Info , AutoGenC , AutoGenH ):
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_BASE ]:
2018-04-27 00:57:56 +08:00
GuidType = TAB_GUID
2014-01-27 05:23:15 +00:00
else :
GuidType = "EFI_GUID"
if Info . GuidList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( " \n // Guids \n " )
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( " \n // Guids \n " )
2014-01-27 05:23:15 +00:00
#
# GUIDs
#
for Key in Info . GuidList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s ; \n ' % ( GuidType , Key , Info . GuidList [ Key ]))
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( 'extern %s %s ; \n ' % ( GuidType , Key ))
2014-01-27 05:23:15 +00:00
## Create code for protocol
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateProtocolDefinitionCode ( Info , AutoGenC , AutoGenH ):
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_BASE ]:
2018-04-27 00:57:56 +08:00
GuidType = TAB_GUID
2014-01-27 05:23:15 +00:00
else :
GuidType = "EFI_GUID"
if Info . ProtocolList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( " \n // Protocols \n " )
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( " \n // Protocols \n " )
2014-01-27 05:23:15 +00:00
#
# Protocol GUIDs
#
for Key in Info . ProtocolList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s ; \n ' % ( GuidType , Key , Info . ProtocolList [ Key ]))
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( 'extern %s %s ; \n ' % ( GuidType , Key ))
2014-01-27 05:23:15 +00:00
## Create code for PPI
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreatePpiDefinitionCode ( Info , AutoGenC , AutoGenH ):
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_BASE ]:
2018-04-27 00:57:56 +08:00
GuidType = TAB_GUID
2014-01-27 05:23:15 +00:00
else :
GuidType = "EFI_GUID"
if Info . PpiList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( " \n // PPIs \n " )
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( " \n // PPIs \n " )
2014-01-27 05:23:15 +00:00
#
# PPI GUIDs
#
for Key in Info . PpiList :
2015-10-26 03:26:55 +00:00
if not Info . IsLibrary :
AutoGenC . Append ( 'GLOBAL_REMOVE_IF_UNREFERENCED %s %s = %s ; \n ' % ( GuidType , Key , Info . PpiList [ Key ]))
2015-06-08 08:08:58 +00:00
AutoGenH . Append ( 'extern %s %s ; \n ' % ( GuidType , Key ))
2014-01-27 05:23:15 +00:00
## Create code for PCD
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreatePcdCode ( Info , AutoGenC , AutoGenH ):
# Collect Token Space GUIDs used by DynamicEc PCDs
TokenSpaceList = []
for Pcd in Info . ModulePcdList :
2018-04-20 23:51:37 +08:00
if Pcd . Type in PCD_DYNAMIC_EX_TYPE_SET and Pcd . TokenSpaceGuidCName not in TokenSpaceList :
2018-05-18 08:06:52 +08:00
TokenSpaceList . append ( Pcd . TokenSpaceGuidCName )
2018-07-05 17:40:04 +08:00
2019-07-22 11:09:22 +08:00
SkuMgr = Info . PlatformInfo . Platform . SkuIdMgr
2017-12-22 20:46:15 +08:00
AutoGenH . Append ( " \n // Definition of SkuId Array \n " )
AutoGenH . Append ( "extern UINT64 _gPcd_SkuId_Array[]; \n " )
2014-01-27 05:23:15 +00:00
# Add extern declarations to AutoGen.h if one or more Token Space GUIDs were found
2018-04-11 07:17:24 +08:00
if TokenSpaceList :
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( " \n // Definition of PCD Token Space GUIDs used in this module \n\n " )
2019-07-01 06:19:13 +00:00
if Info . ModuleType in [ SUP_MODULE_USER_DEFINED , SUP_MODULE_HOST_APPLICATION , SUP_MODULE_BASE ]:
2018-04-27 00:57:56 +08:00
GuidType = TAB_GUID
2014-01-27 05:23:15 +00:00
else :
2018-07-05 17:40:04 +08:00
GuidType = "EFI_GUID"
2014-01-27 05:23:15 +00:00
for Item in TokenSpaceList :
AutoGenH . Append ( 'extern %s %s ; \n ' % ( GuidType , Item ))
if Info . IsLibrary :
if Info . ModulePcdList :
AutoGenH . Append ( " \n // PCD definitions \n " )
for Pcd in Info . ModulePcdList :
CreateLibraryPcdCode ( Info , AutoGenC , AutoGenH , Pcd )
DynExPcdTokenNumberMapping ( Info , AutoGenH )
else :
2017-12-22 20:46:15 +08:00
AutoGenC . Append ( " \n // Definition of SkuId Array \n " )
AutoGenC . Append ( "GLOBAL_REMOVE_IF_UNREFERENCED UINT64 _gPcd_SkuId_Array[] = %s ; \n " % SkuMgr . DumpSkuIdArrary ())
2014-01-27 05:23:15 +00:00
if Info . ModulePcdList :
AutoGenH . Append ( " \n // Definition of PCDs used in this module \n " )
AutoGenC . Append ( " \n // Definition of PCDs used in this module \n " )
for Pcd in Info . ModulePcdList :
CreateModulePcdCode ( Info , AutoGenC , AutoGenH , Pcd )
DynExPcdTokenNumberMapping ( Info , AutoGenH )
if Info . LibraryPcdList :
AutoGenH . Append ( " \n // Definition of PCDs used in libraries is in AutoGen.c \n " )
AutoGenC . Append ( " \n // Definition of PCDs used in libraries \n " )
for Pcd in Info . LibraryPcdList :
CreateModulePcdCode ( Info , AutoGenC , AutoGenC , Pcd )
CreatePcdDatabaseCode ( Info , AutoGenC , AutoGenH )
## Create code for unicode string definition
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
# @param UniGenBinBuffer Buffer to store uni string package data
#
def CreateUnicodeStringCode ( Info , AutoGenC , AutoGenH , UniGenCFlag , UniGenBinBuffer ):
WorkingDir = os . getcwd ()
os . chdir ( Info . WorkspaceDir )
IncList = [ Info . MetaFile . Dir ]
# Get all files under [Sources] section in inf file for EDK-II module
EDK2Module = True
SrcList = [ F for F in Info . SourceFileList ]
if 'BUILD' in Info . BuildOption and Info . BuildOption [ 'BUILD' ][ 'FLAGS' ] . find ( '-c' ) > - 1 :
CompatibleMode = True
else :
CompatibleMode = False
#
# -s is a temporary option dedicated for building .UNI files with ISO 639-2 language codes of EDK Shell in EDK2
#
if 'BUILD' in Info . BuildOption and Info . BuildOption [ 'BUILD' ][ 'FLAGS' ] . find ( '-s' ) > - 1 :
if CompatibleMode :
EdkLogger . error ( "build" , AUTOGEN_ERROR ,
"-c and -s build options should be used exclusively" ,
ExtraData = "[ %s ]" % str ( Info ))
ShellMode = True
else :
ShellMode = False
#RFC4646 is only for EDKII modules and ISO639-2 for EDK modules
if EDK2Module :
FilterInfo = [ EDK2Module ] + [ Info . PlatformInfo . Platform . RFCLanguages ]
else :
FilterInfo = [ EDK2Module ] + [ Info . PlatformInfo . Platform . ISOLanguages ]
Header , Code = GetStringFiles ( Info . UnicodeFileList , SrcList , IncList , Info . IncludePathList , [ '.uni' , '.inf' ], Info . Name , CompatibleMode , ShellMode , UniGenCFlag , UniGenBinBuffer , FilterInfo )
if CompatibleMode or UniGenCFlag :
AutoGenC . Append ( " \n // \n //Unicode String Pack Definition \n // \n " )
AutoGenC . Append ( Code )
AutoGenC . Append ( " \n " )
AutoGenH . Append ( " \n // \n //Unicode String ID \n // \n " )
AutoGenH . Append ( Header )
if CompatibleMode or UniGenCFlag :
AutoGenH . Append ( " \n #define STRING_ARRAY_NAME %s Strings \n " % Info . Name )
os . chdir ( WorkingDir )
2016-09-21 10:39:11 +08:00
def CreateIdfFileCode ( Info , AutoGenC , StringH , IdfGenCFlag , IdfGenBinBuffer ):
if len ( Info . IdfFileList ) > 0 :
ImageFiles = IdfFileClassObject ( sorted ( Info . IdfFileList ))
if ImageFiles . ImageFilesDict :
Index = 1
PaletteIndex = 1
IncList = [ Info . MetaFile . Dir ]
SrcList = [ F for F in Info . SourceFileList ]
SkipList = [ '.jpg' , '.png' , '.bmp' , '.inf' , '.idf' ]
FileList = GetFileList ( SrcList , IncList , SkipList )
ValueStartPtr = 60
StringH . Append ( " \n // \n //Image ID \n // \n " )
ImageInfoOffset = 0
PaletteInfoOffset = 0
ImageBuffer = pack ( 'x' )
PaletteBuffer = pack ( 'x' )
BufferStr = ''
PaletteStr = ''
2016-10-17 17:43:45 +08:00
FileDict = {}
2016-09-21 10:39:11 +08:00
for Idf in ImageFiles . ImageFilesDict :
if ImageFiles . ImageFilesDict [ Idf ]:
for FileObj in ImageFiles . ImageFilesDict [ Idf ]:
for sourcefile in Info . SourceFileList :
if FileObj . FileName == sourcefile . File :
if not sourcefile . Ext . upper () in [ '.PNG' , '.BMP' , '.JPG' ]:
EdkLogger . error ( "build" , AUTOGEN_ERROR , "The %s 's postfix must be one of .bmp, .jpg, .png" % ( FileObj . FileName ), ExtraData = "[ %s ]" % str ( Info ))
FileObj . File = sourcefile
break
else :
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 ))
for FileObj in ImageFiles . ImageFilesDict [ Idf ]:
ID = FileObj . ImageID
File = FileObj . File
2019-09-04 13:00:37 +08:00
try :
SearchImageID ( FileObj , FileList )
if FileObj . Referenced :
if ( ValueStartPtr - len ( DEFINE_STR + ID )) <= 0 :
Line = DEFINE_STR + ' ' + ID + ' ' + DecToHexStr ( Index , 4 ) + ' \n '
else :
Line = DEFINE_STR + ' ' + ID + ' ' * ( ValueStartPtr - len ( DEFINE_STR + ID )) + DecToHexStr ( Index , 4 ) + ' \n '
2016-09-21 10:39:11 +08:00
2019-09-04 13:00:37 +08:00
if File not in FileDict :
FileDict [ File ] = Index
else :
DuplicateBlock = pack ( 'B' , EFI_HII_IIBT_DUPLICATE )
DuplicateBlock += pack ( 'H' , FileDict [ File ])
ImageBuffer += DuplicateBlock
BufferStr = WriteLine ( BufferStr , '// %s : %s : %s ' % ( DecToHexStr ( Index , 4 ), ID , DecToHexStr ( Index , 4 )))
TempBufferList = AscToHexList ( DuplicateBlock )
BufferStr = WriteLine ( BufferStr , CreateArrayItem ( TempBufferList , 16 ) + ' \n ' )
StringH . Append ( Line )
Index += 1
continue
TmpFile = open ( File . Path , 'rb' )
Buffer = TmpFile . read ()
TmpFile . close ()
if File . Ext . upper () == '.PNG' :
TempBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_PNG )
TempBuffer += pack ( 'I' , len ( Buffer ))
TempBuffer += Buffer
elif File . Ext . upper () == '.JPG' :
ImageType , = struct . unpack ( '4s' , Buffer [ 6 : 10 ])
if ImageType != b 'JFIF' :
EdkLogger . error ( "build" , FILE_TYPE_MISMATCH , "The file %s is not a standard JPG file." % File . Path )
TempBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_JPEG )
TempBuffer += pack ( 'I' , len ( Buffer ))
TempBuffer += Buffer
elif File . Ext . upper () == '.BMP' :
TempBuffer , TempPalette = BmpImageDecoder ( File , Buffer , PaletteIndex , FileObj . TransParent )
if len ( TempPalette ) > 1 :
PaletteIndex += 1
NewPalette = pack ( 'H' , len ( TempPalette ))
NewPalette += TempPalette
PaletteBuffer += NewPalette
PaletteStr = WriteLine ( PaletteStr , '// %s : %s : %s ' % ( DecToHexStr ( PaletteIndex - 1 , 4 ), ID , DecToHexStr ( PaletteIndex - 1 , 4 )))
TempPaletteList = AscToHexList ( NewPalette )
PaletteStr = WriteLine ( PaletteStr , CreateArrayItem ( TempPaletteList , 16 ) + ' \n ' )
ImageBuffer += TempBuffer
2016-10-17 17:43:45 +08:00
BufferStr = WriteLine ( BufferStr , '// %s : %s : %s ' % ( DecToHexStr ( Index , 4 ), ID , DecToHexStr ( Index , 4 )))
2019-09-04 13:00:37 +08:00
TempBufferList = AscToHexList ( TempBuffer )
2016-10-17 17:43:45 +08:00
BufferStr = WriteLine ( BufferStr , CreateArrayItem ( TempBufferList , 16 ) + ' \n ' )
2019-09-04 13:00:37 +08:00
2016-10-17 17:43:45 +08:00
StringH . Append ( Line )
Index += 1
2019-09-04 13:00:37 +08:00
except IOError :
EdkLogger . error ( "build" , FILE_NOT_FOUND , ExtraData = File . Path )
2016-09-21 10:39:11 +08:00
BufferStr = WriteLine ( BufferStr , '// End of the Image Info' )
BufferStr = WriteLine ( BufferStr , CreateArrayItem ( DecToHexList ( EFI_HII_IIBT_END , 2 )) + ' \n ' )
ImageEnd = pack ( 'B' , EFI_HII_IIBT_END )
ImageBuffer += ImageEnd
if len ( ImageBuffer ) > 1 :
ImageInfoOffset = 12
if len ( PaletteBuffer ) > 1 :
PaletteInfoOffset = 12 + len ( ImageBuffer ) - 1 # -1 is for the first empty pad byte of ImageBuffer
IMAGE_PACKAGE_HDR = pack ( '=II' , ImageInfoOffset , PaletteInfoOffset )
# PACKAGE_HEADER_Length = PACKAGE_HEADER + ImageInfoOffset + PaletteInfoOffset + ImageBuffer Length + PaletteCount + PaletteBuffer Length
if len ( PaletteBuffer ) > 1 :
PACKAGE_HEADER_Length = 4 + 4 + 4 + len ( ImageBuffer ) - 1 + 2 + len ( PaletteBuffer ) - 1
else :
PACKAGE_HEADER_Length = 4 + 4 + 4 + len ( ImageBuffer ) - 1
if PaletteIndex > 1 :
PALETTE_INFO_HEADER = pack ( 'H' , PaletteIndex - 1 )
# EFI_HII_PACKAGE_HEADER length max value is 0xFFFFFF
Hex_Length = ' %06X ' % PACKAGE_HEADER_Length
if PACKAGE_HEADER_Length > 0xFFFFFF :
EdkLogger . error ( "build" , AUTOGEN_ERROR , "The Length of EFI_HII_PACKAGE_HEADER exceed its maximum value" , ExtraData = "[ %s ]" % str ( Info ))
PACKAGE_HEADER = pack ( '=HBB' , int ( '0x' + Hex_Length [ 2 :], 16 ), int ( '0x' + Hex_Length [ 0 : 2 ], 16 ), EFI_HII_PACKAGE_IMAGES )
IdfGenBinBuffer . write ( PACKAGE_HEADER )
IdfGenBinBuffer . write ( IMAGE_PACKAGE_HDR )
if len ( ImageBuffer ) > 1 :
IdfGenBinBuffer . write ( ImageBuffer [ 1 :])
if PaletteIndex > 1 :
IdfGenBinBuffer . write ( PALETTE_INFO_HEADER )
if len ( PaletteBuffer ) > 1 :
IdfGenBinBuffer . write ( PaletteBuffer [ 1 :])
if IdfGenCFlag :
TotalLength = EFI_HII_ARRAY_SIZE_LENGTH + PACKAGE_HEADER_Length
AutoGenC . Append ( " \n // \n //Image Pack Definition \n // \n " )
AllStr = WriteLine ( '' , CHAR_ARRAY_DEFIN + ' ' + Info . Module . BaseName + 'Images' + '[] = { \n ' )
AllStr = WriteLine ( AllStr , '// STRGATHER_OUTPUT_HEADER' )
AllStr = WriteLine ( AllStr , CreateArrayItem ( DecToHexList ( TotalLength )) + ' \n ' )
AllStr = WriteLine ( AllStr , '// Image PACKAGE HEADER \n ' )
IMAGE_PACKAGE_HDR_List = AscToHexList ( PACKAGE_HEADER )
IMAGE_PACKAGE_HDR_List += AscToHexList ( IMAGE_PACKAGE_HDR )
AllStr = WriteLine ( AllStr , CreateArrayItem ( IMAGE_PACKAGE_HDR_List , 16 ) + ' \n ' )
AllStr = WriteLine ( AllStr , '// Image DATA \n ' )
if BufferStr :
AllStr = WriteLine ( AllStr , BufferStr )
if PaletteStr :
AllStr = WriteLine ( AllStr , '// Palette Header \n ' )
PALETTE_INFO_HEADER_List = AscToHexList ( PALETTE_INFO_HEADER )
AllStr = WriteLine ( AllStr , CreateArrayItem ( PALETTE_INFO_HEADER_List , 16 ) + ' \n ' )
AllStr = WriteLine ( AllStr , '// Palette Data \n ' )
AllStr = WriteLine ( AllStr , PaletteStr )
AllStr = WriteLine ( AllStr , '};' )
AutoGenC . Append ( AllStr )
AutoGenC . Append ( " \n " )
StringH . Append ( ' \n extern unsigned char ' + Info . Module . BaseName + 'Images[]; \n ' )
StringH . Append ( " \n #define IMAGE_ARRAY_NAME %s Images \n " % Info . Module . BaseName )
# typedef struct _EFI_HII_IMAGE_PACKAGE_HDR {
# EFI_HII_PACKAGE_HEADER Header; # Standard package header, where Header.Type = EFI_HII_PACKAGE_IMAGES
# UINT32 ImageInfoOffset;
# UINT32 PaletteInfoOffset;
# } EFI_HII_IMAGE_PACKAGE_HDR;
# typedef struct {
# UINT32 Length:24;
# UINT32 Type:8;
# UINT8 Data[];
# } EFI_HII_PACKAGE_HEADER;
# typedef struct _EFI_HII_IMAGE_BLOCK {
# UINT8 BlockType;
# UINT8 BlockBody[];
# } EFI_HII_IMAGE_BLOCK;
def BmpImageDecoder ( File , Buffer , PaletteIndex , TransParent ):
ImageType , = struct . unpack ( '2s' , Buffer [ 0 : 2 ])
2019-01-23 10:16:00 +08:00
if ImageType != b 'BM' : # BMP file type is 'BM'
2016-09-21 10:39:11 +08:00
EdkLogger . error ( "build" , FILE_TYPE_MISMATCH , "The file %s is not a standard BMP file." % File . Path )
2018-06-25 18:31:33 +08:00
BMP_IMAGE_HEADER = collections . namedtuple ( 'BMP_IMAGE_HEADER' , [ 'bfSize' , 'bfReserved1' , 'bfReserved2' , 'bfOffBits' , 'biSize' , 'biWidth' , 'biHeight' , 'biPlanes' , 'biBitCount' , 'biCompression' , 'biSizeImage' , 'biXPelsPerMeter' , 'biYPelsPerMeter' , 'biClrUsed' , 'biClrImportant' ])
2016-09-21 10:39:11 +08:00
BMP_IMAGE_HEADER_STRUCT = struct . Struct ( 'IHHIIIIHHIIIIII' )
BmpHeader = BMP_IMAGE_HEADER . _make ( BMP_IMAGE_HEADER_STRUCT . unpack_from ( Buffer [ 2 :]))
#
# Doesn't support compress.
#
if BmpHeader . biCompression != 0 :
EdkLogger . error ( "build" , FORMAT_NOT_SUPPORTED , "The compress BMP file %s is not support." % File . Path )
# The Width and Height is UINT16 type in Image Package
if BmpHeader . biWidth > 0xFFFF :
EdkLogger . error ( "build" , FORMAT_NOT_SUPPORTED , "The BMP file %s Width is exceed 0xFFFF." % File . Path )
if BmpHeader . biHeight > 0xFFFF :
EdkLogger . error ( "build" , FORMAT_NOT_SUPPORTED , "The BMP file %s Height is exceed 0xFFFF." % File . Path )
PaletteBuffer = pack ( 'x' )
if BmpHeader . biBitCount == 1 :
if TransParent :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_1BIT_TRANS )
else :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_1BIT )
ImageBuffer += pack ( 'B' , PaletteIndex )
2018-12-07 12:34:44 +08:00
Width = ( BmpHeader . biWidth + 7 ) // 8
2016-09-21 10:39:11 +08:00
if BmpHeader . bfOffBits > BMP_IMAGE_HEADER_STRUCT . size + 2 :
PaletteBuffer = Buffer [ BMP_IMAGE_HEADER_STRUCT . size + 2 : BmpHeader . bfOffBits ]
elif BmpHeader . biBitCount == 4 :
if TransParent :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_4BIT_TRANS )
else :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_4BIT )
ImageBuffer += pack ( 'B' , PaletteIndex )
2018-12-07 12:34:44 +08:00
Width = ( BmpHeader . biWidth + 1 ) // 2
2016-09-21 10:39:11 +08:00
if BmpHeader . bfOffBits > BMP_IMAGE_HEADER_STRUCT . size + 2 :
PaletteBuffer = Buffer [ BMP_IMAGE_HEADER_STRUCT . size + 2 : BmpHeader . bfOffBits ]
elif BmpHeader . biBitCount == 8 :
if TransParent :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_8BIT_TRANS )
else :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_8BIT )
ImageBuffer += pack ( 'B' , PaletteIndex )
Width = BmpHeader . biWidth
if BmpHeader . bfOffBits > BMP_IMAGE_HEADER_STRUCT . size + 2 :
PaletteBuffer = Buffer [ BMP_IMAGE_HEADER_STRUCT . size + 2 : BmpHeader . bfOffBits ]
elif BmpHeader . biBitCount == 24 :
if TransParent :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_24BIT_TRANS )
else :
ImageBuffer = pack ( 'B' , EFI_HII_IIBT_IMAGE_24BIT )
Width = BmpHeader . biWidth * 3
else :
EdkLogger . error ( "build" , FORMAT_NOT_SUPPORTED , "Only support the 1 bit, 4 bit, 8bit, 24 bit BMP files." , ExtraData = "[ %s ]" % str ( File . Path ))
ImageBuffer += pack ( 'H' , BmpHeader . biWidth )
ImageBuffer += pack ( 'H' , BmpHeader . biHeight )
Start = BmpHeader . bfOffBits
End = BmpHeader . bfSize - 1
for Height in range ( 0 , BmpHeader . biHeight ):
if Width % 4 != 0 :
Start = End + ( Width % 4 ) - 4 - Width
else :
Start = End - Width
ImageBuffer += Buffer [ Start + 1 : Start + Width + 1 ]
End = Start
# 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
if PaletteBuffer and len ( PaletteBuffer ) > 1 :
PaletteTemp = pack ( 'x' )
for Index in range ( 0 , len ( PaletteBuffer )):
if Index % 4 == 3 :
continue
2019-01-23 10:16:00 +08:00
PaletteTemp += PaletteBuffer [ Index : Index + 1 ]
2016-09-21 10:39:11 +08:00
PaletteBuffer = PaletteTemp [ 1 :]
return ImageBuffer , PaletteBuffer
2014-01-27 05:23:15 +00:00
## Create common code
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateHeaderCode ( Info , AutoGenC , AutoGenH ):
# file header
AutoGenH . Append ( gAutoGenHeaderString . Replace ({ 'FileName' : 'AutoGen.h' }))
# header file Prologue
2018-06-25 18:31:33 +08:00
AutoGenH . Append ( gAutoGenHPrologueString . Replace ({ 'File' : 'AUTOGENH' , 'Guid' : Info . Guid . replace ( '-' , '_' )}))
2014-01-27 05:23:15 +00:00
AutoGenH . Append ( gAutoGenHCppPrologueString )
2019-01-14 09:24:12 +08:00
# header files includes
if Info . ModuleType in gModuleTypeHeaderFile :
AutoGenH . Append ( "#include < %s > \n " % gModuleTypeHeaderFile [ Info . ModuleType ][ 0 ])
#
# if either PcdLib in [LibraryClasses] sections or there exist Pcd section, add PcdLib.h
# As if modules only uses FixedPcd, then PcdLib is not needed in [LibraryClasses] section.
#
if 'PcdLib' in Info . Module . LibraryClasses or Info . Module . Pcds :
AutoGenH . Append ( "#include <Library/PcdLib.h> \n " )
2014-01-27 05:23:15 +00:00
2019-01-14 09:24:12 +08:00
AutoGenH . Append ( ' \n extern GUID gEfiCallerIdGuid;' )
2020-10-11 06:24:54 +08:00
AutoGenH . Append ( ' \n extern GUID gEdkiiDscPlatformGuid;' )
2019-01-14 09:24:12 +08:00
AutoGenH . Append ( ' \n extern CHAR8 *gEfiCallerBaseName; \n\n ' )
2014-01-27 05:23:15 +00:00
2019-01-14 09:24:12 +08:00
if Info . IsLibrary :
return
AutoGenH . Append ( "#define EFI_CALLER_ID_GUID \\\n %s \n " % GuidStringToGuidStructureString ( Info . Guid ))
2020-10-11 06:24:54 +08:00
AutoGenH . Append ( "#define EDKII_DSC_PLATFORM_GUID \\\n %s \n " % GuidStringToGuidStructureString ( Info . PlatformInfo . Guid ))
2014-01-27 05:23:15 +00:00
if Info . IsLibrary :
return
# C file header
AutoGenC . Append ( gAutoGenHeaderString . Replace ({ 'FileName' : 'AutoGen.c' }))
2019-01-14 09:24:12 +08:00
# C file header files includes
if Info . ModuleType in gModuleTypeHeaderFile :
for Inc in gModuleTypeHeaderFile [ Info . ModuleType ]:
AutoGenC . Append ( "#include < %s > \n " % Inc )
else :
AutoGenC . Append ( "#include < %s > \n " % gBasicHeaderFile )
2014-01-27 05:23:15 +00:00
2019-01-14 09:24:12 +08:00
#
# Publish the CallerId Guid
#
AutoGenC . Append ( ' \n GLOBAL_REMOVE_IF_UNREFERENCED GUID gEfiCallerIdGuid = %s ; \n ' % GuidStringToGuidStructureString ( Info . Guid ))
2020-10-11 06:24:54 +08:00
AutoGenC . Append ( ' \n GLOBAL_REMOVE_IF_UNREFERENCED GUID gEdkiiDscPlatformGuid = %s ; \n ' % GuidStringToGuidStructureString ( Info . PlatformInfo . Guid ))
2019-01-14 09:24:12 +08:00
AutoGenC . Append ( ' \n GLOBAL_REMOVE_IF_UNREFERENCED CHAR8 *gEfiCallerBaseName = " %s "; \n ' % Info . Name )
2014-01-27 05:23:15 +00:00
## Create common code for header file
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
#
def CreateFooterCode ( Info , AutoGenC , AutoGenH ):
AutoGenH . Append ( gAutoGenHEpilogueString )
## Create code for a module
#
# @param Info The ModuleAutoGen object
# @param AutoGenC The TemplateString object for C code
# @param AutoGenH The TemplateString object for header file
2016-09-21 10:39:11 +08:00
# @param StringH The TemplateString object for header file
2014-01-27 05:23:15 +00:00
# @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
# @param UniGenBinBuffer Buffer to store uni string package data
2016-09-21 10:39:11 +08:00
# @param StringIdf The TemplateString object for header file
# @param IdfGenCFlag IdfString is generated into AutoGen C file when it is set to True
# @param IdfGenBinBuffer Buffer to store Idf string package data
2014-01-27 05:23:15 +00:00
#
2016-09-21 10:39:11 +08:00
def CreateCode ( Info , AutoGenC , AutoGenH , StringH , UniGenCFlag , UniGenBinBuffer , StringIdf , IdfGenCFlag , IdfGenBinBuffer ):
2014-01-27 05:23:15 +00:00
CreateHeaderCode ( Info , AutoGenC , AutoGenH )
2025-09-17 14:24:49 -07:00
# The only 32 bit arch we have is IA32, everything else is 64 bit
Bitwidth = 32 if Info . Arch == 'IA32' else 64
2024-06-14 14:07:33 -07:00
if GlobalData . gStackCookieValues64 == [] and os . path . exists ( os . path . join ( Info . PlatformInfo . BuildDir , "StackCookieValues64.json" )):
with open ( os . path . join ( Info . PlatformInfo . BuildDir , "StackCookieValues64.json" ), "r" ) as file :
GlobalData . gStackCookieValues64 = json . load ( file )
if GlobalData . gStackCookieValues32 == [] and os . path . exists ( os . path . join ( Info . PlatformInfo . BuildDir , "StackCookieValues32.json" )):
with open ( os . path . join ( Info . PlatformInfo . BuildDir , "StackCookieValues32.json" ), "r" ) as file :
GlobalData . gStackCookieValues32 = json . load ( file )
try :
if Bitwidth == 32 :
CookieValue = int ( GlobalData . gStackCookieValues32 [ hash ( Info . Guid ) % len ( GlobalData . gStackCookieValues32 )])
else :
CookieValue = int ( GlobalData . gStackCookieValues64 [ hash ( Info . Guid ) % len ( GlobalData . gStackCookieValues64 )])
except :
EdkLogger . warn ( "build" , "Failed to get Stack Cookie Value List! Generating random value." , ExtraData = "[ %s ]" % str ( Info ))
if Bitwidth == 32 :
CookieValue = secrets . randbelow ( 0xFFFFFFFF )
else :
CookieValue = secrets . randbelow ( 0xFFFFFFFFFFFFFFFF )
AutoGenH . Append ((
'#define STACK_COOKIE_VALUE 0x %X ULL \n ' % CookieValue
if Bitwidth == 64 else
'#define STACK_COOKIE_VALUE 0x %X \n ' % CookieValue
))
2019-01-14 09:24:12 +08:00
CreateGuidDefinitionCode ( Info , AutoGenC , AutoGenH )
CreateProtocolDefinitionCode ( Info , AutoGenC , AutoGenH )
CreatePpiDefinitionCode ( Info , AutoGenC , AutoGenH )
CreatePcdCode ( Info , AutoGenC , AutoGenH )
CreateLibraryConstructorCode ( Info , AutoGenC , AutoGenH )
CreateLibraryDestructorCode ( Info , AutoGenC , AutoGenH )
CreateModuleEntryPointCode ( Info , AutoGenC , AutoGenH )
CreateModuleUnloadImageCode ( Info , AutoGenC , AutoGenH )
2014-01-27 05:23:15 +00:00
if Info . UnicodeFileList :
FileName = " %s StrDefs.h" % Info . Name
StringH . Append ( gAutoGenHeaderString . Replace ({ 'FileName' : FileName }))
2018-06-25 18:31:33 +08:00
StringH . Append ( gAutoGenHPrologueString . Replace ({ 'File' : 'STRDEFS' , 'Guid' : Info . Guid . replace ( '-' , '_' )}))
2014-01-27 05:23:15 +00:00
CreateUnicodeStringCode ( Info , AutoGenC , StringH , UniGenCFlag , UniGenBinBuffer )
2014-11-11 07:33:50 +00:00
GuidMacros = []
for Guid in Info . Module . Guids :
if Guid in Info . Module . GetGuidsUsedByPcd ():
continue
GuidMacros . append ( '#define %s %s ' % ( Guid , Info . Module . Guids [ Guid ]))
2019-01-28 15:06:30 +08:00
for Guid , Value in list ( Info . Module . Protocols . items ()) + list ( Info . Module . Ppis . items ()):
2014-11-11 07:33:50 +00:00
GuidMacros . append ( '#define %s %s ' % ( Guid , Value ))
2018-06-19 09:08:41 +08:00
# supports FixedAtBuild and FeaturePcd usage in VFR file
2017-02-13 13:10:43 +08:00
if Info . VfrFileList and Info . ModulePcdList :
GuidMacros . append ( '#define %s %s ' % ( 'FixedPcdGetBool(TokenName)' , '_PCD_VALUE_##TokenName' ))
GuidMacros . append ( '#define %s %s ' % ( 'FixedPcdGet8(TokenName)' , '_PCD_VALUE_##TokenName' ))
GuidMacros . append ( '#define %s %s ' % ( 'FixedPcdGet16(TokenName)' , '_PCD_VALUE_##TokenName' ))
GuidMacros . append ( '#define %s %s ' % ( 'FixedPcdGet32(TokenName)' , '_PCD_VALUE_##TokenName' ))
GuidMacros . append ( '#define %s %s ' % ( 'FixedPcdGet64(TokenName)' , '_PCD_VALUE_##TokenName' ))
2018-06-19 09:08:41 +08:00
GuidMacros . append ( '#define %s %s ' % ( 'FeaturePcdGet(TokenName)' , '_PCD_VALUE_##TokenName' ))
2017-02-13 13:10:43 +08:00
for Pcd in Info . ModulePcdList :
2018-06-19 09:08:41 +08:00
if Pcd . Type in [ TAB_PCDS_FIXED_AT_BUILD , TAB_PCDS_FEATURE_FLAG ]:
2017-02-13 13:10:43 +08:00
TokenCName = Pcd . TokenCName
Value = Pcd . DefaultValue
if Pcd . DatumType == 'BOOLEAN' :
BoolValue = Value . upper ()
if BoolValue == 'TRUE' :
Value = '1'
elif BoolValue == 'FALSE' :
Value = '0'
for PcdItem in GlobalData . MixedPcd :
if ( Pcd . TokenCName , Pcd . TokenSpaceGuidCName ) in GlobalData . MixedPcd [ PcdItem ]:
TokenCName = PcdItem [ 0 ]
break
GuidMacros . append ( '#define %s %s ' % ( '_PCD_VALUE_' + TokenCName , Value ))
2017-03-31 22:05:28 +08:00
if Info . IdfFileList :
GuidMacros . append ( '#include " %s ImgDefs.h"' % Info . Name )
2014-11-11 07:33:50 +00:00
if GuidMacros :
StringH . Append ( ' \n #ifdef VFRCOMPILE \n %s \n #endif \n ' % ' \n ' . join ( GuidMacros ))
2014-01-27 05:23:15 +00:00
StringH . Append ( " \n #endif \n " )
AutoGenH . Append ( '#include " %s " \n ' % FileName )
2016-09-21 10:39:11 +08:00
if Info . IdfFileList :
FileName = " %s ImgDefs.h" % Info . Name
StringIdf . Append ( gAutoGenHeaderString . Replace ({ 'FileName' : FileName }))
2018-06-25 18:31:33 +08:00
StringIdf . Append ( gAutoGenHPrologueString . Replace ({ 'File' : 'IMAGEDEFS' , 'Guid' : Info . Guid . replace ( '-' , '_' )}))
2016-09-21 10:39:11 +08:00
CreateIdfFileCode ( Info , AutoGenC , StringIdf , IdfGenCFlag , IdfGenBinBuffer )
StringIdf . Append ( " \n #endif \n " )
AutoGenH . Append ( '#include " %s " \n ' % FileName )
2014-01-27 05:23:15 +00:00
CreateFooterCode ( Info , AutoGenC , AutoGenH )
## Create the code file
#
# @param FilePath The path of code file
# @param Content The content of code file
# @param IsBinaryFile The flag indicating if the file is binary file or not
#
# @retval True If file content is changed or file doesn't exist
# @retval False If the file exists and the content is not changed
#
def Generate ( FilePath , Content , IsBinaryFile ):
return SaveFileOnChange ( FilePath , Content , IsBinaryFile )