在实现利用DXE驱动打印hello world的功能开发中,发现DEBUG函数无法显示的问题,接下来为整个开发流程。
首先在.c文件中需要包含#include <Library/DebugLib.h>头文件,而在函数体内部需要调用DEBUG ((EFI_D_ERROR , "DEBUG test start!\n"));其中EFI_D_ERROR为DEBUG_ERROR的宏定义,DEBUG test start!为想要DEBUG打印的内容。
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS
EFIAPI
DxeTestEntry(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status = EFI_SUCCESS;
DEBUG ((EFI_D_ERROR , "DEBUG test start!\n"));
Print(L"Hello,this is a DxeDriver test!\n");
DEBUG ((EFI_D_ERROR ,"DEBUG test end!\n"));
return Status;
}
接下来需要在.inf文件中的LibraryClasses中包含DebugLib
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = DxeDriver
FILE_GUID = D0B2C191-6255-4AC2-AE8E-73821B3E1F0F
MODULE_TYPE = UEFI_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = DxeTestEntry
[Sources]
DxePrint.c
[Packages]
MdePkg/MdePkg.dec
ShellPkg/ShellPkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
UefiDriverEntryPoint
BaseLib
BaseMemoryLib
DebugLib
DevicePathLib
UefiBootServicesTableLib
MemoryAllocationLib
UefiLib
[depex]
TRUE
接下来尤为重要,需要将.c .inf文件所在的Pkg包内的.dsc文件中的DEBUG_ENABLE_OUTPUT与DEBUG_PROPERTY_MASK修改为以下内容,其中TRUE为使能DEBUG输出,对应着调用下面的DebugLibConOut,即控制台输出Debug,而MASK为2为是能DEBUG打印。
DEFINE DEBUG_ENABLE_OUTPUT = TRUE # Set to TRUE to enable debug output
DEFINE DEBUG_PRINT_ERROR_LEVEL = 0x80000040 # Flags to control amount of debug output
DEFINE DEBUG_PROPERTY_MASK = 2
!if $(DEBUG_ENABLE_OUTPUT)
DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf
#DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
!else ## DEBUG_ENABLE_OUTPUT
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
!endif ## DEBUG_ENABLE_OUTPUT
#define DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED 0x01
#define DEBUG_PROPERTY_DEBUG_PRINT_ENABLED 0x02
#define DEBUG_PROPERTY_DEBUG_CODE_ENABLED 0x04
#define DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED 0x08
#define DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED 0x10
#define DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED 0x20