From patchwork Wed Jun 11 05:08:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ying-Chun Liu \(PaulLiu\)" X-Patchwork-Id: 895531 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp2608713wrb; Tue, 10 Jun 2025 22:09:17 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUdgqmwL3YSaz/U3rE+yHwCD5+/ciXjOl2g5ODZy0U8//6Jm5yG4ZInWsrqE1VPPAP6CD45+g==@linaro.org X-Google-Smtp-Source: AGHT+IHqvFoK+8kACBRWSpLvb/2edWczJuqwuz+TevZywnUrRaEyQuJnUKHoggCzl06dSkvny1mc X-Received: by 2002:a05:6402:51c6:b0:602:10b6:c982 with SMTP id 4fb4d7f45d1cf-6084e6b6a41mr1088158a12.12.1749618557712; Tue, 10 Jun 2025 22:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749618557; cv=none; d=google.com; s=arc-20240605; b=CiNppUgPq2kWjgSJfG11LffqRdJDZlSTw5Rzkyxbwz3DgT0Q5Rn4PLGd8G/ge0FJGs bQxWQjd1ET5l45KPrpZiRz4m3muNX7AoNm6X6zWH2jmxq6l7kxrrqGh2ZbhtcryqYhh+ ee70/UWImgY9jzGCVx8fBVT4xfuTYUbqT2xsXDMRhIQjpBRxnzAAz1Nl3lCOjS8jsbCu LAJvH0AvIXJzNGuJy6LqcTonKNwK1GS7bxFMXb0UWIq5EzQLLBPXk+CAbmz+GVb0Uzas SORhbbbOEIFKV1H0moU5JFB8IisTApqX2XmnB5Xof75UTHB3DCVW4ErHE+odtdvG75u5 Sopw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XDFBvNBvhhq4Swz/RoJ3jC4CBUwAvIhB3uqGG8fS/us=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=LkR+lhzqnj3V7mczRz+DghHqGknai0a/TFcS2j6heFklmF0eWJUL13lsRG+inBLC0q 7qHNRJrQke+5Mf1i7lyCpYPQ7LOvfxjdAbhtjn8CsGyeClJC8XZf6xYOFtr+jNcs+cNd sOjjhjhRrMdP3WhLXF3QnZ/qqbEPCxFbBbIWv5e9gii7kHYPtl+kPtswxoOkO4t6JBED fp6+fEROBOfFVdD+dN1xLq9w1bgQOED56zJuD24oQiPz5Xm1Zh0k9pN+hn4EVME8/NNV WWvZsennbEScwimPRhQrupL3k/Jc1IJfs9sqdgkYlLJIKRnUu9G0irVLpZ4bGa48Hv3R IZXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=mzjQHhB6; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-607783ac76esi9197127a12.497.2025.06.10.22.09.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:09:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=mzjQHhB6; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2935182B97; Wed, 11 Jun 2025 07:08:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="mzjQHhB6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AAEF380050; Wed, 11 Jun 2025 07:08:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4E52880050 for ; Wed, 11 Jun 2025 07:08:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-b1396171fb1so3257022a12.2 for ; Tue, 10 Jun 2025 22:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749618533; x=1750223333; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=XDFBvNBvhhq4Swz/RoJ3jC4CBUwAvIhB3uqGG8fS/us=; b=mzjQHhB6UsoTiaLSQRs/FTqvaqN24xwaNgJ5/0LqoNZ8KqPnixO/atxeI5w9pVo0Nn PUrn0+NA/4bSUvmTF0Z41WbWFSu7pfSltT4D6VmiYfPdAanPErh6nDEpQKNuRi/ua+Yo NqkP1LyC3SIkeMc3I6GRjooGDoFso0nzBscfYBuvrCx+8RTe96R/OOAofl56a2vtQpL+ 9OaywrzNOe1ABMEhh0sDGaUz0DHLyeEXQ4ns7qLn0wLSv+tqPonh1X6l2+2fhT1/HrEo 8v7q24MaE9i52Ua1BUn6b5NtKu1VPws6KKYOCAPRaKRLIP2IEP2J0KQV2vzTdLHCxI91 ZCcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749618533; x=1750223333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=XDFBvNBvhhq4Swz/RoJ3jC4CBUwAvIhB3uqGG8fS/us=; b=WWvNc/mC/ViDdv9Zce6WdaA8H8gc1U3s98YHArNsY8Fl4jN2iclW1eE/C08qekHIrW H0S69yS1qKSPVI716iAZ+1rE2z6+kty6haFylwuUUXSgUkm+EwQQstC9SaQuLkMrRN4X RpYUx5GmBcLIVqYQ6QsOQZtm3z+iR+yNNS4G34s5rulclPeecRptdi/8Ylfje3EXE4jL 6xaTdtFsz2VwdzMm0N5dW/dUqm1jxglzLI2B/L4/LES3u46fGVZJG6K/+VzsHHTWBV05 9oa7qF96AwYfRqoBeEnthGWl3zXluJx0nlW+CCewnzvdUxzKrJQi+QVeZ+vzJY1gAMHl b6aw== X-Gm-Message-State: AOJu0YyV6QgBjAdJgSjNcQuT+8r65mYsMUc9ygJPcT6DfYXIHMoXNKaP lW+3gUWszMI7HA0/uwxmP9IjBMEh8pQ/7kLygyDiME/pxJY7VH9i5jDJbWPEoBvc X-Gm-Gg: ASbGnct4SM0cQTMhAMrfED+qY69zuPliOzwfODIwiX+Jxp0ZGJ53eC+5SZtSqfVUTa8 Je7phRQSUpAUaai2psFuZUQMnhz/l9serRBfhvDoqmSyC0dJGNyHRgwbaLHFd6pYhiKnVPp+akU fllF3snaC6a9mNcoUxkAq2JguKXCj2OPepWger3v5W/hcjAv9w70BaeCheou1si0UIE9i1+hAYH h4PjjrS84KdbPANkAouQrQv0050AXV8LsEh6WYAZhCw08ylywiB/SIuCxHNDc7NM3Db4qAmSV0Y OHCGNmwaTLrMScBmtzwLtsGwNBwESfh0rdwmI9Q46uypHRj97mNoZ/vUvA== X-Received: by 2002:a17:90b:2b4b:b0:312:def0:e2dc with SMTP id 98e67ed59e1d1-313af0e431cmr3448659a91.7.1749618533240; Tue, 10 Jun 2025 22:08:53 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-236035069c3sm79338905ad.234.2025.06.10.22.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:08:52 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson , Simon Glass Subject: [PATCH v5 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug Date: Wed, 11 Jun 2025 13:08:40 +0800 Message-ID: <20250611050844.210384-2-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250611050844.210384-1-paulliu@debian.org> References: <20250611050844.210384-1-paulliu@debian.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: "Ying-Chun Liu (PaulLiu)" Add EFI_SYSTEM_TABLE_POINTER structure for remote debugger to locate the address of EFI_SYSTEM_TABLE. This feature is described in UEFI SPEC version 2.10. Section 18.4.2. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover the EFI system table. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Peter Robinson Cc: Simon Glass --- V2: add Kconfig options to turn on/off this feature. V3: make efi_initialize_system_table_pointer() do the job as described. V4: use efi_alloc_aligned_pages() for system_table_pointer. V5: move the code into a separate module. --- include/efi_api.h | 16 +++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 8 ++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_debug_support.c | 46 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++ 6 files changed, 81 insertions(+) create mode 100644 lib/efi_loader/efi_debug_support.c diff --git a/include/efi_api.h b/include/efi_api.h index eb61eafa028..6c4c1a0cc7b 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -259,6 +259,22 @@ struct efi_capsule_result_variable_header { efi_status_t capsule_status; } __packed; +/** + * struct efi_system_table_pointer - struct to store the pointer of system + * table. + * @signature: The signature of this struct. + * @efi_system_table_base: The physical address of System Table. + * @crc32: CRC32 checksum + * + * This struct is design for hardware debugger to search through memory to + * get the address of EFI System Table. + */ +struct efi_system_table_pointer { + u64 signature; + efi_physical_addr_t efi_system_table_base; + u32 crc32; +}; + struct efi_memory_range { efi_physical_addr_t address; u64 length; diff --git a/include/efi_loader.h b/include/efi_loader.h index 8f9f2bcf1cb..8f065244d8e 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -646,6 +646,8 @@ efi_status_t efi_tcg2_measure_dtb(void *dtb); efi_status_t efi_root_node_register(void); /* Called by bootefi to initialize runtime */ efi_status_t efi_initialize_system_table(void); +/* Called by bootefi to initialize debug */ +efi_status_t efi_initialize_system_table_pointer(void); /* efi_runtime_detach() - detach unimplemented runtime functions */ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 7f02a83e2a2..f9d75cbc3fd 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -71,6 +71,14 @@ config EFI_SECURE_BOOT config EFI_SIGNATURE_SUPPORT bool +config EFI_DEBUG_SUPPORT + bool "EFI Debug Support" + help + Select this option if you want to setup the EFI Debug Support + Table and the EFI_SYSTEM_TABLE_POINTER which is used by the debug + agent or an external debugger to determine loaded image information + in a quiescent manner. + menu "UEFI services" config EFI_GET_TIME diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index cf050e5385d..51ccf1cd87e 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -70,6 +70,7 @@ obj-$(CONFIG_EFI_RISCV_BOOT_PROTOCOL) += efi_riscv.o obj-$(CONFIG_EFI_LOAD_FILE2_INITRD) += efi_load_initrd.o obj-$(CONFIG_EFI_SIGNATURE_SUPPORT) += efi_signature.o obj-$(CONFIG_EFI_ECPT) += efi_conformance.o +obj-$(CONFIG_EFI_DEBUG_SUPPORT) += efi_debug_support.o EFI_VAR_SEED_FILE := $(subst $\",,$(CONFIG_EFI_VAR_SEED_FILE)) $(obj)/efi_var_seed.o: $(srctree)/$(EFI_VAR_SEED_FILE) diff --git a/lib/efi_loader/efi_debug_support.c b/lib/efi_loader/efi_debug_support.c new file mode 100644 index 00000000000..a0f7506779d --- /dev/null +++ b/lib/efi_loader/efi_debug_support.c @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * EFI application boot time services + * + * Copyright (c) 2025 Ying-Chun Liu, Linaro Ltd. + */ + +#include +#include + +struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; + +/** + * efi_initialize_system_table_pointer() - Initialize system table pointer + * + * Return: status code + */ +efi_status_t efi_initialize_system_table_pointer(void) +{ + const int size_4MB = 0x00400000; + uintptr_t addr; + u32 crc32_value; + + /* Allocate configuration table array */ + addr = (uintptr_t)efi_alloc_aligned_pages(sizeof(struct efi_system_table_pointer), + EFI_RUNTIME_SERVICES_DATA, + size_4MB); + + if (!addr) { + log_err("Installing EFI system table pointer failed\n"); + return EFI_OUT_OF_RESOURCES; + } + + systab_pointer = (struct efi_system_table_pointer *)addr; + memset(systab_pointer, 0, sizeof(struct efi_system_table_pointer)); + + systab_pointer->signature = EFI_SYSTEM_TABLE_SIGNATURE; + systab_pointer->efi_system_table_base = (efi_physical_addr_t)&systab; + + crc32_value = crc32(0, + (const unsigned char *)systab_pointer, + sizeof(struct efi_system_table_pointer)); + systab_pointer->crc32 = crc32_value; + + return EFI_SUCCESS; +} diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 48f91da5df7..6193b9f6d0c 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -278,6 +278,14 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + /* Initialize system table pointer */ + if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) { + ret = efi_initialize_system_table_pointer(); + if (ret != EFI_SUCCESS) { + goto out; + } + } + if (IS_ENABLED(CONFIG_EFI_ECPT)) { ret = efi_ecpt_register(); if (ret != EFI_SUCCESS) From patchwork Wed Jun 11 05:08:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ying-Chun Liu \(PaulLiu\)" X-Patchwork-Id: 895532 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp2608739wrb; Tue, 10 Jun 2025 22:09:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWdRhcFrF9NRKXn9cQiBzfgrbbpH7J4NtnyaDF3Ht4X9y+3J+Ij9QLUV+BDisD8D6omHyT7ag==@linaro.org X-Google-Smtp-Source: AGHT+IHMVd45BHL1cIApYnFpNjpwtJQEgRPFWRyVzHtP+wigJCx9oV7XH+dLjCro8laIhB/+hK7V X-Received: by 2002:a17:907:1b02:b0:ade:865f:481 with SMTP id a640c23a62f3a-ade893d47b1mr185583766b.12.1749618565965; Tue, 10 Jun 2025 22:09:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749618565; cv=none; d=google.com; s=arc-20240605; b=hTDrMmborjw5I3xR5xr40jBNkcnnJSxWjUGAuLlOFK5bDjm5CpK9CuexzXDPOVOjPe 1DmVOjD8xi6Aq+7KWPtrhCWDUeTDxKrI16FXRwY3mBhy1Bet1MG2jf5XBWvaaM2hhCdC Zub1xThXubuqd9NVERBihWqzQZW0qbtM4n/Q147/uXZtMyMeMA5KUwQ1/KNC0zkInpmK e3WItveSWCevST8+ApTfozultFUr0alm4GbyGhhpdt9Ut9LtWe2qDX0+5Hq92omTHc3m jCe2P/aACg6m1jqVDsmW8lHqkuHJcRCAEAmaiZ6M+kVcYAkHsRs91CR0efIgpdDtrqIm OK5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sAnt5grOYAmtBrk+EO3Lf3szAFDblOZwt15E0G9G4T4=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=TjH5gm56R8W1yUpO11lMRb+0QNnXWnhU29mhi6qUZEgHGVmN6Lh9yj2fOAqPomA4Oq z+o4Pi9XfCrnmfGanwcG7WeXZoG45cOwIekU8QHpf+yg71F+EawTFe94Dk7tbAi/9NOT biuAtpoA2dJn92iZ6XV08PWugLaDbyA0ivZ+EeAloeIMPgRVUQl1Xsm/nt4gmhfZxw9z EWfNPN/9Spjnm2oxmGsHKt1OIwLd8TnDFKNGuXBGdbv94UzV0QntsadqKXpNDAXGx4RT CbNIAMh78egPzYnxnPowxqQ+qbdBDXdr7iOzKxQ+HZvCA0M2loPpHbGizbGoF4MlZonq 7h2A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=RfEeJz2t; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-ade1dc1a46fsi907209066b.335.2025.06.10.22.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:09:25 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=RfEeJz2t; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E809382BA7; Wed, 11 Jun 2025 07:09:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RfEeJz2t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5BF4F82B20; Wed, 11 Jun 2025 07:09:10 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 85AED82B95 for ; Wed, 11 Jun 2025 07:08:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-311a6236effso4655471a91.2 for ; Tue, 10 Jun 2025 22:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749618536; x=1750223336; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=sAnt5grOYAmtBrk+EO3Lf3szAFDblOZwt15E0G9G4T4=; b=RfEeJz2t/PwRhc9XdhjpazMpLaNNglIiknmH+exq4u04EYXhhWHWUTxBrEaOy/nHf+ Ls2JhcCIkRS4oi+ZfVmUynMW64pNVTHX1MsPEyt/lUOoMZKN8dYBD4hWLRHxlaljkEF5 jYcXMpLlEdbRrSAUa56GzTuFyyKcXT61JsLKo22cZbzvAaUR1zEt+XRfXe++SPCPXvag de4fdKidlC4kl3Sose9faOWA6n6Jx8dBnCGV9MScCu/OLclbwsx/9RqBmvN96cnuvRFR 2zpg8ldIQxrSTlwIlt5ss2exThQg/xovWnZUnY9wI4gU4zV9XFBwAfwMhoUWdqy9ve1L LJ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749618536; x=1750223336; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=sAnt5grOYAmtBrk+EO3Lf3szAFDblOZwt15E0G9G4T4=; b=lV2batNAOM4rYkVhtEMX8D3pCsuJJVzVCZGJvy2ht6ysOdKwC7zHIbUdHyNCkG+Buv uv29hat75fBBa0cG/MJ7T7+d3KyuSTGZP0ud0QRNg2dMyOyena/PbyvOM6DscIVngsZf wAhkMLoXBtt9qYIxkCMFLjCkVCxuoz1t074fNMYNRai7fb/K+7kNRr77wIwds/4+7Q+b V7sOw77AlRAIFtMsYqUPyvIjGEhJFGScCoUiUYbwlHZLeEOY91t+vyL5CdjXvLPK5Okc VCvWd+mI2pu/fg1YEdW0xJ7xIPz2J2E+9MV5nYvbvOUCrU9HWxfAUq+hC09qyimERHxX scog== X-Gm-Message-State: AOJu0YyRMY+koxpAU6KVrPUcQOW8Pmyehhg+FwMCKk37hVQeB7oYaW4W f9QY7qYr3ZgizlPOfN9Kv+m9mwqoNo2BdQuxKeKlFvJaxGUqwb9IDBmSefuCBIEp X-Gm-Gg: ASbGncsD5eL48bUfxiPsIY9nlEz/9NKozDkn2gZiAE4y3lrGDAjDleqC0urOZM9NHdo EPLkpCmg7xFFFUDfvNHwcuodJ18Wmtcnf5xQe/OV10FNGJGUdkREeyw/7pFrxnG27131GJZB7EL AT3XDe83xbFwNoC5qrlI51RM3VxuvvFI75aQJgh7eWlCKduPkV1xHwW+9/ccSk7Hf/jz+xxKwvU YyNc6GY/HJAsfkrXgSMpnMnqZ2qNcbYOnhGfZz74RaGTEK/Of3rP8neVjI6VdAeX6SzZq6pqN3b hUXnjIV2rXClYe6VIFdQkaSD4iaMPi6kxuMgG0hX1Bp+NqaqYL97tBm6dg== X-Received: by 2002:a17:90b:3c08:b0:311:b413:f5e1 with SMTP id 98e67ed59e1d1-313b20043camr1563653a91.32.1749618535590; Tue, 10 Jun 2025 22:08:55 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-313b201d843sm455288a91.23.2025.06.10.22.08.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:08:55 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson , Simon Glass Subject: [PATCH v5 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug Date: Wed, 11 Jun 2025 13:08:41 +0800 Message-ID: <20250611050844.210384-3-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250611050844.210384-1-paulliu@debian.org> References: <20250611050844.210384-1-paulliu@debian.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: "Ying-Chun Liu (PaulLiu)" EFI_DEBUG_IMAGE_INFO_TABLE is used to store EFI_LOADED_IMAGE for debug purpose. This commit adds the table to the EFI_CONFIGURATION_TABLE. This feature is described in UEFI Spec version 2.10. Section 18.4. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover and interact with system-level debug resources. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Peter Robinson Cc: Simon Glass --- V3: Fix the way of installation of configuration table. V5: move the code into a separate module. --- include/efi_api.h | 53 ++++++++++++++++++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_debug_support.c | 6 ++++ lib/efi_loader/efi_setup.c | 12 +++++++ 4 files changed, 73 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 6c4c1a0cc7b..8da0a350ce3 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -238,6 +238,10 @@ enum efi_reset_type { EFI_GUID(0xcce33c35, 0x74ac, 0x4087, 0xbc, 0xe7, \ 0x8b, 0x29, 0xb0, 0x2e, 0xeb, 0x27) +#define EFI_DEBUG_IMAGE_INFO_TABLE_GUID \ + EFI_GUID(0x49152e77, 0x1ada, 0x4764, 0xb7, 0xa2, \ + 0x7a, 0xfe, 0xfe, 0xd9, 0x5e, 0x8b) + struct efi_conformance_profiles_table { u16 version; u16 number_of_profiles; @@ -574,6 +578,55 @@ struct efi_loaded_image { efi_status_t (EFIAPI *unload)(efi_handle_t image_handle); }; +#define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01 +#define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED 0x02 + +/** + * struct efi_debug_image_info_normal - Store Debug Information for normal + * image. + * @image_info_type: the type of image info. + * @loaded_image_protocol_instance: the pointer to struct efi_loaded_image. + * @image_handle: the EFI handle of the image. + * + * This struct is created by efi_load_image() and store the information + * for debugging an normal image. + */ +struct efi_debug_image_info_normal { + u32 image_info_type; + struct efi_loaded_image *loaded_image_protocol_instance; + efi_handle_t image_handle; +}; + +/** + * union efi_debug_image_info - The union to store a pointer for EFI + * DEBUG IMAGE INFO. + * @image_info_type: the type of the image_info if it is not a normal image. + * @normal_image: The pointer to a normal image. + * + * This union is for a pointer that can point to the struct of normal_image. + * Or it points to an image_info_type. + */ +union efi_debug_image_info { + u32 *image_info_type; + struct efi_debug_image_info_normal *normal_image; +}; + +/** + * struct efi_debug_image_info_table_header - store the array of + * struct efi_debug_image_info. + * @update_status: Status to notify this struct is ready to use or not. + * @table_size: The number of elements of efi_debug_image_info_table. + * @efi_debug_image_info_table: The array of efi_debug_image_info. + * + * This struct stores the array of efi_debug_image_info. The + * number of elements is table_size. + */ +struct efi_debug_image_info_table_header { + volatile u32 update_status; + u32 table_size; + union efi_debug_image_info *efi_debug_image_info_table; +}; + #define EFI_DEVICE_PATH_PROTOCOL_GUID \ EFI_GUID(0x09576e91, 0x6d3f, 0x11d2, \ 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) diff --git a/include/efi_loader.h b/include/efi_loader.h index 8f065244d8e..d0c72d0bc58 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -315,6 +315,8 @@ extern const struct efi_hii_config_routing_protocol efi_hii_config_routing; extern const struct efi_hii_config_access_protocol efi_hii_config_access; extern const struct efi_hii_database_protocol efi_hii_database; extern const struct efi_hii_string_protocol efi_hii_string; +/* structure for EFI_DEBUG_SUPPORT_PROTOCOL */ +extern struct efi_debug_image_info_table_header efi_m_debug_info_table_header; uint16_t *efi_dp_str(struct efi_device_path *dp); diff --git a/lib/efi_loader/efi_debug_support.c b/lib/efi_loader/efi_debug_support.c index a0f7506779d..a6a672bc0e4 100644 --- a/lib/efi_loader/efi_debug_support.c +++ b/lib/efi_loader/efi_debug_support.c @@ -10,6 +10,12 @@ struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; +struct efi_debug_image_info_table_header efi_m_debug_info_table_header = { + 0, + 0, + NULL +}; + /** * efi_initialize_system_table_pointer() - Initialize system table pointer * diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 6193b9f6d0c..60f3a7e5fbf 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -18,6 +18,9 @@ efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; +const efi_guid_t efi_debug_image_info_table_guid = + EFI_DEBUG_IMAGE_INFO_TABLE_GUID; + /* * Allow unaligned memory access. * @@ -280,10 +283,19 @@ efi_status_t efi_init_obj_list(void) /* Initialize system table pointer */ if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) { + efi_guid_t debug_image_info_table_guid = + efi_debug_image_info_table_guid; + ret = efi_initialize_system_table_pointer(); if (ret != EFI_SUCCESS) { goto out; } + + ret = efi_install_configuration_table(&debug_image_info_table_guid, + &efi_m_debug_info_table_header); + if (ret != EFI_SUCCESS) { + goto out; + } } if (IS_ENABLED(CONFIG_EFI_ECPT)) { From patchwork Wed Jun 11 05:08:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ying-Chun Liu \(PaulLiu\)" X-Patchwork-Id: 895534 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp2608817wrb; Tue, 10 Jun 2025 22:09:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXOuKXaVOI7rMUzAn7DEzYXBCUeae9nWaUfm7C+zNyJkc4+p4H67yv6ezNBuOK2qMfzh7WEIA==@linaro.org X-Google-Smtp-Source: AGHT+IEiimKNTBLAcff9xDmgKh62Hui2GOtvz0e3g1EMMc57naJOBzXjRoEv0p87XP4lAiOLIclZ X-Received: by 2002:a17:907:9303:b0:add:deb0:8b64 with SMTP id a640c23a62f3a-ade8955ec01mr173083666b.24.1749618586258; Tue, 10 Jun 2025 22:09:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749618586; cv=none; d=google.com; s=arc-20240605; b=GixxELWZogzHU9OCPpK7CMCcvjgy7PxlqSkd0Y/cHaeBv3OeWIG/UqHqbNS/3ki2tA Z5vvHvnOul4u9UfozC9BmubR2PZ3f2af0LJrXUmpGCZfE8W/sncjsHw15oXSObNzHsVC pc2wyguRdTA3HRL4NUDCl4A+GAwKWWJOEAqtzXHoHgwnnQuFhoRznTjYFbSlg8wRNMAF Cw1RsdKdKKuJg87NDLju+50TK/QoI3owFDchxQO2BjIIm5WN0rsdjFcF44lkKM6MNZwp 2BEyXg1jnhr3anpfGPT7httgnjsKZvo3H8HXeUKKxchIueszekAVN2u9Ra2UOPxd5Bva zMlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OAxJD/tro4tQ+LLFN6U7a59OXHxib3oVjSK6WfPOJpk=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=AjeB8tvRS8TuwMf+ampjg41J6JwQREhKWM2r514RaR1odI5k447npWoBSAWOIVkIe8 BeN/U4teUSli7jYt55Yl6L5kC3bVuhtTohPvUU+ktoVHFoCZzv+ZLhs7qgETDVzTcD6l Cq8faxhqcIPIueWMnudDSluIweHjg86CW8L0+4mkyc/tY+RbIDBP3q5N0g7NzGaxrP6D zvmA+Z480KpdRKab8Gly40tRN55DavmWKdGyERSeHaXIL+jaTBdjQrbM0TBAQ5CkQ3z1 O01MsfFP+6mZ9j9+l2vMAiUuGqPY5cA0GGEWbyYtkHkKCY3UuQh3eSKAJ6DynsAxugqG cv5g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=ktYaylW+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-ade1dc7766dsi928498266b.584.2025.06.10.22.09.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:09:46 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=ktYaylW+; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C6EBD82C4C; Wed, 11 Jun 2025 07:09:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ktYaylW+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D3DF80050; Wed, 11 Jun 2025 07:09:16 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4550C82C44 for ; Wed, 11 Jun 2025 07:09:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-3138e64b42aso2561027a91.0 for ; Tue, 10 Jun 2025 22:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749618538; x=1750223338; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=OAxJD/tro4tQ+LLFN6U7a59OXHxib3oVjSK6WfPOJpk=; b=ktYaylW+t4v8v6vxRb9fSe3ZwpmD0cCcMVZJE5cPkra7tXtCxGNW2btpL84MFOtkSH 8PpYJgGQFcj0F87LYBNMDrRWx0h/jB+jbr3SzGvVmFxBnHnyDqJHGm0mb32f9mWupajR Ho6/24C0+tqjP0JA9v4hef7R72HqsC0B+soVFgq8bADADYuS5eBJCxfdfjOqOYhzZPWv +3AjNPLHHRuyGLbTe/z88740pzaZfQkVgR7ANRwXYNLfeOpRqZxdrUhkxCk40Vk+AXeG 5YmWvMQKXid9E2rj0bu4pdIPCbakFmRnOGyUZNqaZkZGSvd94IjhmTsZppWfO0lbf4Yz 7a4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749618538; x=1750223338; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OAxJD/tro4tQ+LLFN6U7a59OXHxib3oVjSK6WfPOJpk=; b=dVe1qI/PLLKzSf9kOU4Ritx6co2pAy1sGP0O1mfS1Jyoj8h3MWU3XS18ntJwYHCFQ+ CTM0xZdaVUXoAxWlwsKgAwn2o7P/BXwGGzgaqR8R5BeVgK5RlQjAwzm9zcTOFzXE4U7E NeUUpIE4De4gqW4IdSNHzTHhx3LoQNrCP1FGTifU/rAO1lEt8vQN/fzDjPDzAHcgSGeZ CRnMrJUwgzPyLAafhPdPBc4eZMgA8mb9Seu65IoL6OAXtbALrkvtSz/Hu+hjIHqmA7wn OI+4WfMBswsRxxSNKHXXVy9stcuUIfs8rPlgGdPWZsR+wF4x8XP18faGuGsij2WM8NH4 NcmA== X-Gm-Message-State: AOJu0YyRwmA+iKBMHqOL0dULhk416oXUk/GeCwG9Bzpm3pnUsWUwTHB8 mcT+9cTC2NSFe2sF0kfbDYhHCQa+BzkEfOGyLsyRnccX4BZ3rFdK5HY0BBso90ym X-Gm-Gg: ASbGncuRydyW4Oy8BNp5PGbLLsUwjYLwXgLwdXL1RUJWnAopQsondEm8aKBeKc4hfuD ze9X9U329aAqxUzAIasMsS4M7/KZVVoJt2CDg57YSPZwfjQvTB99276pOOERtQ88uovRVbDLQlI uwQpT1XowfzA//dUIHalp0k08/UAsRq+MgN9Y+ayaR2kcKFuRarkLD2q8Oz61Iw1pRQb9FCXx+2 Yey+Vl+GkvPDhk6vZ6pMs+RzeYXsyi9VzRHSNehOSe75vFnamXDOiCosb5wlXZSFxX71qzADTgt IXvz3akBuKUM8nF8oNVgSqqVOexjzFUeWIsk6iGYVVv13kf6I6BOYr9FbHluLJjYpYoB X-Received: by 2002:a17:90b:53c7:b0:311:ad7f:329c with SMTP id 98e67ed59e1d1-313af1b61a9mr3403154a91.18.1749618537927; Tue, 10 Jun 2025 22:08:57 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-313b1ff1123sm462386a91.10.2025.06.10.22.08.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:08:57 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson , Simon Glass Subject: [PATCH v5 3/4] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory Date: Wed, 11 Jun 2025 13:08:42 +0800 Message-ID: <20250611050844.210384-4-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250611050844.210384-1-paulliu@debian.org> References: <20250611050844.210384-1-paulliu@debian.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: "Ying-Chun Liu (PaulLiu)" Add efi_realloc() for realloc memory that previously alloc by efi_alloc(). Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Peter Robinson Cc: Simon Glass --- V4: Fix efi_realloc return failure code. --- include/efi_loader.h | 10 +++++++ lib/efi_loader/efi_memory.c | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/efi_loader.h b/include/efi_loader.h index d0c72d0bc58..13ca2ec9a4e 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -878,6 +878,16 @@ efi_status_t efi_next_variable_name(efi_uintn_t *size, u16 **buf, #define efi_size_in_pages(size) (((size) + EFI_PAGE_MASK) >> EFI_PAGE_SHIFT) /* Allocate boot service data pool memory */ void *efi_alloc(size_t len); +/** + * efi_realloc() - reallocate boot services data pool memory + * + * Reallocate memory from pool for a new size and copy the data from old one. + * + * @ptr: pointer to the buffer + * @size: number of bytes to allocate + * Return: EFI status to indicate success or not + */ +efi_status_t efi_realloc(void **ptr, size_t len); /* Allocate pages on the specified alignment */ void *efi_alloc_aligned_pages(u64 len, int memory_type, size_t align); /* More specific EFI memory allocator, called by EFI payloads */ diff --git a/lib/efi_loader/efi_memory.c b/lib/efi_loader/efi_memory.c index 0abb1f6159a..d69bbb85efb 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -666,6 +666,62 @@ void *efi_alloc(size_t size) return buf; } +/** + * efi_realloc() - reallocate boot services data pool memory + * + * Reallocate memory from pool for a new size and copy the data from old one. + * + * @ptr: pointer to old buffer + * @size: number of bytes to allocate + * Return: EFI status to indicate success or not + */ +efi_status_t efi_realloc(void **ptr, size_t size) +{ + efi_status_t ret; + void *new_ptr; + struct efi_pool_allocation *alloc; + u64 num_pages = efi_size_in_pages(size + + sizeof(struct efi_pool_allocation)); + size_t old_size; + + if (!*ptr) { + *ptr = efi_alloc(size); + return EFI_SUCCESS; + } + + ret = efi_check_allocated((uintptr_t)*ptr, true); + if (ret != EFI_SUCCESS) + return ret; + + alloc = container_of(*ptr, struct efi_pool_allocation, data); + + /* Check that this memory was allocated by efi_allocate_pool() */ + if (((uintptr_t)alloc & EFI_PAGE_MASK) || + alloc->checksum != checksum(alloc)) { + printf("%s: illegal realloc 0x%p\n", __func__, *ptr); + return EFI_INVALID_PARAMETER; + } + + /* Don't realloc. The actual size in pages is the same. */ + if (alloc->num_pages == num_pages) + return EFI_SUCCESS; + + old_size = alloc->num_pages * EFI_PAGE_SIZE - + sizeof(struct efi_pool_allocation); + + new_ptr = efi_alloc(size); + + /* copy old data to new alloced buffer */ + memcpy(new_ptr, *ptr, min(size, old_size)); + + /* free the old buffer */ + efi_free_pool(*ptr); + + *ptr = new_ptr; + + return EFI_SUCCESS; +} + /** * efi_free_pool() - free memory from pool * From patchwork Wed Jun 11 05:08:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ying-Chun Liu \(PaulLiu\)" X-Patchwork-Id: 895533 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:ecd:b0:3a4:ee3f:8f15 with SMTP id ea13csp2608767wrb; Tue, 10 Jun 2025 22:09:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW77C5ssn/hZXSNIvf6PgZX7Pnm5aak7kGvk/7nUMkjJr4F4eEdVxil27aSJdtYV7leEg9mRw==@linaro.org X-Google-Smtp-Source: AGHT+IFOjAPvjjEngEYBHEGUAxdhWf9RsUzGGTNA7YSDXJiFBl0Lk180rS1sjQ+2Pm6mtLroCg8v X-Received: by 2002:a05:6402:280e:b0:606:cef8:a028 with SMTP id 4fb4d7f45d1cf-60846c6c66cmr1590564a12.22.1749618574152; Tue, 10 Jun 2025 22:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1749618574; cv=none; d=google.com; s=arc-20240605; b=InkFHmO816K4Rt3ttL8wuWEAcj/5fCYeB2DV+f1Q6yymHH3c+MTM0by2AvYztej4l5 ye18GIKHI9V4G+YeF13wue8PeghNmYcsDtjkaFzl+IKcU22221gqqIhzKGJRlSZGUFM5 sS3AvQ3Pf06Ytr3sproa04u927+4f752X+TwtUHWBdme1BGGLKIRKsT1YaunwYX41H2o Qb6BTf0rSD/QPy0e2FIfBvuA/ttDC8aykJ1CDg8IwLGbmlT9oIrikJmY6fHKHP1F0gq2 Y3Wka27HOdljxDwiLpqnpSC9wrKeFUd3NrPnI7JJmK9kQzzsEz89xr6laV/DT/ZLxiQd Qtig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/O0J5UK+vrh2GMdoew/PWnH+pTzu2PWEpzWA1bX+yns=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=hwkKxJIf5upU049syWD58k5fViT2nKx0n4YHSxvHEKiTEJu+ZCJWfz5VBlkWICIdcj vkS88O+W2qau1wo78hzvpOItvM9HSUF6dFzIyrfNqyW1h9y47MiDMT0eXlgllHTdFOOj wd+os1Ki4jSftt2CREOtfFqQUgDvB/fYdhcKzFiGGp8q4L7iCV/qqlbAh9CnMNxsTJ2d RS/QtKRZYX9Zz0cdhhjFvu1spwFRxj6VBdhnDlvNQEx0p7W6VVXJoYHNmJnNxGiEDk91 v0SeOE9FpOQfDzBGkQLzZ5u1Es+YVqYTrzaWpHqqx0oLalr/StG9luDgiRnCO8SgsL1f 7KJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=YOw4ApGA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-607783ab277si9906955a12.442.2025.06.10.22.09.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=YOw4ApGA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dara=fail header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5098782B18; Wed, 11 Jun 2025 07:09:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YOw4ApGA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C1A7D82C30; Wed, 11 Jun 2025 07:09:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1A89782C4C for ; Wed, 11 Jun 2025 07:09:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-748435ce7cdso2681825b3a.1 for ; Tue, 10 Jun 2025 22:09:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749618541; x=1750223341; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=/O0J5UK+vrh2GMdoew/PWnH+pTzu2PWEpzWA1bX+yns=; b=YOw4ApGAtOP3+mNbzBCs4pqAy/DJy2Y+iz0HIkIXESx+JfCTO6wtuJCuaaFBQLTVpO NTOOFGZ92DA+EeGBZZt4hfEgXXSwMyQ8aKu/srAQcY7dKPrfsVYZcOC2bJRMf1xN1WUV hL2e9FwjC+ojkBL8Gmq9r7//rNhRopYxXHf77XhgDoq2UtIZMbC3J9ahyFsCxcDZw8LX Ecoem3DBLSsfzn+UYo2Ae0Gf3OYVxwT8Z0JDV6cve1rahc4acY53kzLhRbhoH3njQW5f 8bO1L71NRAyyrxmFOF+u3plePpr1ayZvT2NKtPfL9Rx7ZBHLuhfS+c3/3ViZnSIRoC3Y JcRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749618541; x=1750223341; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/O0J5UK+vrh2GMdoew/PWnH+pTzu2PWEpzWA1bX+yns=; b=mQ+oN8kifxOEyHaDVYJF8Z2iRTcbSqdfO3dhKyJGTONagY+CfitvVYQ+4Dk5AZogrt s3POQKCfRpHyIapRf0ZLYIHZNMM2UVyQ+zxvWrxPvWHnc5OeK68duqdbVvC/E289hsDy 4vCnsM+UDrCgT3x5ns2dTjijwhOOb6C/y5TBG1VHEU+47Dp1v17Ea1R4p4aXQXAanjTD 6qpHejbe8ZwgqEz2WAub/AgxTIOrf5R30aqcOtChgq0PV/i3y9EUZ7HPj7NVLnIuZU40 1QbiC3i/moj56lSGRdsP6NA4BxFs9dGWhc/gtn9bkXl6JobkbVM4eMjKS7wK1FaExIpr tkgg== X-Gm-Message-State: AOJu0Yz8Z/hU7nbqfqX25hnn5UNQ/B0qcVgo/2u0iLfT3G7hdTyc3aCB jTcLH5Lo+5FYYkkoxL04xL23ofdd8Jupov68rgpxxJ6t0r8JVI9zI89vEUYBvEwz X-Gm-Gg: ASbGncub8lkcxGn1xK5P0xcVgBdMGJ+k4zrSoxoGmihMjg4UNlqjBMqP9RNN9/IQFj0 N7G3HQaK5ubOsv3f9y7kM36Tt1JHit0EotGHn8KU+K5uHEZzrH2CKk3vM4i6pTRjMvERpBYgEt6 llj94bVp+lCkFCeR29q3BMrl+0IZi9lcaNB/2Rhb6R9+PyEP9yuZ8WYJsc5z1dWPxRzHjxjUVSO 4Ged6t+eEC2oUdzwhbQI6cnkz9U689rbOn4hgwNLR32Di+oejMV298AsShETjq4GvCYM3YY44JD Sb/9IEMQMeCiOWWQ9o/xGyTojFeie52reVZebA3EMvAyIA7gcrgeO1HCcc2bjGgaFcpR X-Received: by 2002:a05:6a00:b4d:b0:748:2d1d:f7b7 with SMTP id d2e1a72fcca58-7486ce51b3emr2747180b3a.21.1749618540885; Tue, 10 Jun 2025 22:09:00 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7482b0ec4aasm8492998b3a.171.2025.06.10.22.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 22:09:00 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson , Simon Glass Subject: [PATCH v5 4/4] efi: add EFI_DEBUG_IMAGE_INFO for debug Date: Wed, 11 Jun 2025 13:08:43 +0800 Message-ID: <20250611050844.210384-5-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250611050844.210384-1-paulliu@debian.org> References: <20250611050844.210384-1-paulliu@debian.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: "Ying-Chun Liu (PaulLiu)" This commit adds the functionality of generate EFI_DEBUG_IMAGE_INFO while loading the image. This feature is described in UEFI Spec 2.10. Section 18.4.3. The implementation ensures support for hardware-assisted debugging and provides a standardized mechanism for debuggers to discover the load address of an EFI application. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas Cc: Peter Robinson Cc: Simon Glass --- V2: use Kconfig options to turn on/off this feature. V3: Use efi_realloc to realloc the tables. Move tables to boot time. V4: Use new efi_realloc(). V5: Fix function comments and move the code into a separate module. --- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 11 +++ lib/efi_loader/efi_debug_support.c | 129 +++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 8da0a350ce3..77a05f752e5 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -581,6 +581,8 @@ struct efi_loaded_image { #define EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS 0x01 #define EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED 0x02 +#define EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL 0x01 + /** * struct efi_debug_image_info_normal - Store Debug Information for normal * image. diff --git a/include/efi_loader.h b/include/efi_loader.h index 13ca2ec9a4e..22440b842e3 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -650,6 +650,11 @@ efi_status_t efi_root_node_register(void); efi_status_t efi_initialize_system_table(void); /* Called by bootefi to initialize debug */ efi_status_t efi_initialize_system_table_pointer(void); +/* Called by efi_load_image for register debug info */ +efi_status_t efi_core_new_debug_image_info_entry(u32 image_info_type, + struct efi_loaded_image *loaded_image, + efi_handle_t image_handle); +void efi_core_remove_debug_image_info_entry(efi_handle_t image_handle); /* efi_runtime_detach() - detach unimplemented runtime functions */ void efi_runtime_detach(void); /* efi_convert_pointer() - convert pointer to virtual address */ diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index dbebb37dc04..40495c98c18 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2129,6 +2129,14 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, *image_handle = NULL; free(info); } + + if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) { + if (*image_handle) { + efi_core_new_debug_image_info_entry(EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, + info, + *image_handle); + } + } error: return EFI_EXIT(ret); } @@ -3359,6 +3367,9 @@ efi_status_t EFIAPI efi_unload_image(efi_handle_t image_handle) ret = EFI_INVALID_PARAMETER; goto out; } + if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT)) { + efi_core_remove_debug_image_info_entry(image_handle); + } switch (efiobj->type) { case EFI_OBJECT_TYPE_STARTED_IMAGE: /* Call the unload function */ diff --git a/lib/efi_loader/efi_debug_support.c b/lib/efi_loader/efi_debug_support.c index a6a672bc0e4..468e9e1cc83 100644 --- a/lib/efi_loader/efi_debug_support.c +++ b/lib/efi_loader/efi_debug_support.c @@ -16,6 +16,13 @@ struct efi_debug_image_info_table_header efi_m_debug_info_table_header = { NULL }; +/* efi_m_max_table_entries is the maximum entries allocated for + * the efi_m_debug_info_table_header.efi_debug_image_info_table. + */ +static u32 efi_m_max_table_entries; + +#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof(union efi_debug_image_info *)) + /** * efi_initialize_system_table_pointer() - Initialize system table pointer * @@ -50,3 +57,125 @@ efi_status_t efi_initialize_system_table_pointer(void) return EFI_SUCCESS; } + +/** + * efi_core_new_debug_image_info_entry() - Add a new efi_loaded_image structure to the + * efi_debug_image_info Table. + * + * @image_info_type: type of debug image information + * @loaded_image: pointer to the loaded image protocol for the image + * being loaded + * @image_handle: image handle for the image being loaded + * + * Re-Allocates the table if it's not large enough to accomidate another + * entry. + * + * Return: status code + **/ +efi_status_t efi_core_new_debug_image_info_entry(u32 image_info_type, + struct efi_loaded_image *loaded_image, + efi_handle_t image_handle) +{ + union efi_debug_image_info **table; + u32 index; + u32 table_size; + efi_status_t ret; + + /* Set the flag indicating that we're in the process of updating + * the table. + */ + efi_m_debug_info_table_header.update_status |= + EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + + table = &efi_m_debug_info_table_header.efi_debug_image_info_table; + + if (efi_m_debug_info_table_header.table_size >= efi_m_max_table_entries) { + /* table is full, re-allocate the buffer increasing the size + * by 4 KiB. + */ + table_size = efi_m_max_table_entries * EFI_DEBUG_TABLE_ENTRY_SIZE; + + ret = efi_realloc((void **)table, table_size + EFI_PAGE_SIZE); + + if (ret != EFI_SUCCESS) { + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + return ret; + } + + /* Enlarge the max table entries and set the first empty + * entry index to be the original max table entries. + */ + efi_m_max_table_entries += + EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE; + } + + /* We always put the next entry at the end of the currently consumed + * table (i.e. first free entry) + */ + index = efi_m_debug_info_table_header.table_size; + + /* Allocate data for new entry. */ + efi_allocate_pool(EFI_BOOT_SERVICES_DATA, + sizeof(union efi_debug_image_info), + (void **)(&(*table)[index].normal_image)); + if ((*table)[index].normal_image) { + /* Update the entry. */ + (*table)[index].normal_image->image_info_type = image_info_type; + (*table)[index].normal_image->loaded_image_protocol_instance = + loaded_image; + (*table)[index].normal_image->image_handle = image_handle; + + /* Increase the number of EFI_DEBUG_IMAGE_INFO elements and + * set the efi_m_debug_info_table_header in modified status. + */ + efi_m_debug_info_table_header.table_size++; + efi_m_debug_info_table_header.update_status |= + EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED; + } + + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + + return EFI_SUCCESS; +} + +void efi_core_remove_debug_image_info_entry(efi_handle_t image_handle) +{ + union efi_debug_image_info *table; + u32 index; + + efi_m_debug_info_table_header.update_status |= + EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + + table = efi_m_debug_info_table_header.efi_debug_image_info_table; + + for (index = 0; index < efi_m_max_table_entries; index++) { + if (table[index].normal_image && + table[index].normal_image->image_handle == image_handle) { + /* Found a match. Free up the table entry. + * Move the tail of the table one slot to the front. + */ + efi_free_pool(table[index].normal_image); + + memcpy(&table[index], + &table[index + 1], + (efi_m_debug_info_table_header.table_size - + index - 1) * EFI_DEBUG_TABLE_ENTRY_SIZE); + + /* Decrease the number of EFI_DEBUG_IMAGE_INFO + * elements and set the efi_m_debug_info_table_header + * in modified status. + */ + efi_m_debug_info_table_header.table_size--; + table[efi_m_debug_info_table_header.table_size].normal_image = + NULL; + efi_m_debug_info_table_header.update_status |= + EFI_DEBUG_IMAGE_INFO_TABLE_MODIFIED; + break; + } + } + + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; +}