From nobody Tue Feb 10 19:14:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+90073+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90073+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1653619435; cv=none; d=zohomail.com; s=zohoarc; b=ZLTgwYp0pEJbBAArJhicGkyAg/awra5Bk5N00wW9wBDv4ubZG0Gpk6sNDaf+BbIXVg2pL4mhVqtA/My7Xzt9ktH+/YRDUjQgUCDX88G4QF0UYGqBepD6UtNkY2KreT89h3PHmMzVDR1wLFwDTDUtXhNM7c2xxern6lxUiRfmjb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653619435; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=lvsUggttQWZnm29fJUvQtnJyvZ8LsS5s6mFza2R/Ceg=; b=FV404ZgG7W3oC7RxHiLhktHGR2RAgtIgEVs29MPFBQObvWfeAMjBYJCXmjTUFOJyDtaQZSo8SVtaX+1uHexxtJViMoF7MKrU7C7CBXjoTvRPVPo1gRe02777eicQLHDmU/lYK91gut1xuz8v0Me0fYEqCqm9jkf/rjxrhKrlZxI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+90073+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1653619434988436.4549192370383; Thu, 26 May 2022 19:43:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PkzjYY1788612xQU1pY3sSIW; Thu, 26 May 2022 19:43:54 -0700 X-Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by mx.groups.io with SMTP id smtpd.web11.3218.1653619433155395947 for ; Thu, 26 May 2022 19:43:53 -0700 X-IronPort-AV: E=Sophos;i="5.91,254,1647302400"; d="scan'208";a="92377795" X-Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-90d70b14.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP; 27 May 2022 02:43:49 +0000 X-Received: from EX13MTAUWC002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1e-90d70b14.us-east-1.amazon.com (Postfix) with ESMTPS id DEA00C0919; Fri, 27 May 2022 02:43:46 +0000 (UTC) X-Received: from EX13D20UWC001.ant.amazon.com (10.43.162.244) by EX13MTAUWC002.ant.amazon.com (10.43.162.240) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Fri, 27 May 2022 02:43:46 +0000 X-Received: from u79c5a0a55de558.ant.amazon.com (10.43.161.125) by EX13D20UWC001.ant.amazon.com (10.43.162.244) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Fri, 27 May 2022 02:43:44 +0000 From: "Alexander Graf via groups.io" To: CC: Ard Biesheuvel , Leif Lindholm , Dandan Bi , Zhichao Gao , Liming Gao Subject: [edk2-devel] [PATCH 07/12] MdePkg: Add Dxe phase BaseDebugBootlog Date: Fri, 27 May 2022 04:43:12 +0200 Message-ID: <20220527024317.13476-8-graf@amazon.com> In-Reply-To: <20220527024317.13476-1-graf@amazon.com> References: <20220527024317.13476-1-graf@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.43.161.125] X-ClientProxiedBy: EX13D06UWC001.ant.amazon.com (10.43.162.91) To EX13D20UWC001.ant.amazon.com (10.43.162.244) Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,graf@amazon.com X-Gm-Message-State: T7A4SAHEVp1rHUiMxam4nZUUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1653619434; bh=imjCS8gG+5otkxXHQTDTtge5GhzRAI/UnHoeT6JjQGU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=JoE1mLujXbUCjZYLoesvntOih1Fgn/bQ/GbeppKqgkrosVMvT8MU72mBWV4rYIPzDrr S8fycg29wF3lYlMqVHqhd8BQ2vRpyMxNFKRh8cz8XamMrWOILXqkct50vcu/EwCc/YCLa FxvXOybXHJZ8YheVmEWcqUlwDHCNo/k9Fk0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1653619436670100035 Content-Type: text/plain; charset="utf-8" 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 --- .../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/MdeP= kg/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 avai= lable as +# Bootlog Configuration Table. +# +# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2012, Red Hat, Inc.
+# Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights = reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseDebugBootlog + FILE_GUID =3D DF934DA3-CD31-49FE-AF50-B3C87C79325C + MODULE_TYPE =3D DXE_CORE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D DebugBootlogLib|DXE_CORE DXE_DRIVER U= EFI_DRIVER UEFI_APPLICATION + CONSTRUCTOR =3D 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/Lib= rary/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 avail= able as + Bootlog Configuration Table. + + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2012, Red Hat, Inc.
+ Copyright (c) 2022, Amazon Development Center Germany GmbH.
+ 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 referen= ces +// 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 referenc= es + 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 =3D 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 =3D 0; Index < Table->NrLogs; Index++) { + if (Table->LogAddress[Index] =3D=3D (EFI_PHYSICAL_ADDRESS) OldBootlog)= { + Table->LogAddress[Index] =3D (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 =3D 0; Index < Table->NrLogs; Index++) { + Cur =3D (BOOTLOG_HEADER *)Table->LogAddress[Index]; + if (Cur->Signature =3D=3D SIG_BOOTLOG_HEADER && + CompareMem(Cur->Producer, BOOTLOG_PRODUCER, sizeof(Cur->Producer))= =3D=3D 0 && + Cur->ExtraHeaderType =3D=3D BOOTLOG_EXTRA_HEADER_EDK2) { + *Bootlog =3D 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 =3D Table; + UINTN Index; + + if (TableGuid =3D=3D NULL || Table =3D=3D NULL) { + return EFI_NOT_FOUND; + } + + SystemTable =3D mDebugST; + *_Table =3D NULL; + for (Index =3D 0; Index < SystemTable->NumberOfTableEntries; Index++) { + if (CompareGuid (TableGuid, &(SystemTable->ConfigurationTable[Index].V= endorGuid))) { + *_Table =3D 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 =3D sizeof(BOOTLOG_CONFIG_TABLE) + MAX_LOGS * sizeof(U= INT64); + + Status =3D BS->AllocatePool ( + EfiBootServicesData, + TableLength, + (VOID **)pTable + ); + if (Status !=3D EFI_SUCCESS) + return Status; + + ZeroMem (*pTable, TableLength); + (*pTable)->Signature =3D SIG_BOOTLOG_CONFIG_TABLE; + (*pTable)->MaxLogs =3D 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 =3D BS->AllocatePages ( + AllocateAnyPages, + EfiBootServicesData, + EFI_SIZE_TO_PAGES (Size), + (EFI_PHYSICAL_ADDRESS *)NewBootlog + ); + if (Status !=3D EFI_SUCCESS) + return Status; + + ZeroMem (*NewBootlog, Size); + + return Status; +} + +static +VOID +EFIAPI +BaseDebugLibBootlogInitialize ( + IN BOOTLOG_HEADER *Bootlog, + IN UINT64 Size + ) +{ + Bootlog->Signature =3D SIG_BOOTLOG_HEADER; + CopyMem(Bootlog->Producer, BOOTLOG_PRODUCER, sizeof(Bootlog->Producer)); + Bootlog->ExtraHeaderType =3D BOOTLOG_EXTRA_HEADER_EDK2; + Bootlog->ExtraHeaderSize =3D sizeof(Bootlog->ExtraHeader); + Bootlog->MsgExtraHeaderSize =3D sizeof(BOOTLOG_ENTRY_EDK2) - sizeof(BOOT= LOG_ENTRY); + Bootlog->LastByte =3D OFFSET_OF(BOOTLOG_HEADER, Data); + Bootlog->TicksPerSecond =3D BaseDebugLibBootlogTicksPerSecond(); + Bootlog->ExtraHeader.AllocatedSize =3D 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 =3D EFI_SUCCESS; + UINTN NewSize; + EFI_PEI_HOB_POINTERS Hob; + + if (!mDebugST || !mDebugST->BootServices) + return EFI_NOT_FOUND; + + BS =3D mDebugST->BootServices; + + if (!gBootlog) { + /* Allocate a new Bootlog Configuration Table if not present */ + if (FindConfigTable (&gBootlogConfigTableGuid, &Table) !=3D EFI_SUCCES= S) { + Status =3D AllocateTable (BS, &Table); + if (Status !=3D EFI_SUCCESS) { + return Status; + } + + Status =3D BS->InstallConfigurationTable ( + &gBootlogConfigTableGuid, + Table + ); + if (Status !=3D EFI_SUCCESS) { + return Status; + } + } + + /* Allocate a Bootlog structure if none is in the table */ + if (FindEdk2Bootlog (Table, &Bootlog) !=3D 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 =3D FindConfigTable (&gEfiHobListGuid, &Hob.Raw); + if (Status !=3D EFI_SUCCESS) { + return Status; + } + + Status =3D AllocateBootlog (BS, &Bootlog, BOOTLOG_MIN_SIZE); + if (Status !=3D EFI_SUCCESS) { + return Status; + } + BaseDebugLibBootlogInitialize(Bootlog, BOOTLOG_MIN_SIZE); + + if (Table->NrLogs >=3D Table->MaxLogs) { + return EFI_NOT_FOUND; + } + Table->LogAddress[Table->NrLogs++] =3D (EFI_PHYSICAL_ADDRESS) Bootlo= g; + + gBootlog =3D Bootlog; + + /* + * This is the first time we go from PEI -> DXE. Copy all PEI log en= tries + * into our full fledged boot log structure + */ + if (Status =3D=3D EFI_SUCCESS) { + while (!END_OF_HOB_LIST (Hob)) { + if (Hob.Header->HobType =3D=3D EFI_HOB_TYPE_GUID_EXTENSION && + CompareGuid (&gBootlogConfigTableGuid, &Hob.Guid->Name) && + GET_HOB_LENGTH (Hob) > sizeof (BOOTLOG_ENTRY_EDK2)) { + BOOTLOG_ENTRY_EDK2 *Entry =3D GET_GUID_HOB_DATA (Hob); + BaseDebugBootlogAppendInternal ( + Entry->Log.String, + AsciiStrLen (Entry->Log.String), + Entry->ErrorLevel, + Entry->Log.Ticks + ); + } + + Hob.Raw =3D GET_NEXT_HOB (Hob); + } + } + } + + gBootlog =3D Bootlog; + } else { + Bootlog =3D gBootlog; + } + + /* Resize if the new string would not fit */ + if ((Bootlog->LastByte + AppendDataLength) > Bootlog->ExtraHeader.Alloca= tedSize) { + NewSize =3D ALIGN_VALUE (Bootlog->LastByte + AppendDataLength + EFI_PA= GE_SIZE * 16, + EFI_PAGE_SIZE); + Status =3D AllocateBootlog (BS, &NewBootlog, NewSize); + if (Status !=3D EFI_SUCCESS) { + return Status; + } + + CopyMem (NewBootlog, Bootlog, Bootlog->LastByte); + NewBootlog->ExtraHeader.AllocatedSize =3D NewSize; + UpdateEdk2Bootlog (Table, Bootlog, NewBootlog); + BS->FreePages ((EFI_PHYSICAL_ADDRESS) Bootlog, + EFI_SIZE_TO_PAGES (Bootlog->ExtraHeader.AllocatedSize)); + Bootlog =3D gBootlog =3D NewBootlog; + } + + *pBootlog =3D 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)) != =3D EFI_SUCCESS) + return EFI_SUCCESS; + + Hdr.ErrorLevel =3D ErrorLevel; + Hdr.Log.Ticks =3D Ticks; + + CopyMem (((VOID *)Bootlog) + Bootlog->LastByte, &Hdr, sizeof(Hdr)); + Bootlog->LastByte +=3D sizeof(Hdr); + CopyMem (((VOID *)Bootlog) + Bootlog->LastByte, String, Length); + Bootlog->LastByte +=3D Length; + *((CHAR8 *)Bootlog + Bootlog->LastByte) =3D '\0'; + Bootlog->LastByte +=3D 1; + + return EFI_SUCCESS; +} + +RETURN_STATUS +EFIAPI +DebugBootlogAppend ( + IN CONST CHAR8 *String, + IN UINTN Length, + IN UINTN ErrorLevel + ) +{ + return BaseDebugBootlogAppendInternal(String, Length, ErrorLevel, + BaseDebugLibBootlogTicks ()); +} --=20 2.28.0.394.ge197136389 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#90073): https://edk2.groups.io/g/devel/message/90073 Mute This Topic: https://groups.io/mt/91368913/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-