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