From nobody Tue Feb 10 19:14:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90070+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90070+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1653619433; cv=none; d=zohomail.com; s=zohoarc; b=d2z/fOFW9o5Q4HRsCxjesjwhYK6ngEd2Cy8KcztbrHofizeJi3TY/pUb39EnFxr5ymWZPUYYi6yGHkrlfD8bG1m7KkDBubQj2KlEWAg2jEwkl8ZuHdjFpwjXOGjCsrz4su/z3cKOZiC5jxwDF9IannKwO510L0/GU/nEUM8EBOU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653619433; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gV2SIy0P0TqsTnp9ho9GhU8r5SeENa4vUxx2tUqlyiY=; b=LbFoCwohmiLe5g5yryTBBk6ehbEg0Li8HfwZNGe4Zqyam92lXpst65E+ncF4AYNIRmMNOD4zwPAxPa/licByj+b6nJZtpI8zVLnHfFLEA9T6GDKIFgkrluw9OEwiof+RAcaY7u4UY9WnxrzvyHFMh+wzhf7ZFg3SihdKu6hWlEk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90070+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1653619433031927.0976321677301; Thu, 26 May 2022 19:43:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bOAOYY1788612xzptFgF7zYw; Thu, 26 May 2022 19:43:52 -0700 X-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 X-IronPort-AV: E=Sophos;i="5.91,254,1647302400"; d="scan'208";a="202322438" X-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 X-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) X-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 X-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 via groups.io" To: CC: Ard Biesheuvel , Leif Lindholm , Dandan Bi , Zhichao Gao , Liming Gao Subject: [edk2-devel] [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Date: Fri, 27 May 2022 04:43:13 +0200 Message-ID: <20220527024317.13476-9-graf@amazon.com> 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) Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,graf@amazon.com X-Gm-Message-State: uJG8Do7h9yKig7YaLuYLZWVax1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1653619432; bh=39+jvvHYlNFfiklF8IZwt/BHL/KyYSWxFoD+4YKAEFE=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=lkfCrwzH7tq2inpDkTn5IqF+UTyj+rRerB1toJTEX7zvYUTeBnU+VpBsA36VLlNz6I3 OBB/CdEYhPoXefKj3GgW9ClqwfMcG7cwalPz56s4hrIUVzQGuylTkDxzc7/a8r9m9YS4a Wes2RzIppIK/yjl/+os0UDStF9XaDmsNf7w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1653619434691100026 Content-Type: text/plain; charset="utf-8" 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); +} --=20 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 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90070): https://edk2.groups.io/g/devel/message/90070 Mute This Topic: https://groups.io/mt/91368910/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-