public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 00/12] Introduce Bootlog DEBUG() output
@ 2022-05-27  2:43 Alexander Graf
  2022-05-27  2:43 ` [PATCH 01/12] MdePkg: Add DebugBootlog header Alexander Graf
                   ` (12 more replies)
  0 siblings, 13 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

I recently looked at improving the bootup performance of virtual machines
and was amazed by the fact that there is no logging / tracing framework
available that would give me a full picture of the Pre-OS phase including
time stamps and boot loaders (such as grub) without writing data to the
serial port - which taints all measurements.

The only place that I did find was PerformanceLib, which creates an FPDT.
I had 2 problems with that though:

  1) Discoverability - The best debugging tools give you all information
     you need as quickly as possible. The sub table FBPT which contains
     performance data is very condensed: It contains a modules GUID and up
     to 24 bytes of text per entry. Entries are limited to 255 bytes. It
     also only logs load events by default, nothing as fancy as FS reads.

  2) Ease of use - The best kernel engineers I know still use printk()
     and trace_printk() to identify issues: Because it's easy. You can
     quickly extract data into text and analyze later.

  3) Extensability to other payloads - The FPDT infrastructure considers
     everything as owned by PerformanceLib. I would like to create a one
     stop place for arbitrary UEFI applications to also put performance
     measurement data.

So I wrote a small configuration table (very similar to FPDT) that
contains references to boot logs, each with an array of strings as well
as time stamp. This patch set contains everything needed to set this up
and hook it into the 2 main DebugLib implementations in virtual machines:
Serial and DebugIO. That way, I can see every debug message after boot
with time stamp included, with very little impact on boot time.

I tried to see if I can call PERF_EVENT() instead of my Bootlog
infrastructure, but was unsuccessful. Let's use this patch set to open
the conversation on how to best move forward.

Eventually, I want to be able to log into Linux, fetch a sysfs file and
get a human readable, synchronized, time stamped log file with enough
information that allow me to create at least a bug report against the
actual firmware owner.


Github: https://github.com/agraf/edk2/tree/bootlog-v1

Alex


Alexander Graf (12):
  MdePkg: Add DebugBootlog header
  MdePkg: Add Null BaseDebugBootlog
  MdePkg: Add Fallback timer support for BaseDebugBootlog
  MdePkg: Add X86 timer support for BaseDebugBootlog
  MdePkg: Add ARM timer support for BaseDebugBootlog
  MdePkg: Add Pei phase BaseDebugBootlog
  MdePkg: Add Dxe phase BaseDebugBootlog
  MdePkg: Add BaseDebugLibBootlog
  Scripts: Add bootlog decyphering script
  BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs
  BaseDebugLibSerialPort: Emit messages to boot log
  OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support

 ArmVirtPkg/ArmVirt.dsc.inc                    |   5 +
 BaseTools/Scripts/ShowDebugLog.py             |  88 +++++
 EmulatorPkg/EmulatorPkg.dsc                   |   3 +
 IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc       |   1 +
 MdePkg/Include/Library/DebugBootlog.h         | 141 +++++++
 .../BaseDebugBootlog/BaseDebugBootlog.h       |  43 +++
 .../BaseDebugBootlog/BaseDebugBootlogLib.inf  |  61 +++
 .../BaseDebugBootlogLibPei.inf                |  60 +++
 .../BaseDebugBootlogNullLib.inf               |  26 ++
 .../Library/BaseDebugBootlog/DebugBootlog.c   |  22 ++
 .../BaseDebugBootlog/DebugBootlogArm.c        |  32 ++
 .../BaseDebugBootlog/DebugBootlogDxe.c        | 349 ++++++++++++++++++
 .../BaseDebugBootlog/DebugBootlogNotime.c     |  31 ++
 .../BaseDebugBootlog/DebugBootlogNull.c       |  32 ++
 .../BaseDebugBootlog/DebugBootlogPei.c        |  36 ++
 .../BaseDebugBootlog/DebugBootlogX86.c        |  50 +++
 .../BaseDebugLibBootlog.inf                   |  44 +++
 .../BaseDebugLibBootlog.uni                   |  17 +
 MdePkg/Library/BaseDebugLibBootlog/DebugLib.c | 338 +++++++++++++++++
 .../BaseDebugLibSerialPort.inf                |   1 +
 .../Library/BaseDebugLibSerialPort/DebugLib.c |  22 +-
 MdePkg/MdePkg.dec                             |  29 ++
 OvmfPkg/AmdSev/AmdSevX64.dsc                  |  10 +
 OvmfPkg/Bhyve/BhyveX64.dsc                    |  10 +
 OvmfPkg/CloudHv/CloudHvX64.dsc                |  10 +
 OvmfPkg/IntelTdx/IntelTdxX64.dsc              |   8 +
 .../Library/PlatformDebugLibIoPort/DebugLib.c |  23 +-
 .../PlatformDebugLibIoPort.inf                |   1 +
 .../PlatformRomDebugLibIoPort.inf             |   1 +
 .../PlatformRomDebugLibIoPortNocheck.inf      |   1 +
 OvmfPkg/Microvm/MicrovmX64.dsc                |  10 +
 OvmfPkg/OvmfPkgIa32.dsc                       |  10 +
 OvmfPkg/OvmfPkgIa32X64.dsc                    |  10 +
 OvmfPkg/OvmfPkgX64.dsc                        |   7 +
 OvmfPkg/OvmfXen.dsc                           |   1 +
 SourceLevelDebugPkg/SourceLevelDebugPkg.dsc   |   1 +
 UefiPayloadPkg/UefiPayloadPkg.dsc             |   1 +
 37 files changed, 1526 insertions(+), 9 deletions(-)
 create mode 100755 BaseTools/Scripts/ShowDebugLog.py
 create mode 100644 MdePkg/Include/Library/DebugBootlog.h
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlog.h
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlog.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogArm.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogDxe.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogNotime.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogNull.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogPei.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c
 create mode 100644 MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.inf
 create mode 100644 MdePkg/Library/BaseDebugLibBootlog/BaseDebugLibBootlog.uni
 create mode 100644 MdePkg/Library/BaseDebugLibBootlog/DebugLib.c

-- 
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




^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 01/12] MdePkg: Add DebugBootlog header
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 02/12] MdePkg: Add Null BaseDebugBootlog Alexander Graf
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

We will shortly introduce a new bootlog framework. This commit contains the
main library header that defines its data structure and public APIs.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 MdePkg/Include/Library/DebugBootlog.h | 141 ++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)
 create mode 100644 MdePkg/Include/Library/DebugBootlog.h

diff --git a/MdePkg/Include/Library/DebugBootlog.h b/MdePkg/Include/Library/DebugBootlog.h
new file mode 100644
index 0000000000..5e6b05411c
--- /dev/null
+++ b/MdePkg/Include/Library/DebugBootlog.h
@@ -0,0 +1,141 @@
+/** @file
+  Base Debug library for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+
+/*
+ * The bootlog framework is a way to collect all boot logging streams from the
+ * system into a single, condensed and time correlated data format. Its purpose
+ * is to allow extraction and correlation of boot logs from within the Operating
+ * System. Unlike I/O based logging, it's very cheap to use and can be used to
+ * easily identify duration of boot time code paths.
+ *
+ * Its intended use in edk2 is as a print backend for DebugLib, however you can
+ * use it stand alone as well. To append an edk2 log line, call
+ * DebugBootlogAppend() with the UTF-8 encoded string to append. The framework
+ * will initialize the boot log and add a configuration table if not existent
+ * automatically.
+ *
+ * The bootlog entry point is the bootlog configuration table. That table
+ * contains a dynamic number of pointers to bootlog logs. Each of these logs
+ * belong to one component of the boot flow, such as edk2 or grub and contain a
+ * dynamic number of log entries, each with a time stamp and optional additional
+ * data.
+ *
+ * All fields are Little Endian.
+ *
+ *  ___________________________________________________
+ * |             Bootlog Configuration Table           |
+ * |---------------------------------------------------|
+ * | UINT32 Signature | "BTLG"                         |
+ * | UINT16 MaxLogs   | Maximum number of logs this    |
+ * |                  | configuration table can hold.  |
+ * |                  | If you need more, create a     |
+ * |                  | clone and reregister it.       |
+ * | UINT16 NrLogs    | Number of occupied Log slots   |
+ * | BOOTLOG *Log[0]  |                             ---+------------,
+ * | BOOTLOG *Log[..] |                             ---+------------|
+ * |___________________________________________________|            |
+ *  ___________________________________________________________    /
+ * |                          Bootlog                          | <´
+ * |-----------------------------------------------------------|
+ * | UINT32 Signature          | "BTLH"                        |
+ * | CHAR8[4] Producer         | "edk2" for edk2, boot binary  |
+ * |                           | dependent.                    |
+ * | UINT16 ExtraHeaderType    | 1 for edk2                    |
+ * | UINT8  ExtraHeaderSize    | Bytes for ExtraHeader below   |
+ * | UINT8  MsgExtraHeaderSize | Bytes for Extra header in     |
+ * |                           | each log line                 |
+ * | UINT32 LastByte           | Length of the log, starting   |
+ * |                           | at &Signature                 |
+ * | UINT64 TicksPerSecond     | Frequency of the timer for    |
+ * |                           | each log line. Time at system |
+ * |                           | reset is 0 for all logs.      |
+ * | ExtraHeader ExtraHeader   | Depends on Type above      ---+---,
+ * | BootlogMessage Msgs[]     | Log lines                  ---+---|--,
+ * |___________________________________________________________|   |  |
+ *  _________________________________________________________     /   |
+ * |                     ExtraHeader (edk2)                  | <-´    |
+ * |---------------------------------------------------------|        |
+ * | UINT32 AllocatedSize | Size of the allocation for the   |        |
+ * |                      | current bootlog. Used internally |        |
+ * |                      | to resize on demand.             |        |
+ * |_________________________________________________________|        |
+ *  _________________________________________________________        /
+ * |                 Bootlog Message (edk2)                  | <----´
+ * |---------------------------------------------------------|
+ * | UINT32 ErrorLevel | edk2 defined ErrorLevel             |
+ * | UINT64 Ticks      | Ticks since power on                |
+ * | CHAR8  String[]   | '\0' terminated UTF-8 message       |
+ * |_________________________________________________________|
+ */
+
+
+#define SIG_BOOTLOG_CONFIG_TABLE 0x474c5442 /* BTLG */
+#define SIG_BOOTLOG_HEADER       0x484c5442 /* BTLH */
+
+#define BOOTLOG_PRODUCER "edk2"
+
+enum BOOTLOG_EXTRA_HEADER_TYPE {
+  BOOTLOG_EXTRA_HEADER_EDK2 = 1,
+};
+
+typedef struct {
+  UINT32 Signature;
+  UINT16 MaxLogs;
+  UINT16 NrLogs;
+  UINT64 LogAddress[];
+} BOOTLOG_CONFIG_TABLE;
+
+typedef struct {
+  UINT32 AllocatedSize;  /* Maximum space available for the log */
+} BOOTLOG_EXTRA_HEADER;
+
+typedef struct {
+  UINT32               Signature;            /* "BTLH" */
+  CHAR8                Producer[4];          /* "edk2" */
+  UINT16               ExtraHeaderType;      /* enum BOOTLOG_EXTRA_HEADER_TYPE */
+  UINT8                ExtraHeaderSize;      /* sizeof(ExtraHeader) */
+  UINT8                MsgExtraHeaderSize;   /* sizeof(BOOTLOG_ENTRY_EDK2) -
+                                                sizeof(BOOTLOG_ENTRY) */
+  UINT32               LastByte;             /* sizeof(BOOTLOG_HEADER) +
+                                                sizeof(Data) */
+  UINT64               TicksPerSecond;       /* Tick frequency. */
+  BOOTLOG_EXTRA_HEADER ExtraHeader;
+  CHAR8                Data[];               /* Multiple successive
+                                                BOOTLOG_ENTRY_EDK2 entries,
+                                                ends at LastByte */
+} BOOTLOG_HEADER;
+
+typedef struct {
+  UINT64 Ticks;                              /* Ticks since system start. */
+  CHAR8  String[];                           /* NULL terminated UTF-8 */
+} BOOTLOG_ENTRY;
+
+typedef struct {
+  UINT32        ErrorLevel;
+  BOOTLOG_ENTRY Log;
+} BOOTLOG_ENTRY_EDK2;
+
+RETURN_STATUS
+EFIAPI
+DebugBootlogAppend (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel
+  );
+
+UINT32
+EFIAPI
+GetDebugBootlogErrorLevel (
+  VOID
+  );
-- 
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



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 02/12] MdePkg: Add Null BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
  2022-05-27  2:43 ` [PATCH 01/12] MdePkg: Add DebugBootlog header Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 03/12] MdePkg: Add Fallback timer support for BaseDebugBootlog Alexander Graf
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

In some situations, we may not want to actually emit any boot log. This
commit adds a null bootlog handler. We will use this in situations where
we can not maintain a boot log, such as during the SEC phase.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlogNullLib.inf               | 26 +++++++++++++++
 .../BaseDebugBootlog/DebugBootlogNull.c       | 32 +++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogNull.c

diff --git a/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
new file mode 100644
index 0000000000..0f650f6260
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
@@ -0,0 +1,26 @@
+## @file
+#  Null Debug library instance for a RAM based boot log.
+#  It provides function stubs for boot log that do nothing.
+#
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2012, Red Hat, Inc.<BR>
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseDebugBootlogNull
+  FILE_GUID                      = DF934DA3-CD31-49FE-AF50-B3C87C79325F
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DebugBootlogLib
+
+[Sources]
+  DebugBootlogNull.c
+
+[Packages]
+  MdePkg/MdePkg.dec
diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogNull.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogNull.c
new file mode 100644
index 0000000000..fbb304e6e2
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogNull.c
@@ -0,0 +1,32 @@
+/** @file
+  Null Debug library instance for a RAM based boot log.
+  It provides function stubs for boot log that do nothing.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+
+UINT32
+EFIAPI
+GetDebugBootlogErrorLevel (
+  VOID
+  )
+{
+  return 0;
+}
+
+RETURN_STATUS
+EFIAPI
+DebugBootlogAppend (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel
+  )
+{
+  return RETURN_SUCCESS;
+}
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 03/12] MdePkg: Add Fallback timer support for BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
  2022-05-27  2:43 ` [PATCH 01/12] MdePkg: Add DebugBootlog header Alexander Graf
  2022-05-27  2:43 ` [PATCH 02/12] MdePkg: Add Null BaseDebugBootlog Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 04/12] MdePkg: Add X86 " Alexander Graf
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

The bootlog infrastructure records time stamps of every message. However,
not all platforms have readily available time sources. Add a fallback path
to return 0 for every time stamp.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlog/DebugBootlogNotime.c     | 31 +++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogNotime.c

diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogNotime.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogNotime.c
new file mode 100644
index 0000000000..e88c949cf2
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogNotime.c
@@ -0,0 +1,31 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseDebugBootlog.h"
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicksPerSecond (
+  VOID
+  )
+{
+  return 0;
+}
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicks (
+  VOID
+  )
+{
+  return 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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 04/12] MdePkg: Add X86 timer support for BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (2 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 03/12] MdePkg: Add Fallback timer support for BaseDebugBootlog Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 05/12] MdePkg: Add ARM " Alexander Graf
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

This patch adds time stamp infrastructure using the TSC. It attempts to
determine TSC frequency inside virtual machines, but not on read hardware.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlog/DebugBootlogX86.c        | 50 +++++++++++++++++++
 1 file changed, 50 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c

diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c
new file mode 100644
index 0000000000..1b6f677ce8
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogX86.c
@@ -0,0 +1,50 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseDebugBootlog.h"
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicksPerSecond (
+  VOID
+  )
+{
+  UINT32 MaxLeaf = 0;
+  UINT32 TscKhz = 0;
+
+  /* Look up VMware's TSC leaf first */
+  AsmCpuid (0x40000000, &MaxLeaf, NULL, NULL, NULL);
+  if (MaxLeaf >= 0x40000010 && MaxLeaf < 0x50000000) {
+    /* We're in a VM that supports the TSC leaf. */
+    AsmCpuid (0x40000010, &TscKhz, NULL, NULL, NULL);
+
+    return (UINT64)TscKhz * 1000;
+  }
+
+  /*
+   * The natural fallback path here would be to leverage TimerLib's
+   * GetPerformanceCounterProperties(), but TimerLib uses DebugLib
+   * so we can not use it. Let's leave TSC frequency extraction to
+   * post processing for now.
+   */
+
+  return 0;
+}
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicks (
+  VOID
+  )
+{
+  return AsmReadTsc();
+}
+
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 05/12] MdePkg: Add ARM timer support for BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (3 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 04/12] MdePkg: Add X86 " Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 06/12] MdePkg: Add Pei phase BaseDebugBootlog Alexander Graf
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

This patch adds bootlog time stamp infrastructure for ARM. It leverages
the architected timer which is present on all supported platforms.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlog/DebugBootlogArm.c        | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogArm.c

diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogArm.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogArm.c
new file mode 100644
index 0000000000..5a2c346844
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogArm.c
@@ -0,0 +1,32 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseDebugBootlog.h"
+#include <Library/ArmGenericTimerCounterLib.h>
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicksPerSecond (
+  VOID
+  )
+{
+  return ArmGenericTimerGetTimerFreq();
+}
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicks (
+  VOID
+  )
+{
+  return ArmGenericTimerGetSystemCount();
+}
+
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 06/12] MdePkg: Add Pei phase BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (4 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 05/12] MdePkg: Add ARM " Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 07/12] MdePkg: Add Dxe " Alexander Graf
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

This patch adds all logic required to collect bootlog data during the PEI
phase. During PEI, we create a HOB entry for every log line. Later, when
we emit the first DXE bootlog line, we automatically collect all bootlog
HOB entries into the actual bootlog.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlog/BaseDebugBootlog.h       | 43 +++++++++++++
 .../BaseDebugBootlogLibPei.inf                | 60 +++++++++++++++++++
 .../Library/BaseDebugBootlog/DebugBootlog.c   | 22 +++++++
 .../BaseDebugBootlog/DebugBootlogPei.c        | 36 +++++++++++
 MdePkg/MdePkg.dec                             | 29 +++++++++
 5 files changed, 190 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlog.h
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlog.c
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogPei.c

diff --git a/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlog.h b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlog.h
new file mode 100644
index 0000000000..6bba4a5c30
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlog.h
@@ -0,0 +1,43 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <PiPei.h>
+#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+#include <Library/PcdLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugPrintErrorLevelLib.h>
+#include <Library/DebugBootlog.h>
+
+//
+// Starting size of the log buffer
+//
+#define BOOTLOG_MIN_SIZE 0x80000
+
+//
+// Maximum number of parallel boot logs
+//
+#define MAX_LOGS 16
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicksPerSecond (
+  VOID
+  );
+
+UINT64
+EFIAPI
+BaseDebugLibBootlogTicks (
+  VOID
+  );
diff --git a/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
new file mode 100644
index 0000000000..abc66a953f
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
@@ -0,0 +1,60 @@
+## @file
+#  Base Debug library instance for a RAM based boot log
+#  It provides functions to store debug messages in RAM and make them available as
+#  Bootlog Configuration Table.
+#
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2012, Red Hat, Inc.<BR>
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseDebugBootlog
+  FILE_GUID                      = DF934DA3-CD31-49FE-AF50-B3C87C79325D
+  MODULE_TYPE                    = PEI_CORE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DebugBootlogLib|PEI_CORE PEIM
+
+[Sources]
+  DebugBootlog.c
+  DebugBootlogPei.c
+
+[Sources.IA32, Sources.X64]
+  DebugBootlogX86.c
+
+[Sources.ARM, Sources.AARCH64]
+  DebugBootlogArm.c
+
+[Sources.EBC, Sources.RISCV64]
+  DebugBootlogNotime.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[Packages.AARCH64]
+  ArmPkg/ArmPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  PcdLib
+  PrintLib
+  BaseLib
+  DebugPrintErrorLevelLib
+  PeiServicesLib
+
+[LibraryClasses.AARCH64]
+  ArmGenericTimerCounterLib
+
+[LibraryClasses.ARM]
+  ArmGenericTimerCounterLib
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugBootlogErrorLevel       ## CONSUMES
+
+[Guids]
+  gBootlogConfigTableGuid ## CONSUMES
diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlog.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlog.c
new file mode 100644
index 0000000000..bceb1c96da
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlog.c
@@ -0,0 +1,22 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/PcdLib.h>
+
+UINT32
+EFIAPI
+GetDebugBootlogErrorLevel (
+  VOID
+  )
+{
+  return PcdGet32 (PcdDebugBootlogErrorLevel);
+}
diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogPei.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogPei.c
new file mode 100644
index 0000000000..2106e8190a
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogPei.c
@@ -0,0 +1,36 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseDebugBootlog.h"
+#include <Library/PeiServicesLib.h>
+
+RETURN_STATUS
+EFIAPI
+DebugBootlogAppend (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel
+  )
+{
+  BOOTLOG_ENTRY_EDK2 *Entry;
+
+  Entry = BuildGuidHob (&gBootlogConfigTableGuid, sizeof(*Entry) + Length + 1);
+  if (Entry == NULL)
+    return EFI_NOT_FOUND;
+
+  Entry->ErrorLevel = ErrorLevel;
+  Entry->Log.Ticks = BaseDebugLibBootlogTicks();
+  CopyMem (&Entry->Log.String, String, Length);
+  Entry->Log.String[Length] = '\0';
+
+  return EFI_SUCCESS;
+}
diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec
index f1ebf9e251..8e68324028 100644
--- a/MdePkg/MdePkg.dec
+++ b/MdePkg/MdePkg.dec
@@ -837,6 +837,11 @@
   ## Include/Protocol/CcMeasurement.h
   gEfiCcFinalEventsTableGuid     = { 0xdd4a4648, 0x2de7, 0x4665, { 0x96, 0x4d, 0x21, 0xd9, 0xef, 0x5f, 0xb4, 0x46 }}
 
+  #
+  # GUID to identify Bootlog data
+  #
+  gBootlogConfigTableGuid               = {0xd6128add, 0x85fa, 0x4428, {0x96, 0x5b, 0x26, 0xfd, 0xab, 0xad, 0xfb, 0x26}}
+
 [Guids.IA32, Guids.X64]
   ## Include/Guid/Cper.h
   gEfiIa32X64ErrorTypeCacheCheckGuid = { 0xA55701F5, 0xE3EF, 0x43de, { 0xAC, 0x72, 0x24, 0x9B, 0x57, 0x3F, 0xAD, 0x2C }}
@@ -2257,6 +2262,30 @@
   # @Expression  0x80000002 | (gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel & 0x7F84AA00) == 0
   gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000000|UINT32|0x00000006
 
+  ## This flag is used to control the boot log Debug message.<BR><BR>
+  #  BIT0  - Initialization message.<BR>
+  #  BIT1  - Warning message.<BR>
+  #  BIT2  - Load Event message.<BR>
+  #  BIT3  - File System message.<BR>
+  #  BIT4  - Allocate or Free Pool message.<BR>
+  #  BIT5  - Allocate or Free Page message.<BR>
+  #  BIT6  - Information message.<BR>
+  #  BIT7  - Dispatcher message.<BR>
+  #  BIT8  - Variable message.<BR>
+  #  BIT10 - Boot Manager message.<BR>
+  #  BIT12 - BlockIo Driver message.<BR>
+  #  BIT14 - Network Driver message.<BR>
+  #  BIT16 - UNDI Driver message.<BR>
+  #  BIT17 - LoadFile message.<BR>
+  #  BIT19 - Event message.<BR>
+  #  BIT20 - Global Coherency Database changes message.<BR>
+  #  BIT21 - Memory range cachability changes message.<BR>
+  #  BIT22 - Detailed debug message.<BR>
+  #  BIT31 - Error message.<BR>
+  # @Prompt Debug Message Bootlog Level.
+  # @Expression  0x80000002 | (gEfiMdePkgTokenSpaceGuid.PcdDebugBootlogErrorLevel & 0x7F84AA00) == 0
+  gEfiMdePkgTokenSpaceGuid.PcdDebugBootlogErrorLevel|0x8000004F|UINT32|0x00000031
+
   ## The mask is used to control ReportStatusCodeLib behavior.<BR><BR>
   #  BIT0 - Enable Progress Code.<BR>
   #  BIT1 - Enable Error Code.<BR>
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 07/12] MdePkg: Add Dxe phase BaseDebugBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (5 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 06/12] MdePkg: Add Pei phase BaseDebugBootlog Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Alexander Graf
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

This patch adds the main bootlog infrastructure to dynamically create the
bootlog configuration table and edk2 bootlog at DXE phase. It attempts to
do all this dynamically: The bootlog configuration table may first get
created by a UEFI application.

This code also collects all PEI phase log entries and assembles them into
the final bootlog.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugBootlog/BaseDebugBootlogLib.inf  |  61 +++
 .../BaseDebugBootlog/DebugBootlogDxe.c        | 349 ++++++++++++++++++
 2 files changed, 410 insertions(+)
 create mode 100644 MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
 create mode 100644 MdePkg/Library/BaseDebugBootlog/DebugBootlogDxe.c

diff --git a/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
new file mode 100644
index 0000000000..49cdd3f9ad
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
@@ -0,0 +1,61 @@
+## @file
+#  Base Debug library instance for a RAM based boot log
+#  It provides functions to store debug messages in RAM and make them available as
+#  Bootlog Configuration Table.
+#
+#  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2012, Red Hat, Inc.<BR>
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseDebugBootlog
+  FILE_GUID                      = DF934DA3-CD31-49FE-AF50-B3C87C79325C
+  MODULE_TYPE                    = DXE_CORE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DebugBootlogLib|DXE_CORE DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
+  CONSTRUCTOR                    = BaseDebugBootlogLibConstructor
+
+[Sources]
+  DebugBootlog.c
+  DebugBootlogDxe.c
+
+[Sources.IA32, Sources.X64]
+  DebugBootlogX86.c
+
+[Sources.ARM, Sources.AARCH64]
+  DebugBootlogArm.c
+
+[Sources.EBC, Sources.RISCV64]
+  DebugBootlogNotime.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+
+[Packages.AARCH64]
+  ArmPkg/ArmPkg.dec
+
+[LibraryClasses]
+  BaseMemoryLib
+  PcdLib
+  PrintLib
+  BaseLib
+  DebugPrintErrorLevelLib
+
+[LibraryClasses.AARCH64]
+  ArmGenericTimerCounterLib
+
+[LibraryClasses.ARM]
+  ArmGenericTimerCounterLib
+
+[Pcd]
+  gEfiMdePkgTokenSpaceGuid.PcdDebugBootlogErrorLevel       ## CONSUMES
+
+[Guids]
+  gBootlogConfigTableGuid ## CONSUMES
+  gEfiHobListGuid ## CONSUMES
diff --git a/MdePkg/Library/BaseDebugBootlog/DebugBootlogDxe.c b/MdePkg/Library/BaseDebugBootlog/DebugBootlogDxe.c
new file mode 100644
index 0000000000..b95cb969f1
--- /dev/null
+++ b/MdePkg/Library/BaseDebugBootlog/DebugBootlogDxe.c
@@ -0,0 +1,349 @@
+/** @file
+  Base Debug library instance for a RAM based boot log
+  It provides functions to store debug messages in RAM and make them available as
+  Bootlog Configuration Table.
+
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2012, Red Hat, Inc.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "BaseDebugBootlog.h"
+
+//
+// Cached pointer to the current bootlog structure
+//
+BOOTLOG_HEADER *gBootlog;
+
+//
+// We can not link against UefiBootServicesTableLib as that itself references
+// DebugLib, so instead we save our own copies of the System Table and Boot
+// Services structs.
+//
+static EFI_SYSTEM_TABLE *mDebugST;
+
+/**
+  We can not link against UefiBootServicesTableLib as that itself references
+  DebugLib, so instead we save our own copies of the System Table and Boot
+  Services structs.
+
+  @retval EFI_SUCCESS   The constructor always returns RETURN_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+BaseDebugBootlogLibConstructor (
+  IN EFI_HANDLE        ImageHandle,
+  IN EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  mDebugST = SystemTable;
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+BaseDebugBootlogAppendInternal (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel,
+  IN        UINT64 Ticks
+  );
+
+static
+EFI_STATUS
+EFIAPI
+UpdateEdk2Bootlog (
+  IN BOOTLOG_CONFIG_TABLE *Table,
+  IN BOOTLOG_HEADER       *OldBootlog,
+  IN BOOTLOG_HEADER       *NewBootlog
+  )
+{
+  UINTN Index;
+
+  for (Index = 0; Index < Table->NrLogs; Index++) {
+    if (Table->LogAddress[Index] == (EFI_PHYSICAL_ADDRESS) OldBootlog) {
+      Table->LogAddress[Index] = (EFI_PHYSICAL_ADDRESS) NewBootlog;
+      return EFI_SUCCESS;
+    }
+  }
+
+  return EFI_NOT_FOUND;
+}
+
+static
+EFI_STATUS
+EFIAPI
+FindEdk2Bootlog (
+  IN  BOOTLOG_CONFIG_TABLE  *Table,
+  OUT BOOTLOG_HEADER       **Bootlog
+  )
+{
+  UINTN Index;
+  BOOTLOG_HEADER *Cur;
+
+  for (Index = 0; Index < Table->NrLogs; Index++) {
+    Cur = (BOOTLOG_HEADER *)Table->LogAddress[Index];
+    if (Cur->Signature == SIG_BOOTLOG_HEADER &&
+        CompareMem(Cur->Producer, BOOTLOG_PRODUCER, sizeof(Cur->Producer)) == 0 &&
+        Cur->ExtraHeaderType == BOOTLOG_EXTRA_HEADER_EDK2) {
+      *Bootlog = Cur;
+      return EFI_SUCCESS;
+    }
+  }
+
+  return EFI_NOT_FOUND;
+}
+
+static
+EFI_STATUS
+EFIAPI
+FindConfigTable (
+  IN  EFI_GUID *TableGuid,
+  OUT VOID     *Table
+  )
+{
+  EFI_SYSTEM_TABLE  *SystemTable;
+  VOID             **_Table = Table;
+  UINTN             Index;
+
+  if (TableGuid == NULL || Table == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  SystemTable = mDebugST;
+  *_Table      = NULL;
+  for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {
+    if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].VendorGuid))) {
+      *_Table = SystemTable->ConfigurationTable[Index].VendorTable;
+      return EFI_SUCCESS;
+    }
+  }
+
+  return EFI_NOT_FOUND;
+}
+
+static
+EFI_STATUS
+EFIAPI
+AllocateTable (
+  IN EFI_BOOT_SERVICES     *BS,
+  IN BOOTLOG_CONFIG_TABLE **pTable
+  )
+{
+  EFI_STATUS Status;
+  UINTN TableLength = sizeof(BOOTLOG_CONFIG_TABLE) + MAX_LOGS * sizeof(UINT64);
+
+  Status = BS->AllocatePool (
+                  EfiBootServicesData,
+                  TableLength,
+                  (VOID **)pTable
+                  );
+  if (Status != EFI_SUCCESS)
+    return Status;
+
+  ZeroMem (*pTable, TableLength);
+  (*pTable)->Signature = SIG_BOOTLOG_CONFIG_TABLE;
+  (*pTable)->MaxLogs = MAX_LOGS;
+
+  return Status;
+}
+
+static
+EFI_STATUS
+EFIAPI
+AllocateBootlog (
+  IN EFI_BOOT_SERVICES  *BS,
+  IN BOOTLOG_HEADER    **NewBootlog,
+  IN UINTN               Size
+  )
+{
+  EFI_STATUS Status;
+
+  Status = BS->AllocatePages (
+                  AllocateAnyPages,
+                  EfiBootServicesData,
+                  EFI_SIZE_TO_PAGES (Size),
+                  (EFI_PHYSICAL_ADDRESS *)NewBootlog
+                  );
+  if (Status != EFI_SUCCESS)
+    return Status;
+
+  ZeroMem (*NewBootlog, Size);
+
+  return Status;
+}
+
+static
+VOID
+EFIAPI
+BaseDebugLibBootlogInitialize (
+  IN BOOTLOG_HEADER *Bootlog,
+  IN UINT64 Size
+  )
+{
+  Bootlog->Signature = SIG_BOOTLOG_HEADER;
+  CopyMem(Bootlog->Producer, BOOTLOG_PRODUCER, sizeof(Bootlog->Producer));
+  Bootlog->ExtraHeaderType = BOOTLOG_EXTRA_HEADER_EDK2;
+  Bootlog->ExtraHeaderSize = sizeof(Bootlog->ExtraHeader);
+  Bootlog->MsgExtraHeaderSize = sizeof(BOOTLOG_ENTRY_EDK2) - sizeof(BOOTLOG_ENTRY);
+  Bootlog->LastByte = OFFSET_OF(BOOTLOG_HEADER, Data);
+  Bootlog->TicksPerSecond = BaseDebugLibBootlogTicksPerSecond();
+  Bootlog->ExtraHeader.AllocatedSize = Size;
+}
+
+static
+EFI_STATUS
+EFIAPI
+BaseDebugLibFindAndExpandBootlog (
+  IN BOOTLOG_HEADER **pBootlog,
+  IN UINTN AppendDataLength
+  )
+{
+  EFI_BOOT_SERVICES    *BS;
+  BOOTLOG_HEADER       *Bootlog;
+  BOOTLOG_HEADER       *NewBootlog;
+  BOOTLOG_CONFIG_TABLE *Table;
+  EFI_STATUS            Status = EFI_SUCCESS;
+  UINTN                 NewSize;
+  EFI_PEI_HOB_POINTERS  Hob;
+
+  if (!mDebugST || !mDebugST->BootServices)
+    return EFI_NOT_FOUND;
+
+  BS = mDebugST->BootServices;
+
+  if (!gBootlog) {
+    /* Allocate a new Bootlog Configuration Table if not present */
+    if (FindConfigTable (&gBootlogConfigTableGuid, &Table) != EFI_SUCCESS) {
+      Status = AllocateTable (BS, &Table);
+      if (Status != EFI_SUCCESS) {
+        return Status;
+      }
+
+      Status = BS->InstallConfigurationTable (
+                      &gBootlogConfigTableGuid,
+                      Table
+                      );
+      if (Status != EFI_SUCCESS) {
+        return Status;
+      }
+    }
+
+    /* Allocate a Bootlog structure if none is in the table */
+    if (FindEdk2Bootlog (Table, &Bootlog) != EFI_SUCCESS) {
+      /*
+       * There is a tiny phase right after DXE entry where gEfiHobListGuid is
+       * not populated yet. But we need the HobList to carry PEI logs over.
+       * Let's just drop any line that we get in that period.
+       */
+      Status = FindConfigTable (&gEfiHobListGuid, &Hob.Raw);
+      if (Status != EFI_SUCCESS) {
+        return Status;
+      }
+
+      Status = AllocateBootlog (BS, &Bootlog, BOOTLOG_MIN_SIZE);
+      if (Status != EFI_SUCCESS) {
+        return Status;
+      }
+      BaseDebugLibBootlogInitialize(Bootlog, BOOTLOG_MIN_SIZE);
+
+      if (Table->NrLogs >= Table->MaxLogs) {
+        return EFI_NOT_FOUND;
+      }
+      Table->LogAddress[Table->NrLogs++] = (EFI_PHYSICAL_ADDRESS) Bootlog;
+
+      gBootlog = Bootlog;
+
+      /*
+       * This is the first time we go from PEI -> DXE. Copy all PEI log entries
+       * into our full fledged boot log structure
+       */
+      if (Status == EFI_SUCCESS) {
+        while (!END_OF_HOB_LIST (Hob)) {
+          if (Hob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION &&
+              CompareGuid (&gBootlogConfigTableGuid, &Hob.Guid->Name) &&
+              GET_HOB_LENGTH (Hob) > sizeof (BOOTLOG_ENTRY_EDK2)) {
+              BOOTLOG_ENTRY_EDK2 *Entry = GET_GUID_HOB_DATA (Hob);
+              BaseDebugBootlogAppendInternal (
+                  Entry->Log.String,
+                  AsciiStrLen (Entry->Log.String),
+                  Entry->ErrorLevel,
+                  Entry->Log.Ticks
+                  );
+          }
+
+          Hob.Raw = GET_NEXT_HOB (Hob);
+        }
+      }
+    }
+
+    gBootlog = Bootlog;
+  } else {
+    Bootlog = gBootlog;
+  }
+
+  /* Resize if the new string would not fit */
+  if ((Bootlog->LastByte + AppendDataLength) > Bootlog->ExtraHeader.AllocatedSize) {
+    NewSize = ALIGN_VALUE (Bootlog->LastByte + AppendDataLength + EFI_PAGE_SIZE * 16,
+                           EFI_PAGE_SIZE);
+    Status = AllocateBootlog (BS, &NewBootlog, NewSize);
+    if (Status != EFI_SUCCESS) {
+      return Status;
+    }
+
+    CopyMem (NewBootlog, Bootlog, Bootlog->LastByte);
+    NewBootlog->ExtraHeader.AllocatedSize = NewSize;
+    UpdateEdk2Bootlog (Table, Bootlog, NewBootlog);
+    BS->FreePages ((EFI_PHYSICAL_ADDRESS) Bootlog,
+                   EFI_SIZE_TO_PAGES (Bootlog->ExtraHeader.AllocatedSize));
+    Bootlog = gBootlog = NewBootlog;
+  }
+
+  *pBootlog = Bootlog;
+
+  return Status;
+}
+
+EFI_STATUS
+EFIAPI
+BaseDebugBootlogAppendInternal (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel,
+  IN        UINT64 Ticks
+  )
+{
+  BOOTLOG_HEADER     *Bootlog;
+  BOOTLOG_ENTRY_EDK2  Hdr;
+
+  if (BaseDebugLibFindAndExpandBootlog (&Bootlog, Length + sizeof(Hdr)) != EFI_SUCCESS)
+    return EFI_SUCCESS;
+
+  Hdr.ErrorLevel = ErrorLevel;
+  Hdr.Log.Ticks = Ticks;
+
+  CopyMem (((VOID *)Bootlog) + Bootlog->LastByte, &Hdr, sizeof(Hdr));
+  Bootlog->LastByte += sizeof(Hdr);
+  CopyMem (((VOID *)Bootlog) + Bootlog->LastByte, String, Length);
+  Bootlog->LastByte += Length;
+  *((CHAR8 *)Bootlog + Bootlog->LastByte) = '\0';
+  Bootlog->LastByte += 1;
+
+  return EFI_SUCCESS;
+}
+
+RETURN_STATUS
+EFIAPI
+DebugBootlogAppend (
+  IN  CONST CHAR8  *String,
+  IN        UINTN  Length,
+  IN        UINTN  ErrorLevel
+  )
+{
+  return BaseDebugBootlogAppendInternal(String, Length, ErrorLevel,
+                                        BaseDebugLibBootlogTicks ());
+}
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (6 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 07/12] MdePkg: Add Dxe " Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 09/12] Scripts: Add bootlog decyphering script Alexander Graf
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

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 <graf@amazon.com>
---
 .../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/MdePkg/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.<BR>
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = BaseDebugLibSerialPort
+  MODULE_UNI_FILE                = BaseDebugLibSerialPort.uni
+  FILE_GUID                      = BB83F95F-EDBC-4884-A520-CD42AF388FAE
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = DebugLib
+
+#
+#  VALID_ARCHITECTURES           = 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/MdePkg/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 log.
+//
+// Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
+// Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+//
+// 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 Library to produce formatted output strings to the boot log configuration table."
+
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.<BR>
+  Copyright (c) 2022, Amazon Development Center Germany GmbH.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugPrintErrorLevelLib.h>
+#include <Library/DebugBootlog.h>
+
+//
+// Define the maximum debug and assert message length that this library supports
+//
+#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 and 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 and
+  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 != NULL);
+
+  DebugBootlogLevel = GetDebugBootlogErrorLevel ();
+
+  //
+  // Check driver debug mask value and global mask
+  //
+  if ((ErrorLevel & DebugBootlogLevel) == 0) {
+    return;
+  }
+
+  //
+  // Convert the DEBUG() message to an ASCII String
+  //
+  if (BaseListMarker == NULL) {
+    Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+  } else {
+    Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+  }
+
+  //
+  // 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 and
+  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 and
+  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 description.
+  This may be followed by a breakpoint or a dead loop.
+
+  Print a message of the form "ASSERT <FileName>(<LineNumber>): <Description>\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 function
+  returns immediately after the message is printed to the debug output device.
+  DebugAssert() must actively prevent recursion.  If DebugAssert() is called while
+  processing another DebugAssert(), then DebugAssert() must return immediately.
+
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
+
+  @param  FileName     The pointer to the name of the source file that generated the assert condition.
+  @param  LineNumber   The line number in the source file that generated the assert condition
+  @param  Description  The pointer to the description of the assert condition.
+
+**/
+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_ENABLED) != 0) {
+    CpuBreakpoint ();
+  } else if ((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_ASSERT_DEADLOOP_ENABLED) != 0) {
+    CpuDeadLoop ();
+  }
+}
+
+/**
+  Fills a target buffer with PcdDebugClearMemoryValue, and returns the target 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 PcdDebugClearMemoryValue.
+  @param   Length  The number of bytes in Buffer to fill with zeros PcdDebugClearMemoryValue.
+
+  @return  Buffer  The pointer to the target buffer filled with PcdDebugClearMemoryValue.
+
+**/
+VOID *
+EFIAPI
+DebugClearMemory (
+  OUT VOID  *Buffer,
+  IN UINTN  Length
+  )
+{
+  //
+  // If Buffer is NULL, then ASSERT().
+  //
+  ASSERT (Buffer != 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 bit of
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugAssertEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 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 PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_PRINT_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugPrintEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_PRINT_ENABLED) != 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 PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_DEBUG_CODE_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugCodeEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_DEBUG_CODE_ENABLED) != 0);
+}
+
+/**
+  Returns TRUE if DEBUG_CLEAR_MEMORY() macro is enabled.
+
+  This function returns TRUE if the DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of
+  PcdDebugProperyMask is set.  Otherwise FALSE is returned.
+
+  @retval  TRUE    The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is set.
+  @retval  FALSE   The DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED bit of PcdDebugProperyMask is clear.
+
+**/
+BOOLEAN
+EFIAPI
+DebugClearMemoryEnabled (
+  VOID
+  )
+{
+  return (BOOLEAN)((PcdGet8 (PcdDebugPropertyMask) & DEBUG_PROPERTY_CLEAR_MEMORY_ENABLED) != 0);
+}
+
+/**
+  Returns TRUE if any one of the bit is set both in ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+  This function compares the bit mask of ErrorLevel and PcdFixedDebugPrintErrorLevel.
+
+  @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)) != 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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 09/12] Scripts: Add bootlog decyphering script
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (7 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 10/12] BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs Alexander Graf
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

The bootlog itself is a binary data structure that is not immediately human
readable. This commit adds a python script to generate a human readable form
of it with Linux dmesg like time stamp information.

The script can take multiple log sources and collate them into a single
output, making it easier to correlate messages.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 BaseTools/Scripts/ShowDebugLog.py | 88 +++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100755 BaseTools/Scripts/ShowDebugLog.py

diff --git a/BaseTools/Scripts/ShowDebugLog.py b/BaseTools/Scripts/ShowDebugLog.py
new file mode 100755
index 0000000000..f99b4b02f7
--- /dev/null
+++ b/BaseTools/Scripts/ShowDebugLog.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python3
+## @file
+#  Dump Bootlog files
+#
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+from __future__ import print_function
+
+VersionNumber = '0.1'
+__copyright__ = "Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.."
+
+import argparse
+import os
+import sys
+import struct
+
+class DebugLog:
+    """Parses a Bootlog blob and provides a string representation
+    """
+
+    def __init__(self, log):
+        self.entries = []
+        off = 0
+
+        signature, self.producer, extraheadertype, extraheadersize, msgextraheadersize, lastbyte, self.tickspersecond = struct.unpack_from('<4s4sHBBLQ', log)
+        if signature != b'BTLH':
+            raise Exception("File has incorrect signature. Expected b'BTLH'. Found %s." % signature)
+        if len(log) < lastbyte:
+            raise Exception("File smaller than total log contents (%d < %d). It was probably truncated." % (len(log), lastbyte))
+        off = 4 + 4 + 2 + 1 + 1 + 4 + 8 + extraheadersize
+
+        while off < lastbyte:
+            off = off + msgextraheadersize
+            time, = struct.unpack_from('<Q', log, off)
+            off = off + 8
+            msg = log[off:log.find(b'\0', off)]
+            off = off + len(msg) + 1
+            if self.tickspersecond != 0:
+                time = time / float(self.tickspersecond)
+            self.entries.append({ "time": time,
+                                  "msg": msg.decode("utf-8")})
+
+    def __str__(self):
+        if self.tickspersecond != 0:
+           fmt = "[%14.6f] %s"
+        else:
+           fmt = "[%14s] %s"
+        r = ""
+        newline = True
+        for entry in self.entries:
+          if newline:
+              r = r + fmt % (entry["time"], entry["msg"])
+          else:
+              r = r + "%s" % (entry["msg"])
+
+          try:
+              if entry["msg"][-1] == '\n':
+                  newline = True
+              else:
+                  newline = False
+          except:
+              pass
+
+        return r
+
+class DumpDebugLogApp:
+    """Dumps Configuration Table based Debug Logs."""
+
+    def __init__(self):
+        self.parse_options()
+
+        for source in self.args.source:
+            log = open(source, mode='rb').read()
+            print(DebugLog(log))
+
+    def parse_options(self):
+        parser = argparse.ArgumentParser(description=__copyright__)
+        parser.add_argument('--version', action='version',
+                            version='%(prog)s ' + VersionNumber)
+        parser.add_argument('source', nargs='+',
+                            help='[Debug Log Configuration Table]')
+        self.args = parser.parse_args()
+
+if __name__ == "__main__":
+    DumpDebugLogApp()
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 10/12] BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (8 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 09/12] Scripts: Add bootlog decyphering script Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 11/12] BaseDebugLibSerialPort: Emit messages to boot log Alexander Graf
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

In the next commit, we will make BaseDebugLibSerialPort call
DebugBootlogLib to emit log lines. Make sure that every dsc that links
against BaseDebugLibSerialPort also links against a DebugBootlogLib.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 ArmVirtPkg/ArmVirt.dsc.inc                  |  5 +++++
 EmulatorPkg/EmulatorPkg.dsc                 |  3 +++
 IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc     |  1 +
 OvmfPkg/AmdSev/AmdSevX64.dsc                | 10 ++++++++++
 OvmfPkg/Bhyve/BhyveX64.dsc                  | 10 ++++++++++
 OvmfPkg/CloudHv/CloudHvX64.dsc              | 10 ++++++++++
 OvmfPkg/IntelTdx/IntelTdxX64.dsc            |  8 ++++++++
 OvmfPkg/Microvm/MicrovmX64.dsc              | 10 ++++++++++
 OvmfPkg/OvmfPkgIa32.dsc                     | 10 ++++++++++
 OvmfPkg/OvmfPkgIa32X64.dsc                  | 10 ++++++++++
 OvmfPkg/OvmfPkgX64.dsc                      |  7 +++++++
 SourceLevelDebugPkg/SourceLevelDebugPkg.dsc |  1 +
 UefiPayloadPkg/UefiPayloadPkg.dsc           |  1 +
 13 files changed, 86 insertions(+)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index f15a3f7f06..c63c441ff4 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -40,6 +40,7 @@
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
 !endif
   DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
 
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
@@ -184,6 +185,7 @@
   ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf
 
 [LibraryClasses.common.SEC]
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
 
@@ -195,6 +197,7 @@
   MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
 
 [LibraryClasses.common.PEI_CORE]
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -210,6 +213,7 @@
   SerialPortLib|ArmVirtPkg/Library/FdtPL011SerialPortLib/EarlyFdtPL011SerialPortLib.inf
 
 [LibraryClasses.common.PEIM]
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
   HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
@@ -247,6 +251,7 @@
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
 
 [LibraryClasses.common.DXE_RUNTIME_DRIVER]
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
   MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
 !if $(TARGET) != RELEASE
diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 4cf886b9ea..b898622625 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -147,6 +147,7 @@
   SerialPortLib|EmulatorPkg/Library/PeiEmuSerialPortLib/PeiEmuSerialPortLib.inf
   PpiListLib|EmulatorPkg/Library/SecPpiListLib/SecPpiListLib.inf
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   TimerLib|EmulatorPkg/Library/PeiTimerLib/PeiTimerLib.inf
 
 [LibraryClasses.common.USER_DEFINED, LibraryClasses.common.BASE]
@@ -337,6 +338,7 @@
   MdeModulePkg/Core/Dxe/DxeMain.inf {
     <LibraryClasses>
       DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+      DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
       SerialPortLib|EmulatorPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf
       DxeEmuLib|EmulatorPkg/Library/DxeEmuLib/DxeEmuLib.inf
       NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
@@ -351,6 +353,7 @@
   MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.inf {
    <LibraryClasses>
       DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+      DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
       SerialPortLib|EmulatorPkg/Library/DxeEmuStdErrSerialPortLib/DxeEmuStdErrSerialPortLib.inf
   }
 
diff --git a/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc b/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc
index 961576c9a7..db083f8dfb 100644
--- a/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc
+++ b/IntelFsp2Pkg/Tools/Tests/QemuFspPkg.dsc
@@ -110,6 +110,7 @@
   UefiCpuLib|UefiCpuPkg/Library/BaseUefiCpuLib/BaseUefiCpuLib.inf
 !if $(TARGET) == DEBUG
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
 !else
   DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index bead9722ea..7bf37460e5 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -221,6 +221,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -252,6 +253,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -268,6 +270,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -296,6 +299,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -316,6 +320,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -335,6 +340,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -351,6 +357,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibGrub/PlatformBootManagerLibGrub.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -378,6 +385,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -395,6 +403,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -417,6 +426,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index f0166e136c..0cf9e3a3ef 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -238,6 +238,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -264,6 +265,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -280,6 +282,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -301,6 +304,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -319,6 +323,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -335,6 +340,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -349,6 +355,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLibBhyve/PlatformBootManagerLibBhyve.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
@@ -370,6 +377,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -385,6 +393,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -405,6 +414,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc
index 92664f319b..75b3d06dab 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -249,6 +249,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -280,6 +281,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -296,6 +298,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -323,6 +326,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -343,6 +347,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -364,6 +369,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -380,6 +386,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -411,6 +418,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -428,6 +436,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -451,6 +460,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
index 00bc1255bc..74e2c07da1 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -216,6 +216,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
   PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLibIdt/PeiServicesTablePointerLibIdt.inf
@@ -242,6 +243,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
   PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
@@ -259,6 +261,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -278,6 +281,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -294,6 +298,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -316,6 +321,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -333,6 +339,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -352,6 +359,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index f8fc977cb2..52a94a1058 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -244,6 +244,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -275,6 +276,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -291,6 +293,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -316,6 +319,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -335,6 +339,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -353,6 +358,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -368,6 +374,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -392,6 +399,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -408,6 +416,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -429,6 +438,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index c16a840fff..b16102e53f 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -246,6 +246,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -276,6 +277,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -292,6 +294,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -319,6 +322,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -339,6 +343,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -361,6 +366,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -377,6 +383,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -408,6 +415,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -425,6 +433,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -448,6 +457,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index d3a80cb568..2e9f837ba0 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -252,6 +252,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -282,6 +283,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -298,6 +300,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -325,6 +328,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf
@@ -345,6 +349,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -367,6 +372,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
@@ -383,6 +389,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PlatformBootManagerLib|OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf
   QemuBootOrderLib|OvmfPkg/Library/QemuBootOrderLib/QemuBootOrderLib.inf
@@ -414,6 +421,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 [LibraryClasses.common.DXE_SMM_DRIVER]
@@ -431,6 +439,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -454,6 +463,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index c01355e5c7..563051f0c8 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -257,6 +257,7 @@
   VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf
   TdxLib|MdePkg/Library/TdxLib/TdxLib.inf
   TdxMailboxLib|OvmfPkg/Library/TdxMailboxLib/TdxMailboxLib.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLib.inf
 
 [LibraryClasses.common.SEC]
   TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf
@@ -266,6 +267,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/BaseExtractGuidedSectionLib/BaseExtractGuidedSectionLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
@@ -297,6 +299,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
 
 [LibraryClasses.common.PEIM]
@@ -313,6 +316,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogLibPei.inf
   PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
   ResourcePublicationLib|MdePkg/Library/PeiResourcePublicationLib/PeiResourcePublicationLib.inf
   ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
@@ -360,6 +364,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
@@ -446,6 +451,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
 !if $(SOURCE_DEBUG_ENABLE) == TRUE
   DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgentLib.inf
@@ -469,6 +475,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
 
 ################################################################################
diff --git a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc b/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
index eba64a7b78..2b0ea301a1 100644
--- a/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
+++ b/SourceLevelDebugPkg/SourceLevelDebugPkg.dsc
@@ -27,6 +27,7 @@
 
 [LibraryClasses.common]
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
   DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
   BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
   BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 4d9bbc80c8..311ad2d58d 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -281,6 +281,7 @@
   PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
   DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull.inf
   DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
 
 [LibraryClasses.common.DXE_CORE]
   DxeHobListLib|UefiPayloadPkg/Library/DxeHobListLibNull/DxeHobListLibNull.inf
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 11/12] BaseDebugLibSerialPort: Emit messages to boot log
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (9 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 10/12] BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-05-27  2:43 ` [PATCH 12/12] OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support Alexander Graf
  2022-06-01  9:33 ` [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output Gerd Hoffmann
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

Now that we have the bootlog infrastructure in place and link against it
with all in tree consumers of BaseDebugLibSerialPort, let's emit log lines
to the bootlog in addition to serial.

The existing PcdDebugBootlogErrorLevel still defines which messages end up
on serial. However, in addition the new PcdDebugBootlogErrorLevel defines
which ones go into the bootlog. The latter may be more verbose.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../BaseDebugLibSerialPort.inf                |  1 +
 .../Library/BaseDebugLibSerialPort/DebugLib.c | 22 +++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf b/MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
index 7504faee67..dd22fbeb4a 100644
--- a/MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+++ b/MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
@@ -36,6 +36,7 @@
   PrintLib
   BaseLib
   DebugPrintErrorLevelLib
+  DebugBootlogLib
 
 [Pcd]
   gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue  ## SOMETIMES_CONSUMES
diff --git a/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c b/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
index bd56869477..ea2611228d 100644
--- a/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
+++ b/MdePkg/Library/BaseDebugLibSerialPort/DebugLib.c
@@ -20,6 +20,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/SerialPortLib.h>
 #include <Library/DebugPrintErrorLevelLib.h>
+#include <Library/DebugBootlog.h>
 
 //
 // Define the maximum debug and assert message length that this library supports
@@ -103,16 +104,20 @@ DebugPrintMarker (
   )
 {
   CHAR8  Buffer[MAX_DEBUG_MESSAGE_LENGTH];
+  UINT32 DebugPrintLevel, DebugBootlogLevel, Length;
 
   //
   // If Format is NULL, then ASSERT().
   //
   ASSERT (Format != NULL);
 
+  DebugPrintLevel = GetDebugPrintErrorLevel ();
+  DebugBootlogLevel = GetDebugBootlogErrorLevel ();
+
   //
   // Check driver debug mask value and global mask
   //
-  if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
+  if ((ErrorLevel & (DebugPrintLevel | DebugBootlogLevel)) == 0) {
     return;
   }
 
@@ -120,15 +125,24 @@ DebugPrintMarker (
   // Convert the DEBUG() message to an ASCII String
   //
   if (BaseListMarker == NULL) {
-    AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
+    Length = AsciiVSPrint (Buffer, sizeof (Buffer), Format, VaListMarker);
   } else {
-    AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
+    Length = AsciiBSPrint (Buffer, sizeof (Buffer), Format, BaseListMarker);
   }
 
   //
   // Send the print string to a Serial Port
   //
-  SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer));
+  if (ErrorLevel & DebugPrintLevel) {
+    SerialPortWrite ((UINT8 *)Buffer, Length);
+  }
+
+  //
+  // Append the print string to the Boot Log
+  //
+  if (ErrorLevel & DebugBootlogLevel) {
+    DebugBootlogAppend (Buffer, Length, ErrorLevel);
+  }
 }
 
 /**
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 12/12] OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (10 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 11/12] BaseDebugLibSerialPort: Emit messages to boot log Alexander Graf
@ 2022-05-27  2:43 ` Alexander Graf
  2022-06-01  9:33 ` [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output Gerd Hoffmann
  12 siblings, 0 replies; 16+ messages in thread
From: Alexander Graf @ 2022-05-27  2:43 UTC (permalink / raw)
  To: devel; +Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

Now that we have Bootlog support for serial, let's also add it for the PV
Debug Port. The only new platform we touch with this is Xen, where we just
disable bootlogs for now.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 .../Library/PlatformDebugLibIoPort/DebugLib.c | 23 +++++++++++++++----
 .../PlatformDebugLibIoPort.inf                |  1 +
 .../PlatformRomDebugLibIoPort.inf             |  1 +
 .../PlatformRomDebugLibIoPortNocheck.inf      |  1 +
 OvmfPkg/OvmfXen.dsc                           |  1 +
 5 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
index 4e25f198aa..80eb3cce0f 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
@@ -15,6 +15,7 @@
 #include <Library/PrintLib.h>
 #include <Library/PcdLib.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/DebugBootlog.h>
 #include <Library/DebugPrintErrorLevelLib.h>
 #include "DebugLibDetect.h"
 
@@ -86,17 +87,20 @@ DebugPrintMarker (
 {
   CHAR8  Buffer[MAX_DEBUG_MESSAGE_LENGTH];
   UINTN  Length;
+  UINT32 DebugPrintLevel, DebugBootlogLevel;
 
   //
   // If Format is NULL, then ASSERT().
   //
   ASSERT (Format != NULL);
 
+  DebugPrintLevel = GetDebugPrintErrorLevel ();
+  DebugBootlogLevel = GetDebugBootlogErrorLevel ();
+
   //
-  // Check if the global mask disables this message or the device is inactive
+  // Check if the global mask disables this message
   //
-  if (((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) ||
-      !PlatformDebugLibIoPortFound ())
+  if ((ErrorLevel & (DebugPrintLevel | DebugBootlogLevel)) == 0)
   {
     return;
   }
@@ -111,9 +115,18 @@ DebugPrintMarker (
   }
 
   //
-  // Send the print string to the debug I/O port
+  // Send the print string to the debug I/O port if it is active
   //
-  IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);
+  if (PlatformDebugLibIoPortFound () && (ErrorLevel & DebugPrintLevel)) {
+    IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);
+  }
+
+  //
+  // Append the print string to the Boot Log
+  //
+  if (ErrorLevel & DebugBootlogLevel) {
+    DebugBootlogAppend (Buffer, Length, ErrorLevel);
+  }
 }
 
 /**
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
index 94ab910507..4a121a3b7b 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
@@ -40,6 +40,7 @@
   PrintLib
   BaseLib
   DebugPrintErrorLevelLib
+  DebugBootlogLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort                ## CONSUMES
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
index 8f721d249d..ba2052f81d 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPort.inf
@@ -40,6 +40,7 @@
   PrintLib
   BaseLib
   DebugPrintErrorLevelLib
+  DebugBootlogLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort                ## CONSUMES
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPortNocheck.inf b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPortNocheck.inf
index 6a85b333ee..75cdfafd22 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPortNocheck.inf
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/PlatformRomDebugLibIoPortNocheck.inf
@@ -39,6 +39,7 @@
   PrintLib
   BaseLib
   DebugPrintErrorLevelLib
+  DebugBootlogLib
 
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdDebugIoPort                ## CONSUMES
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 6ba4bd729a..6f66d49855 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -226,6 +226,7 @@
 !else
   DebugLib|OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf
 !endif
+  DebugBootlogLib|MdePkg/Library/BaseDebugBootlog/BaseDebugBootlogNullLib.inf
 
 [LibraryClasses.common]
   BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
-- 
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




^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output
  2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
                   ` (11 preceding siblings ...)
  2022-05-27  2:43 ` [PATCH 12/12] OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support Alexander Graf
@ 2022-06-01  9:33 ` Gerd Hoffmann
  2022-06-01 16:58   ` Benjamin Doron
  12 siblings, 1 reply; 16+ messages in thread
From: Gerd Hoffmann @ 2022-06-01  9:33 UTC (permalink / raw)
  To: devel, graf
  Cc: Ard Biesheuvel, Leif Lindholm, Dandan Bi, Zhichao Gao, Liming Gao

On Fri, May 27, 2022 at 04:43:05AM +0200, Alexander Graf via groups.io wrote:
> I recently looked at improving the bootup performance of virtual machines
> and was amazed by the fact that there is no logging / tracing framework
> available that would give me a full picture of the Pre-OS phase including
> time stamps and boot loaders (such as grub) without writing data to the
> serial port - which taints all measurements.

Hmm.  Maybe it's time to tackle the log performance problem for virtual
machines?  Create a debug log device with DMA support, so we don't need
a vmexit for every single character we want log?

That will not completely kill the boot slowdown / measurement tainting
problem, but it should be an order of magnitude smaller.

Advantages:  We can leave the time stamp collection to the host, avoiding
issues like not knowing the tsc frequency in early firmware code.  You
can read the log even in case the guest doesn't boot up successfully.

>   3) Extensability to other payloads - The FPDT infrastructure considers
>      everything as owned by PerformanceLib. I would like to create a one
>      stop place for arbitrary UEFI applications to also put performance
>      measurement data.

How does that relate to coreboot?  coreboot has logging-to-memory too.
Not sure what the state is, there have been discussions on the coreboot
list about changing that from a pure text log to something structed with
timestamps a while back.  Don't know whenever this did actually happen.

So, when adding logging-to-memory to edk2 it surely make sense to
coordinate that with coreboot, so we'll have both coreboot and edk2 logs
there in case edk2 runs as coreboot payload.

take care,
  Gerd


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output
  2022-06-01  9:33 ` [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output Gerd Hoffmann
@ 2022-06-01 16:58   ` Benjamin Doron
  2022-06-02  8:35     ` Gerd Hoffmann
  0 siblings, 1 reply; 16+ messages in thread
From: Benjamin Doron @ 2022-06-01 16:58 UTC (permalink / raw)
  To: Gerd Hoffmann, devel

[-- Attachment #1: Type: text/plain, Size: 1928 bytes --]

On Wed, Jun 1, 2022 at 05:33 AM, Gerd Hoffmann wrote:

> 
> Hmm. Maybe it's time to tackle the log performance problem for virtual
> machines? Create a debug log device with DMA support, so we don't need
> a vmexit for every single character we want log?

Of course, that doesn't work for native systems. I don't know how other developers perform debugging (possibly via a serial port), but I developed a library stack similar to this one to help me with GSoC last year ( https://github.com/benjamindoron/edk2/commit/db888a928c1c6fc94f6a7670f3402718c10c01d2 ). It's WIP, modelled after the simple coreboot ringbuffer and is missing tracing facilities.

Regardless, having a true complement to PcdStatusCodeUseSerial would often be helpful, I suspect (presently, PcdStatusCodeUseMemory only logs the PI status code for the debug messages).

> 
> How does that relate to coreboot? coreboot has logging-to-memory too.
> Not sure what the state is, there have been discussions on the coreboot
> list about changing that from a pure text log to something structed with
> timestamps a while back. Don't know whenever this did actually happen.
> 
> So, when adding logging-to-memory to edk2 it surely make sense to
> coordinate that with coreboot, so we'll have both coreboot and edk2 logs
> there in case edk2 runs as coreboot payload.

I'm working on getting a SerialPortLib that logs to CBMEM merged. It's on the list at the moment.

Some comments on DebugLibBootlog:
- It's possible to support ASSERTs. If PcdDebugPropertyMask & 0x31 == 0x01, then non-fatal ASSERTs are logged. As a DebugLib, this would require handling in `DebugAssert()`.
- SMM-phase logging can be implemented, but I'm not convinced that sharing DXE's buffer is entirely safe. Using SMM communicate could be safer, but would be more complicated. I stopped working on it when the return-on-investment was too low.

Regards,
Benjamin

[-- Attachment #2: Type: text/html, Size: 2157 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output
  2022-06-01 16:58   ` Benjamin Doron
@ 2022-06-02  8:35     ` Gerd Hoffmann
  0 siblings, 0 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2022-06-02  8:35 UTC (permalink / raw)
  To: Benjamin Doron; +Cc: devel

  Hi,

> > Hmm. Maybe it's time to tackle the log performance problem for virtual
> > machines? Create a debug log device with DMA support, so we don't need
> > a vmexit for every single character we want log?
> 
> Of course, that doesn't work for native systems.

Yep.  Maybe we should have both ;)

> > How does that relate to coreboot? coreboot has logging-to-memory too.
> > Not sure what the state is, there have been discussions on the coreboot
> > list about changing that from a pure text log to something structed with
> > timestamps a while back. Don't know whenever this did actually happen.
> > 
> > So, when adding logging-to-memory to edk2 it surely make sense to
> > coordinate that with coreboot, so we'll have both coreboot and edk2 logs
> > there in case edk2 runs as coreboot payload.
> 
> I'm working on getting a SerialPortLib that logs to CBMEM merged. It's on the list at the moment.

> Some comments on DebugLibBootlog:

> - SMM-phase logging can be implemented, but I'm not convinced that sharing DXE's buffer is entirely safe. Using SMM communicate could be safer, but would be more complicated. I stopped working on it when the return-on-investment was too low.

DebugLibBootlog supports multiple buffers.  So we could have one for
coreboot, one for edk2 pei/dxe, one for edk2 smm, one for shim, one for
grub, ...

take care,
  Gerd


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-06-02  8:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
2022-05-27  2:43 ` [PATCH 01/12] MdePkg: Add DebugBootlog header Alexander Graf
2022-05-27  2:43 ` [PATCH 02/12] MdePkg: Add Null BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 03/12] MdePkg: Add Fallback timer support for BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 04/12] MdePkg: Add X86 " Alexander Graf
2022-05-27  2:43 ` [PATCH 05/12] MdePkg: Add ARM " Alexander Graf
2022-05-27  2:43 ` [PATCH 06/12] MdePkg: Add Pei phase BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 07/12] MdePkg: Add Dxe " Alexander Graf
2022-05-27  2:43 ` [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 09/12] Scripts: Add bootlog decyphering script Alexander Graf
2022-05-27  2:43 ` [PATCH 10/12] BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs Alexander Graf
2022-05-27  2:43 ` [PATCH 11/12] BaseDebugLibSerialPort: Emit messages to boot log Alexander Graf
2022-05-27  2:43 ` [PATCH 12/12] OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support Alexander Graf
2022-06-01  9:33 ` [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output Gerd Hoffmann
2022-06-01 16:58   ` Benjamin Doron
2022-06-02  8:35     ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox