From 56867c3bc674097b5982fed19d3ee1b022112e39 Mon Sep 17 00:00:00 2001 From: Maurice Ma Date: Sat, 5 Oct 2019 08:43:05 -0700 Subject: [PATCH] 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 --- .../BootloaderDebugLib/BootloaderDebugLib.inf | 1 + .../Library/BootloaderDebugLib/DebugLib.c | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/BootloaderCommonPkg/Library/BootloaderDebugLib/BootloaderDebugLib.inf b/BootloaderCommonPkg/Library/BootloaderDebugLib/BootloaderDebugLib.inf index 6d95f2df..35e56950 100644 --- a/BootloaderCommonPkg/Library/BootloaderDebugLib/BootloaderDebugLib.inf +++ b/BootloaderCommonPkg/Library/BootloaderDebugLib/BootloaderDebugLib.inf @@ -43,3 +43,4 @@ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES gPlatformCommonLibTokenSpaceGuid.PcdDebugOutputDeviceMask ## CONSUMES + gPlatformCommonLibTokenSpaceGuid.PcdConsoleOutDeviceMask ## CONSUMES diff --git a/BootloaderCommonPkg/Library/BootloaderDebugLib/DebugLib.c b/BootloaderCommonPkg/Library/BootloaderDebugLib/DebugLib.c index 33f5d794..74513137 100644 --- a/BootloaderCommonPkg/Library/BootloaderDebugLib/DebugLib.c +++ b/BootloaderCommonPkg/Library/BootloaderDebugLib/DebugLib.c @@ -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); } }