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 <g...@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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90068): https://edk2.groups.io/g/devel/message/90068 Mute This Topic: https://groups.io/mt/91368907/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-