From 9b8db95a0506bb0301f43fc7f4d494f88c09b66b Mon Sep 17 00:00:00 2001 From: Taylor Beebe <31827475+TaylorBeebe@users.noreply.github.com> Date: Tue, 27 Feb 2024 11:37:39 -0800 Subject: [PATCH] Enable Pre-DXE Logs for Platforms Which Can't use Pre-DXE AdvancedLoggerLib Instances (#440) ## Description Create a new guid and HOB entry definition for specifying a pre-DXE log buffer on platforms which can't use a pre-DXE AdvancedLoggerLib instance. After the advanced logger info buffer is created, the DxeCore AdvancedLoggerLib constructor will search for the guided HOB and, if found, write the contents of the buffer specified by the entry to the advanced logger buffer. - [x] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Tested by creating the HOB and verifying that the DxeCore constructor located it. ## Integration Instructions N/A --- AdvLoggerPkg/AdvLoggerPkg.dec | 7 ++++ .../Include/Guid/AdvancedLoggerPreDxeLogs.h | 33 +++++++++++++++++++ .../AdvancedLoggerLib/AdvancedLoggerCommon.c | 1 - .../AdvancedLoggerLib/AdvancedLoggerCommon.h | 20 +++++++++++ .../DxeCore/AdvancedLoggerLib.c | 31 ++++++++++++----- .../DxeCore/AdvancedLoggerLib.inf | 1 + 6 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 AdvLoggerPkg/Include/Guid/AdvancedLoggerPreDxeLogs.h diff --git a/AdvLoggerPkg/AdvLoggerPkg.dec b/AdvLoggerPkg/AdvLoggerPkg.dec index d1841dc4ae..ffa1395255 100644 --- a/AdvLoggerPkg/AdvLoggerPkg.dec +++ b/AdvLoggerPkg/AdvLoggerPkg.dec @@ -50,6 +50,13 @@ # gAdvancedFileLoggerPolicyGuid = { 0x6c3fd4f1, 0xb596, 0x438e, { 0x8a, 0xb8, 0x53, 0xf1, 0xc, 0x9c, 0x27, 0x74 } } + ## GUID for specifying Advanced logger pre-DXE logs + # Platforms which don't use a Pre-DXE AdvancedLoggerLib instance but still produce logging + # can use this GUID to publish the location of the logs so they can be written to the advanced + # logger buffer created in early DXE. + # + gAdvancedLoggerPreDxeLogsGuid = { 0x751fc006, 0x5804, 0x440d, { 0x8b, 0x15, 0x61, 0x8c, 0xf6, 0x56, 0xae, 0x76 } } + [Ppis] ## Advanced Logger Ppi - Communication from PEIM to PEI_CORE library implementation # diff --git a/AdvLoggerPkg/Include/Guid/AdvancedLoggerPreDxeLogs.h b/AdvLoggerPkg/Include/Guid/AdvancedLoggerPreDxeLogs.h new file mode 100644 index 0000000000..f5ea406b8f --- /dev/null +++ b/AdvLoggerPkg/Include/Guid/AdvancedLoggerPreDxeLogs.h @@ -0,0 +1,33 @@ +/** @file + This file defines GUIDs and data structure for producing HOB entry describing + the location of pre-DXE logs. For platforms which use a Pre-DXE AdvancedLoggerLib + implementation, this HOB is not necessary. + + Copyright (C) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef ADVANCED_LOGGER_PRE_DXE_LOGS_H_ +#define ADVANCED_LOGGER_PRE_DXE_LOGS_H_ + +#pragma pack(1) +// The region specified by this HOB entry should contain raw log output. +// The Advanced Logger library will serialize the contents of the buffer +// when adding it to the advanced logger output. +typedef struct _ADVANCED_LOGGER_PRE_DXE_LOGS_HOB { + UINT32 Signature; + UINT64 BaseAddress; + UINT64 LengthInBytes; +} ADVANCED_LOGGER_PRE_DXE_LOGS_HOB; +#pragma pack() + +#define ADVANCED_LOGGER_PRE_DXE_LOGS_GUID \ +{ \ + 0x751fc006, 0x5804, 0x440d, { 0x8b, 0x15, 0x61, 0x8c, 0xf6, 0x56, 0xae, 0x76 } \ +} + +extern EFI_GUID gAdvancedLoggerPreDxeLogsGuid; + +#define ADVANCED_LOGGER_PRE_DXE_LOGS_SIGNATURE SIGNATURE_32 ('A', 'L', 'P', 'D') + +#endif diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.c b/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.c index fee60ecf38..9ad61d241c 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.c +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.c @@ -31,7 +31,6 @@ @retval LoggerInfo Returns the logger info block. Returns NULL if it cannot be located. This occurs prior to SEC completion. **/ -STATIC ADVANCED_LOGGER_INFO * EFIAPI AdvancedLoggerMemoryLoggerWrite ( diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.h b/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.h index 49f9e5939f..fdc21b2d28 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.h +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/AdvancedLoggerCommon.h @@ -58,4 +58,24 @@ AdvancedLoggerGetPhase ( VOID ); +/** + Write data from buffer into the in memory logging buffer. + + Writes NumberOfBytes data bytes from Buffer to the logging buffer. + + @param DebugLevel Debug level of the message + @param Buffer Pointer to the data buffer to be written. + @param NumberOfBytes Number of bytes to be written to the Advanced Logger log. + + @retval LoggerInfo Returns the logger info block. Returns NULL if it cannot + be located. This occurs prior to SEC completion. +**/ +ADVANCED_LOGGER_INFO * +EFIAPI +AdvancedLoggerMemoryLoggerWrite ( + IN UINTN DebugLevel, + IN CONST CHAR8 *Buffer, + IN UINTN NumberOfBytes + ); + #endif // __ADVANCED_LOGGER_COMMON_H__ diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.c b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.c index f85f5edb96..950ea8b77f 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.c +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -365,8 +366,10 @@ DxeCoreAdvancedLoggerLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - ADVANCED_LOGGER_INFO *LoggerInfo; - EFI_STATUS Status; + ADVANCED_LOGGER_INFO *LoggerInfo; + EFI_STATUS Status; + ADVANCED_LOGGER_PRE_DXE_LOGS_HOB *PreDxeLogs; + EFI_HOB_GUID_TYPE *PreDxeLogsHobEntry; LoggerInfo = AdvancedLoggerGetLoggerInfo (); // Sets mLoggerInfo if Logger Information block found in HOB. @@ -400,12 +403,24 @@ DxeCoreAdvancedLoggerLibConstructor ( if (LoggerInfo != NULL) { mAdvLoggerProtocol.LoggerInfo = LoggerInfo; mLoggerInfo->TimerFrequency = GetPerformanceCounterProperties (NULL, NULL); - Status = SystemTable->BootServices->InstallProtocolInterface ( - &ImageHandle, - &gAdvancedLoggerProtocolGuid, - EFI_NATIVE_INTERFACE, - &mAdvLoggerProtocol.AdvLoggerProtocol - ); + + PreDxeLogsHobEntry = GetFirstGuidHob (&gAdvancedLoggerPreDxeLogsGuid); + + if (PreDxeLogsHobEntry != NULL) { + PreDxeLogs = (ADVANCED_LOGGER_PRE_DXE_LOGS_HOB *)GET_GUID_HOB_DATA (PreDxeLogsHobEntry); + if (PreDxeLogs->Signature != ADVANCED_LOGGER_PRE_DXE_LOGS_SIGNATURE) { + ASSERT (PreDxeLogs->Signature == ADVANCED_LOGGER_PRE_DXE_LOGS_SIGNATURE); + } else { + AdvancedLoggerMemoryLoggerWrite (DEBUG_INFO, (CONST CHAR8 *)(UINTN)PreDxeLogs->BaseAddress, PreDxeLogs->LengthInBytes); + } + } + + Status = SystemTable->BootServices->InstallProtocolInterface ( + &ImageHandle, + &gAdvancedLoggerProtocolGuid, + EFI_NATIVE_INTERFACE, + &mAdvLoggerProtocol.AdvLoggerProtocol + ); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "%a: Error installing protocol - %r\n", __FUNCTION__, Status)); diff --git a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.inf b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.inf index 9341e96ec0..69c7c00708 100644 --- a/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.inf +++ b/AdvLoggerPkg/Library/AdvancedLoggerLib/DxeCore/AdvancedLoggerLib.inf @@ -46,6 +46,7 @@ [Guids] gAdvancedLoggerHobGuid gEfiEndOfDxeEventGroupGuid + gAdvancedLoggerPreDxeLogsGuid [Protocols] gAdvancedLoggerProtocolGuid ## PRODUCES