From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by mx.groups.io with SMTP id smtpd.web10.3205.1653619431365736140 for ; Thu, 26 May 2022 19:43:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=bf1PDbmx; spf=pass (domain: amazon.de, ip: 72.21.196.25, mailfrom: prvs=139655964=graf@amazon.de) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1653619431; x=1685155431; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yhrhG3GqyZBD/JVmTUzzePTQR/xEiJxkzbMEkCXyW6g=; b=bf1PDbmxPYviOQtoFrHKRAVsbbK358m+msHQyN7LA67Yab4FcA04KCDE PbXzTjtg9eeRG9FRfkI6G6k+6xAAS8C7bhXX6AX+MelWyhc4XGB3KJSt6 eIDFnpapQ5Nf7Vd645a7IqzgQ6S50l9HrxM+6BhRzpnOjbxau/ew/YSMe w=; X-IronPort-AV: E=Sophos;i="5.91,254,1647302400"; d="scan'208";a="202322438" Received: from iad12-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-iad-1e-0bfdb89e.us-east-1.amazon.com) ([10.43.8.2]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP; 27 May 2022 02:43:51 +0000 Received: from EX13MTAUWC002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-0bfdb89e.us-east-1.amazon.com (Postfix) with ESMTPS id EA174E0023; Fri, 27 May 2022 02:43:48 +0000 (UTC) Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Fri, 27 May 2022 02:43:47 +0000 Received: from u79c5a0a55de558.ant.amazon.com (10.43.161.125) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Fri, 27 May 2022 02:43:46 +0000 From: "Alexander Graf" To: CC: Ard Biesheuvel , Leif Lindholm , Dandan Bi , Zhichao Gao , Liming Gao Subject: [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Date: Fri, 27 May 2022 04:43:13 +0200 Message-ID: <20220527024317.13476-9-graf@amazon.com> X-Mailer: git-send-email 2.28.0.394.ge197136389 In-Reply-To: <20220527024317.13476-1-graf@amazon.com> References: <20220527024317.13476-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.125] X-ClientProxiedBy: EX13D06UWC001.ant.amazon.com (10.43.162.91) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable In some situations, we do not want to emit any debug output to serial, but still create a bootlog. In these situations, we can use BaseDebugLibBootlog instead of BaseDebugLibNull. It's a DebugLib that emits exclusively to the bootlog. Signed-off-by: Alexander Graf --- .../BaseDebugLibBootlog.inf | 44 +++ .../BaseDebugLibBootlog.uni | 17 + MdePkg/Library/BaseDebugLibBootlog/DebugLib.c | 338 ++++++++++++++++++ 3 files changed, 399 insertions(+) create mode 100644 MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.= inf create mode 100644 MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.= uni create mode 100644 MdePkg/Library/BaseDebugLibBootlog/DebugLib.c diff --git a/MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.inf b/M= dePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.inf new file mode 100644 index 0000000000..4e524e0859 --- /dev/null +++ b/MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.inf @@ -0,0 +1,44 @@ +## @file +# Instance of Debug library that only emits to the boot log +# It uses PrintLib to send debug messages to the boot log. +# +# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2022, Amazon Development Center Germany GmbH.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseDebugLibSerialPort + MODULE_UNI_FILE =3D BaseDebugLibSerialPort.uni + FILE_GUID =3D BB83F95F-EDBC-4884-A520-CD42AF388FAE + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D DebugLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 EBC +# + +[Sources] + DebugLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseMemoryLib + PcdLib + PrintLib + BaseLib + DebugPrintErrorLevelLib + DebugBootlogLib + +[Pcd] + gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue ## SOMETIMES_CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask ## CONSUMES + gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel ## CONSUMES + diff --git a/MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.uni b/M= dePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.uni new file mode 100644 index 0000000000..de131c1292 --- /dev/null +++ b/MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.uni @@ -0,0 +1,17 @@ +// /** @file +// Instance of Debug Library that only emits to the boot log. +// +// It uses Print Library to produce formatted output strings to the boot l= og. +// +// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2022, Amazon Development Center Germany GmbH.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of Debug= Library that only emits to the boot log." + +#string STR_MODULE_DESCRIPTION #language en-US "It uses Print Lib= rary to produce formatted output strings to the boot log configuration tabl= e." + diff --git a/MdePkg/Library/BaseDebugLibBootlog/DebugLib.c b/MdePkg/Library= /BaseDebugLibBootlog/DebugLib.c new file mode 100644 index 0000000000..ad95ba5d22 --- /dev/null +++ b/MdePkg/Library/BaseDebugLibBootlog/DebugLib.c @@ -0,0 +1,338 @@ +/** @file + Base Debug library instance that only emits to the boot log + It uses PrintLib to send debug messages to the boot log. + + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2022, Amazon Development Center Germany GmbH.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +// +// Define the maximum debug and assert message length that this library su= pports +// +#define MAX_DEBUG_MESSAGE_LENGTH 0x100 + +// +// VA_LIST can not initialize to NULL for all compiler, so we use this to +// indicate a null VA_LIST +// +VA_LIST mVaListNull; + +/** + Prints a debug message to the debug output device if the specified error= level is enabled. + + If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function + GetDebugPrintErrorLevel (), then print the message specified by Format a= nd the + associated variable argument list to the debug output device. + + If Format is NULL, then ASSERT(). + + @param ErrorLevel The error level of the debug message. + @param Format Format string for the debug message to print. + @param ... Variable argument list whose contents are accessed + based on the format string specified by Format. + +**/ +VOID +EFIAPI +DebugPrint ( + IN UINTN ErrorLevel, + IN CONST CHAR8 *Format, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, Format); + DebugVPrint (ErrorLevel, Format, Marker); + VA_END (Marker); +} + +/** + Prints a debug message to the debug output device if the specified + error level is enabled base on Null-terminated format string and a + VA_LIST argument list or a BASE_LIST argument list. + + If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function + GetDebugPrintErrorLevel (), then print the message specified by Format a= nd + the associated variable argument list to the debug output device. + + If Format is NULL, then ASSERT(). + + @param ErrorLevel The error level of the debug message. + @param Format Format string for the debug message to print. + @param VaListMarker VA_LIST marker for the variable argument list. + @param BaseListMarker BASE_LIST marker for the variable argument list. + +**/ +VOID +DebugPrintMarker ( + IN UINTN ErrorLevel, + IN CONST CHAR8 *Format, + IN VA_LIST VaListMarker, + IN BASE_LIST BaseListMarker + ) +{ + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; + UINT32 DebugBootlogLevel, Length; + + // + // If Format is NULL, then ASSERT(). + // + ASSERT (Format !=3D NULL); + + DebugBootlogLevel =3D GetDebugBootlogErrorLevel (); + + // + // Check driver debug mask value and global mask + // + if ((ErrorLevel & DebugBootlogLevel) =3D=3D 0) { + return; + } + + // + // Convert the DEBUG() message to an ASCII String + // + if (BaseListMarker =3D=3D NULL) { + Length =3D AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker= ); + } else { + Length =3D AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMark= er); + } + + // + // Append the print string to the Boot Log + // + if (ErrorLevel & DebugBootlogLevel) { + DebugBootlogAppend (Buffer, Length, ErrorLevel); + } +} + +/** + Prints a debug message to the debug output device if the specified + error level is enabled. + + If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function + GetDebugPrintErrorLevel (), then print the message specified by Format a= nd + the associated variable argument list to the debug output device. + + If Format is NULL, then ASSERT(). + + @param ErrorLevel The error level of the debug message. + @param Format Format string for the debug message to print. + @param VaListMarker VA_LIST marker for the variable argument list. + +**/ +VOID +EFIAPI +DebugVPrint ( + IN UINTN ErrorLevel, + IN CONST CHAR8 *Format, + IN VA_LIST VaListMarker + ) +{ + DebugPrintMarker (ErrorLevel, Format, VaListMarker, NULL); +} + +/** + Prints a debug message to the debug output device if the specified + error level is enabled. + This function use BASE_LIST which would provide a more compatible + service than VA_LIST. + + If any bit in ErrorLevel is also set in DebugPrintErrorLevelLib function + GetDebugPrintErrorLevel (), then print the message specified by Format a= nd + the associated variable argument list to the debug output device. + + If Format is NULL, then ASSERT(). + + @param ErrorLevel The error level of the debug message. + @param Format Format string for the debug message to print. + @param BaseListMarker BASE_LIST marker for the variable argument list. + +**/ +VOID +EFIAPI +DebugBPrint ( + IN UINTN ErrorLevel, + IN CONST CHAR8 *Format, + IN BASE_LIST BaseListMarker + ) +{ + DebugPrintMarker (ErrorLevel, Format, mVaListNull, BaseListMarker); +} + +/** + Prints an assert message containing a filename, line number, and descrip= tion. + This may be followed by a breakpoint or a dead loop. + + Print a message of the form "ASSERT (): \n" + to the debug output device. If DEBUG_PROPERTY_ASSERT_BREAKPOINT_ENABLED= bit of + PcdDebugProperyMask is set then CpuBreakpoint() is called. Otherwise, if + DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED bit of PcdDebugProperyMask is set= then + CpuDeadLoop() is called. If neither of these bits are set, then this fu= nction + returns immediately after the message is printed to the debug output dev= ice. + DebugAssert() must actively prevent recursion. If DebugAssert() is call= ed while + processing another DebugAssert(), then DebugAssert() must return immedia= tely. + + If FileName is NULL, then a string of "(NULL) Filename" is pr= inted. + If Description is NULL, then a string of "(NULL) Descripti= on" is printed. + + @param FileName The pointer to the name of the source file that gen= erated the assert condition. + @param LineNumber The line number in the source file that generated t= he assert condition + @param Description The pointer to the description of the assert condit= ion. + +**/ +VOID +EFIAPI +DebugAssert ( + IN CONST CHAR8 *FileName, + IN UINTN LineNumber, + IN CONST CHAR8 *Description + ) +{ + // + // Generate a Breakpoint, DeadLoop, or NOP based on PCD settings + // + if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_BREAKPOINT_E= NABLED) !=3D 0) { + CpuBreakpoint (); + } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADL= OOP_ENABLED) !=3D 0) { + CpuDeadLoop (); + } +} + +/** + Fills a target buffer with PcdDebugClearMemoryValue, and returns the tar= get buffer. + + This function fills Length bytes of Buffer with the value specified by + PcdDebugClearMemoryValue, and returns Buffer. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param Buffer The pointer to the target buffer to be filled with PcdD= ebugClearMemoryValue. + @param Length The number of bytes in Buffer to fill with zeros PcdDeb= ugClearMemoryValue. + + @return Buffer The pointer to the target buffer filled with PcdDebugCl= earMemoryValue. + +**/ +VOID * +EFIAPI +DebugClearMemory ( + OUT VOID *Buffer, + IN UINTN Length + ) +{ + // + // If Buffer is NULL, then ASSERT(). + // + ASSERT (Buffer !=3D NULL); + + // + // SetMem() checks for the the ASSERT() condition on Length and returns = Buffer + // + return SetMem (Buffer, Length, PcdGet8 (PcdDebugClearMemoryValue)); +} + +/** + Returns TRUE if ASSERT() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bi= t of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebug= ProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebug= ProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugAssertEnabled ( + VOID + ) +{ + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_= ASSERT_ENABLED) !=3D 0); +} + +/** + Returns TRUE if DEBUG() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit= of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugP= roperyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugP= roperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugPrintEnabled ( + VOID + ) +{ + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_= PRINT_ENABLED) !=3D 0); +} + +/** + Returns TRUE if DEBUG_CODE() macros are enabled. + + This function returns TRUE if the DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit = of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPr= operyMask is set. + @retval FALSE The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugPr= operyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugCodeEnabled ( + VOID + ) +{ + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_= CODE_ENABLED) !=3D 0); +} + +/** + Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled. + + This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bi= t of + PcdDebugProperyMask is set. Otherwise FALSE is returned. + + @retval TRUE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebug= ProperyMask is set. + @retval FALSE The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebug= ProperyMask is clear. + +**/ +BOOLEAN +EFIAPI +DebugClearMemoryEnabled ( + VOID + ) +{ + return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_= MEMORY_ENABLED) !=3D 0); +} + +/** + Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixe= dDebugPrintErrorLevel. + + This function compares the bit mask of ErrorLevel and PcdFixedDebugPrint= ErrorLevel. + + @retval TRUE Current ErrorLevel is supported. + @retval FALSE Current ErrorLevel is not supported. + +**/ +BOOLEAN +EFIAPI +DebugPrintLevelEnabled ( + IN CONST UINTN ErrorLevel + ) +{ + return (BOOLEAN)((ErrorLevel & PcdGet32 (PcdFixedDebugPrintErrorLevel)) = !=3D 0); +} -- = 2.28.0.394.ge197136389 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879