Fix double debug message output on serial port

SBL allows debug message to be redirected to output console besides
the serial port. However, serial port itself could be part of the
output console device as well. In this case the debug message will
be printed twice. This patch added check to this condition and skip
the redundant print.

It fixed #349.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
This commit is contained in:
Maurice Ma 2019-10-05 08:43:05 -07:00
parent 5ec7be2c5d
commit 56867c3bc6
2 changed files with 20 additions and 5 deletions

View File

@ -43,3 +43,4 @@
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES
gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES
gPlatformCommonLibTokenSpaceGuid.PcdDebugOutputDeviceMask ## CONSUMES
gPlatformCommonLibTokenSpaceGuid.PcdConsoleOutDeviceMask ## CONSUMES

View File

@ -47,6 +47,9 @@ DebugPrint (
{
CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH];
VA_LIST Marker;
UINTN Length;
BOOLEAN OutputToSerial;
//
// If Format is NULL, then ASSERT().
@ -60,6 +63,8 @@ DebugPrint (
return;
}
Length = AsciiStrLen (Buffer);
//
// Convert the DEBUG() message to an ASCII String
//
@ -71,13 +76,22 @@ DebugPrint (
// Send the print string to debug output handler
//
if (PcdGet32 (PcdDebugOutputDeviceMask) & DEBUG_OUTPUT_DEVICE_LOG_BUFFER) {
DebugLogBufferWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
}
if (PcdGet32 (PcdDebugOutputDeviceMask) & DEBUG_OUTPUT_DEVICE_SERIAL_PORT) {
SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
DebugLogBufferWrite ((UINT8 *)Buffer, Length);
}
OutputToSerial = (PcdGet32 (PcdDebugOutputDeviceMask) & DEBUG_OUTPUT_DEVICE_SERIAL_PORT) ? TRUE : FALSE;
if (PcdGet32 (PcdDebugOutputDeviceMask) & DEBUG_OUTPUT_DEVICE_CONSOLE) {
ConsoleWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
ConsoleWrite ((UINT8 *)Buffer, Length);
// If serial port is part of console output devices, skip the output below.
// since it has been outputed in ConsoleWrite().
if ( (PcdGet32 (PcdConsoleOutDeviceMask) & ConsoleOutSerialPort) != 0) {
OutputToSerial = FALSE;
}
}
if (OutputToSerial) {
SerialPortWrite ((UINT8 *)Buffer, Length);
}
}