From patchwork Tue Jun 17 12:08:52 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: 897373 Delivered-To: patch@linaro.org Received: by 2002:adf:9b99:0:b0:3a4:ee3f:8f15 with SMTP id d25csp2109920wrc; Tue, 17 Jun 2025 05:09:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUsml3IZ34isqmJXbgJ0PCMtk9ArY5iLkItPnbfR6TXiG98EO84DZesHebCPFaylpPnHJbz1Q==@linaro.org X-Google-Smtp-Source: AGHT+IFil45RWckf3e/Bq9HnstCTV74RGVD2AH6l3J0WCcKcUhKXk3BajsLEWxenmZPVv4r53SRZ X-Received: by 2002:a05:622a:87:b0:4a4:3bae:8dce with SMTP id d75a77b69052e-4a73c597286mr216909451cf.33.1750162163559; Tue, 17 Jun 2025 05:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1750162163; cv=none; d=google.com; s=arc-20240605; b=SS20JIpn065T0gmXdPiU+icBypveu8Quk+TWHJdzxhOIHRZbp9XtnZrR15Z/NXo37n xERBksATZRMBLS9TIUQL+eiNMypVrIvMFwQyDa9Ev8HztVBv67JIISoPDsKKClQm3SI8 IqRjIPTsRsPsQ8p0u0mEBd8icSKHy5tl5GWOU7gVNf8j3rUYXx6Cxt+Acy1CHJFquyTh rdxLE5DLrSCZyBTqRAKkYxvWg2efXvEoF2Z1hf2ZPYaCuL/G15awx2JLmA5RQ2EaVigj 5IVX7AqZq4/Iw2AgmH5n+HU7Xssf0QsSTt8nd4Ln0qCkAhS8Vs127quBOio5Df+/lg2a uL0Q== 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=vPHwTuMl+G6hwPSEOHWApGdofp/1DlV7mnQ5GtMvyxY=; fh=+3cyYFR/nbclU+pcJoo9mLKkg74thq6d5DTO0xLZ6fI=; b=RCZ+Pg8SawqBNMKYD6xURslBUATDo37eQBJ0nr4ibb1WHoOAxaEbb39KFMPhwLjuAv gzBGsLPHk/R1HHo26Y7tnBp7LPyHZIx5IsYDjWtsXSPAJk4KDna2g4SkynkOX1zVoDrR DPO/lPzP1hAVXQVVgZuh3/VBtlSuoXIUC0jF3Fgw9GMBCMpZuq9P3JOJc+cVleclZTvs 5fQpk0soWUZE4Mm9bSJZ6hE79jw3xU6i1a5i6RQg4D57IcUTXb7esCUhp1GnkxA2nkZY /YUWI9i+ntmlPieh3ZR7fc4hlnPPMldJrBmpqsa0JP2YTrVWuhOVK/w61vJtO3txGyps yURA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=HDOPD+ho; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id d75a77b69052e-4a72a47d93dsi117790201cf.246.2025.06.17.05.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=HDOPD+ho; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 DA5B582D39; Tue, 17 Jun 2025 14:09:11 +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="HDOPD+ho"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4E90882BA1; Tue, 17 Jun 2025 14: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-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (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 C2A4D82BCD for ; Tue, 17 Jun 2025 14:09:07 +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-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-453426170b6so16923215e9.1 for ; Tue, 17 Jun 2025 05:09:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750162147; x=1750766947; 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=vPHwTuMl+G6hwPSEOHWApGdofp/1DlV7mnQ5GtMvyxY=; b=HDOPD+hopEmi5i5q8b2IfrjGZMyStM5MuAoWYLuimr+ucrYaSZMbtj0DR+krtWs3Kp 6h2OCW6WX/HaHVaXnzA0kvA2mwgu/6iyzkcNiyNEQU4Aiid+nSgVgL8UjmDI8V0lqPOF oVwfeVrLnOM+N63QqJ5k2RRcy+sYuQUBr3Ka6s/ThLQScJG1T2lRMC0KCYMdLCgyICrX kIQMTuCJQDeVcwuN3huQtPY5MNiB7it9zHO4HmXjjzmiPNr1ZLVZl1Y5hqNUv6Udsrhm OdqlM3VVhHAWEk8tDE3W9l1mnJOfLGoZUcuK5QclHicUMTILwhziTUIxcxOykIA5PyIO p2DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750162147; x=1750766947; 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=vPHwTuMl+G6hwPSEOHWApGdofp/1DlV7mnQ5GtMvyxY=; b=gTC1dYVAoNnl11mCnSsK5mOBrPSwesxPtjO8p2ExXtwRON5/MHpTrtdAp/rTY1qcGM MuFEsP2b51H5aGUaW14v1eyPVXjELR8G5ua0tNqlm6RT4lXxDhHh2xamcK77fYq9EWQ6 5yXCaSFXMRfdkhYVY1K6xmGhwVQenyQkD2mR6iirmFtsB5bXSaV163vZsx+ixHKqR4wN hRA9venTQ/Tq0np4kmM8o1Vt2p+FMpu0GMqJ0ZIdDO1ujsI/EqCWkwUxlDWn+KicLJHs fRJOH4QzZKT+wpW73KMySvWWz+23reZCrUwEJWRGDQXsz8rTjiZ7BtFuSR7epnhNM274 0yag== X-Gm-Message-State: AOJu0YzyCWu0YtEk72rkwEUPgBHJqk6FMSXnf29azL7Hpi6GMoce+vOG UChRu356sdHd+HBiNJH2wB5xo2+w1h7Bunze6JOQt75lSo/+L5aPIL1UA7k8v+5rCow= X-Gm-Gg: ASbGnct0ZBC1fTs5VoEvafvCXAOqCaziOiYUg+9zu1VcO1ZRL0/Dg3tvQr/7490vPKV eUfmJrpk8OEVbsSVGfS9E6fojVHJK2xuBjiIB5Pg9JJGZEcvp6bz7/x/LC+4KR8ZRTTHTzo/lNw 3iB5SZsa3AJNiEWBzqB4B29e2Lr+kdy0BnxL1CZlYmuXkJLU9IHgJw1u4YqgO0cOSbfjy7rt/3l jbk8w5BIJfBWpINKFev+ZqJ0OTsGZFYN2WSTcd7Z8frEV9A2XPwzcaC4N/NtROyMEp4uFENX4Iz vrLUcC6qM5/0fkYN4WrYLIJqKUJrNL8UEgWEE5PFw70Py8zNCEWhZ3IU0RRXCA== X-Received: by 2002:a05:600c:37c5:b0:43c:f509:2bbf with SMTP id 5b1f17b1804b1-4533b28aa22mr139105505e9.15.1750162146753; Tue, 17 Jun 2025 05:09:06 -0700 (PDT) Received: from localhost ([2001:8a0:6a5a:6c00:eb29:af93:a639:c827]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e224956sm176348555e9.4.2025.06.17.05.09.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:06 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Ilias Apalodimas , Heinrich Schuchardt , Peter Robinson , Simon Glass Subject: [PATCH v6 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug Date: Tue, 17 Jun 2025 13:08:52 +0100 Message-Id: <20250617120855.87492-2-paulliu@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250617120855.87492-1-paulliu@debian.org> References: <20250617120855.87492-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) Reviewed-by: Ilias Apalodimas Cc: Heinrich Schuchardt 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. V6: Use macros to replace size_4MB --- 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..3794b31c4cd --- /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 +#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) +{ + 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, + SZ_4M); + + 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 Tue Jun 17 12:08:53 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: 897374 Delivered-To: patch@linaro.org Received: by 2002:adf:9b99:0:b0:3a4:ee3f:8f15 with SMTP id d25csp2110008wrc; Tue, 17 Jun 2025 05:09:33 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVlVq9fIJQid3BaAGe+1RiIhOhy8VizTcoGg19QB8JS4UIdjL6XQ/V4mg52UljndEAJsTTO2g==@linaro.org X-Google-Smtp-Source: AGHT+IF9SbmRbWTA2FQ+lFNYYzd4xUEme8GjqONyvOMS3J31WAIzjalvW+J4y3dU0KpHOSM9iTA/ X-Received: by 2002:ac8:5f96:0:b0:4a4:3171:b942 with SMTP id d75a77b69052e-4a73c5a8c84mr201113961cf.39.1750162173101; Tue, 17 Jun 2025 05:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1750162173; cv=none; d=google.com; s=arc-20240605; b=H5w/ToRa/VGWBBghUf3u6sOfDxgXAUOKIzRMJYaFRMfOhCYAXAO8XiHapHgkILBhFq tpx1FjUX1OSEi94n5ArgRjVZLFFuekRqZpoEXifydiA9foW26ZerSTNY387+PuoKo5YN 0HjGEYu+QLuaJJRln34adjJM2a/IHxb5x3qigXf0rR2IvfESuI1/Ko4nb1KdxeZUh78O nPDcdD+hILKdSFVXla2FckqahutQsnVot9fZX/FzkjNsJ8Si7LK3vObKPSWLRdBhSnyy e5uGQDoJnUZLIKL3Rf/DqlddXtq3e+VJ2GWtgMmP9UDVmAuYCLITsamaE44MCDc1zQfe 7TsQ== 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=HEIylWC0yYo4Uc3r0VmWEnNvVTsw05DlqRlvmiQKcAA=; fh=+3cyYFR/nbclU+pcJoo9mLKkg74thq6d5DTO0xLZ6fI=; b=CK6lN7yZi8hUyzOpRjjxP0lXt0SydfEiRNWmw3ySW/4Jqh9ckwSFJK9l4rDeX0rc4W W0fi3fgexi/InZDGpmDGSs/k2Oiu8psRXPRGRbHABF7qI3/G6l//fWXA25o3pBmU1BeE dShphNDeRSATB3+8UC12Z8Q7qhia0V3HGnZJwDtIHxCVSFHwDMkB/fePjMUiYkp0KObM ZyHIFyEU1EELRdDS6xiJgDoztM48yy/dHNknepV2ZmAh7I/e2WyCu5/QsergnMbvdbq0 7aBnAbkLF9lnoXexSz2HLQxwILfNWe15aFaWHUgoT05hCMbQ83DEKQdIwGnaktPahh8+ B1Uw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=lyLR4Db3; 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 d75a77b69052e-4a72a47d1f7si129614491cf.297.2025.06.17.05.09.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:33 -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=lyLR4Db3; 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 4E95382BCD; Tue, 17 Jun 2025 14: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="lyLR4Db3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E79782CD5; Tue, 17 Jun 2025 14:09:12 +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-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 7A8B382CD5 for ; Tue, 17 Jun 2025 14:09:09 +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-wr1-x432.google.com with SMTP id ffacd0b85a97d-3a50fc819f2so4756905f8f.2 for ; Tue, 17 Jun 2025 05:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750162148; x=1750766948; 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=HEIylWC0yYo4Uc3r0VmWEnNvVTsw05DlqRlvmiQKcAA=; b=lyLR4Db3VeiVSNG0mMHRh3vyQnXLzJnLXNy9KzpR7FiLJ1xRgwyIN6Kv73KVzzgJAk fnPt7ZXDmZoh0aFM1T1J7RSYpuBTXCz338vowfOCsqgBe4qcvYtK1wt/xDjkxupC5r8+ uqjX7uYw/FjLGWUVDdmCWSp28t0CFUq58JDdsWbzx57xJRxBjL96neb3R8lcUZUpIVR/ UfbNl1rx9RWLhSTQ1RYDRF7iPksoqGBW9e3RWu4JjURB6LNjVO8WI29TGGRlSwnZIDx0 5z6Ny1QOUMexqgZdRVpRbnOMWLORW9jt+wE6KtnW75UdBPj+Kdu+cQdtFp2NHmQSV7pX rpEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750162148; x=1750766948; 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=HEIylWC0yYo4Uc3r0VmWEnNvVTsw05DlqRlvmiQKcAA=; b=Mt+QOsiv08g8r5gaqP6SFyGCKN7n5C9+A2IJw7nw/cYGUcqnkIxxx/nbzJIAHsEJbp 01uvpgO5HYIR6br6ByyRK20jEn6RuoHr1Iaf+IhtIBiUQUY/cjmy8wBscYdNorPxZ5g9 9QIyoDVvO/xUmsFd/YwN43aUmTwejK8leyMJvwegpm3fGK7L50eE7m9r0FHly0ZWaGKr lKdNPcNmYKl6iAw/JtWM3ZqVFvLYnsHrl1fsSWDA20wbZvuWlZ3eDqg7BxwFdretuPDE VFk9Akpp78fav+YCFfI+dUcy4+HU1V01lCadq35/iVHPsm9XQ27dAFtvByPlnRwRZ5d8 aq3Q== X-Gm-Message-State: AOJu0YzJFIff7xE85arZSEaF79aw88fjNgbuFeZb/toYu7une0kEkE6D s0fK8UcJAKlX9kVz5dKiHMe0HCH5h2UurHwoorOOAOwiE/2L7ZShvNt8f2CmLi7vrZE= X-Gm-Gg: ASbGncvq2zqMxVXQ1XYKL4iiqN936jJjxlmoAHqbePBWowEn5LMeNdOJ6Zn6/JwbjvD Sa6y/cWjS8DYzo9jow01vXQOt07buL1Uecir0heAoCXLNXZO8Vuc3uAUbW3a/3FnrkAZ5sqOjwt p6r+F9/pcHVjn+ONaH5cl1zqL9zxLOlF8z8sbhDaQ4NR+HnvBKoY9+mGLsqgs7AOqiIxBD4bnpf +s2sJGS7tzYZOdDNEmrKUiXrurN3ckGjOnaGLK0Os3XqwFru4MLTZruYYlrqIpi6rQHQduE103G aNO3cvN3nT0gb5NuO2DBo9BMEqma8Wd2gp/1N3BSOD9RS/AZd4LrVxxSei37YQ== X-Received: by 2002:a05:6000:288d:b0:3a4:e4ee:4c7b with SMTP id ffacd0b85a97d-3a5723a3ad5mr11124992f8f.15.1750162148251; Tue, 17 Jun 2025 05:09:08 -0700 (PDT) Received: from localhost ([2001:8a0:6a5a:6c00:eb29:af93:a639:c827]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a568b7741bsm13996560f8f.98.2025.06.17.05.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:07 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Ilias Apalodimas , Heinrich Schuchardt , Peter Robinson , Simon Glass Subject: [PATCH v6 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug Date: Tue, 17 Jun 2025 13:08:53 +0100 Message-Id: <20250617120855.87492-3-paulliu@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250617120855.87492-1-paulliu@debian.org> References: <20250617120855.87492-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) Reviewed-by: Ilias Apalodimas Cc: Heinrich Schuchardt 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 3794b31c4cd..f2dfcc5e6b2 100644 --- a/lib/efi_loader/efi_debug_support.c +++ b/lib/efi_loader/efi_debug_support.c @@ -11,6 +11,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 Tue Jun 17 12:08:54 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: 897375 Delivered-To: patch@linaro.org Received: by 2002:adf:9b99:0:b0:3a4:ee3f:8f15 with SMTP id d25csp2110104wrc; Tue, 17 Jun 2025 05:09:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUIqN5Y+6I5+4pxTD+wpajzhzAl9r5M33nlnscEen2m6hml5OX7kpHOxUITGBSI9xMOq2Lifw==@linaro.org X-Google-Smtp-Source: AGHT+IFJe4iVAY+AnQ5QMKFG0g8ixTtoqsZfuyhGQGjJS9IjCg3jCRxKJSZsncBParfsQAaSha1r X-Received: by 2002:a05:6214:248f:b0:6f5:3cae:920f with SMTP id 6a1803df08f44-6fb4775911amr214725116d6.27.1750162183766; Tue, 17 Jun 2025 05:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1750162183; cv=none; d=google.com; s=arc-20240605; b=EzV6tS7rjm1/PZFknAX/mydeW0XtN+iZslcAA+XNYDOsvybIF368XKLacXKfSkmtFn sCT5l78/On3UG6TIKSVeAVYyCutlunBAyLwImy6hW9aXoL8/yOZCQs7W8SG9bdgyZOQN LYAV/R2/8c4OxM6xOa1xOKFmqSjVUXr9M5U7Z3WQxm9dQhh2LTJUTN1Ikn8l3wKUFDSm ETPJ9uDBdl8J44FnqF0msfHgTUsBYurEbpyf6TFOAE7QF4ujfIt2b8KxHN4Ehhp9D7EH bWmIZ8iFD8hAc8QHWJ6F5Cznv0k4kxkVCrjvRN5QZpHFVpo5kY5jANwpINOKIbxLH1/b 5NKA== 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=ydNmL5Gk1TuCL7/qVzPwHMAwrmFgsuXUQqMEZZL11K8=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=gTwR17SVLNyzMzFVd6F33eJfH26SXVmLNJ5gbMkOcfKYHEE6+qrT7v9iV5Xspguk3p 0tREVYTCb63bp/W7D5WlG8pHp/0pH0aSQEAtSSO+2XPCwBey+eGHmivs5K0CCP4JhhXr P/AnkQrwrkSwZfy7rVyQl3NZ67WVw0j0HRYAYIfcfDj41D28v7MYk+/KA0xaWVpAFMio bhvZ3HUmuwzfHfts9i6fOieDppDo0nacMrE/gJ9Ls+3xuO5obOHKL0ScSnhH/eNYYx3p DGXIDQ2a8gnU1mfhrPPCId8fj2+E0L/PhFrdKkH0sH1cO31SiSFnfg+cs7LkxK4S6Ruc n77g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=UfTpgXjW; 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 6a1803df08f44-6fb35ad99f2si128289356d6.1.2025.06.17.05.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:43 -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=UfTpgXjW; 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 A095B82E17; Tue, 17 Jun 2025 14:09:14 +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="UfTpgXjW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 42AB582D60; Tue, 17 Jun 2025 14:09:13 +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-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (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 4638D82BA1 for ; Tue, 17 Jun 2025 14:09:11 +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-wr1-x432.google.com with SMTP id ffacd0b85a97d-3a35c894313so6358117f8f.2 for ; Tue, 17 Jun 2025 05:09:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750162150; x=1750766950; 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=ydNmL5Gk1TuCL7/qVzPwHMAwrmFgsuXUQqMEZZL11K8=; b=UfTpgXjWxwe3888iZdt7hk7I68mcEnu57E+NjM3STOLcxlH3Mnp3Rpc6HcVZGNFk9i RsCexvoiy4/f2L0+2AIg+wRvJQUTq1YSUvLHx3WHJglmaHUAhhGiVcqp959PcT/apcnk 3mX4OuNK84a9qK2lssIzLDsUx/5NlwQ/g+RcJ+i4oi7rxGq0qYqzATMCTrYmEpaUvT+b H3MMVXGx8CDqtmkdOqzcVOr/xXaNvKUVZKJK4ij495zc/uj1/QidwBKNEm4axY9X4n03 MRCRez5TZHiN+KrIalDhqKI0l4ejEDTSsBzGodogPHvG+DBB5nXoFWHW8w4WzVWtQB8u HIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750162150; x=1750766950; 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=ydNmL5Gk1TuCL7/qVzPwHMAwrmFgsuXUQqMEZZL11K8=; b=Jbr2tsXO7i6LloMQgDfFUqd4vUy65En/cPdLEz+5RBTRPUE1go+5k8sGWQk9TpbfAR 6wB4wtDKA/gaYtAQDknfjSLL6RQUoBclnuTWiCSolg7VBJAz1DG+izsiFXEgAjMX2yP0 eO8C8/x3R289aGu9mk8/NEdYL92IFNQvKgIP5xNmOSEqfVtMK6FPjV+iB/4r+8xCX8de DAA4H8IcByePHsHy8lSdJzeHFKu3X/pW+6Jo5dp7QS8WMAlDlptAuU60+EdCF4towB/5 zQGvWFBMdatRXeWeF3STcu0SbjiZa6ZucTqW/MJITTs5e96hHuJ3evPs/KN2omKycDXK 1btA== X-Gm-Message-State: AOJu0YwbGEFrR2FvFE6lNbWDCqNldhXoLTK4tqdLPHfIEqVvFqtEJSfR VNsQyS6sY0S0Vhp1UiERRx52EPLuny5Jxc+ndKha1zdZiImCfodkNTynSTDVD29B73U= X-Gm-Gg: ASbGnct+97mKPNb9xTtDxBvYV0DQWmtFdR6HG+gKSgqHggoeejRY4oRJRCfREpPDL6j X/vPlJd3z4OH81mfDordX42LNsBc+kOyx5ThyfEYdZH5J4N+7vMCOSf/UOb1qwTRxk0BYaewDc7 VM9rOkUSGUZCF2sU2wJZVhwPg5o5x3qRcGNVm/alGHhWrLT6XRxtRgeUrnzbYSWyosW3m52NPBn GNWyo1PU75ccBITfBBiNW8zM6k7fgfRz+yV0YVgFYiukmnOPRJJCwJrtK33vyC0aothOw7JGaQi i0tBmm98BpCNK11t1d4hT4yRrjoEMDb5P/SgGFMp0MwkxAGIggPJr+BdxGgLKA== X-Received: by 2002:a05:6000:2184:b0:3a5:783f:5296 with SMTP id ffacd0b85a97d-3a5783f5728mr6156685f8f.56.1750162150319; Tue, 17 Jun 2025 05:09:10 -0700 (PDT) Received: from localhost ([2001:8a0:6a5a:6c00:eb29:af93:a639:c827]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a5780c5004sm10228630f8f.56.2025.06.17.05.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:09 -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 v6 3/4] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory Date: Tue, 17 Jun 2025 13:08:54 +0100 Message-Id: <20250617120855.87492-4-paulliu@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250617120855.87492-1-paulliu@debian.org> References: <20250617120855.87492-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. V6: Return error status when efi_alloc failed. --- include/efi_loader.h | 10 +++++++ lib/efi_loader/efi_memory.c | 58 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 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..1570e300570 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -666,6 +666,64 @@ 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); + if (*ptr) + return EFI_SUCCESS; + return EFI_OUT_OF_RESOURCES; + } + + 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 Tue Jun 17 12:08:55 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: 897376 Delivered-To: patch@linaro.org Received: by 2002:adf:9b99:0:b0:3a4:ee3f:8f15 with SMTP id d25csp2110181wrc; Tue, 17 Jun 2025 05:09:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXN13Q7mJNJbzcZozGJNnQISiQ9j6GBOoBl61cN99soYMnunRqSIICeA6eHbYk6ImdOzPtAyA==@linaro.org X-Google-Smtp-Source: AGHT+IHZR88gjQMoNFeRj7Yi7Ni7JheR/RzvNbN6AV4fL+XPEQb3yocz0BMfRBD9VeqE7jGrUzDA X-Received: by 2002:a05:6214:458f:b0:6ed:df6:cdcd with SMTP id 6a1803df08f44-6fb47774531mr190994306d6.21.1750162194287; Tue, 17 Jun 2025 05:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1750162194; cv=none; d=google.com; s=arc-20240605; b=WXM17Z3ZkjOSQBiQn8cHZ7QwSVZLL2E4sGIWv309Z6pvE6VXtWDm/R7WDPyaBrgq5M +yryUcY8harHd+ryolkBm6T8aZD0Z+Gkx1+2CgEjahMMbGL83G+inzz2m+i8MAOqlQ1G +2PHCJ1KYROn77g9ncRMNCIKWtOPbhGd0bDom3CDwe4XC8wBG+5lve5YJG6v3m87QyqA pVci7PzJAXHOuXuLYLhfWNwwRPAY+phtLdIKt/vegx7hmZGrCww/p8NtSrzB8u9/ZEQ6 8k6mh87ovU1RhlfWiGVZzGig+3WHRk3AuDdfmXWRoDHAgeYTR19jKfkJTrGsn6zKEmSl Ntig== 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=1c2pwJ2/pvZAcb35TUJkkg9SHD7IYnZRmkc2mtIWLBc=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=N/FSiwLgt2s96i20Y0lGX8tejmceneJoeZ2piu0hY+GsBNt5l/JOG/D+WS+WS/6yNS wq2ohP+QjGo3DZavVC657GbhgRvv5Mmn9VLLxNQ3BWXfkuDK3X+1e3izHmzvuHWmthDX d3potiozqk0/3npSIsKa5BcI2yRpiYCYJMfBmpK0c0QK03obd1WThnfGZ7IJy9pbA/Gk ywRBuqK57MwlKWyWGTzI57juD3ObIVcUGMOH4wpVDUvGygWlz2M85I6Gay9oA4YlHGjP mEf31tleTKv4inDhRdSW8O9TENCdd4Q7X7JS+NfBBo3es+30gVzR5m9GgTSM5p5+Kzte Oj4A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=LwRS3Z8S; 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 6a1803df08f44-6fb35c39f13si127857636d6.472.2025.06.17.05.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:54 -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=LwRS3Z8S; 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 2A6E482CD5; Tue, 17 Jun 2025 14:09:18 +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="LwRS3Z8S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 191A582BA1; Tue, 17 Jun 2025 14: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-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (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 131DE82CD5 for ; Tue, 17 Jun 2025 14: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=grandpaul@gmail.com Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-450cea01b9cso26131095e9.0 for ; Tue, 17 Jun 2025 05:09:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750162152; x=1750766952; 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=1c2pwJ2/pvZAcb35TUJkkg9SHD7IYnZRmkc2mtIWLBc=; b=LwRS3Z8SwsTHSlaTGSMMbv1o8PuQOIMl0GeoxyRboYPI8PH8VvQosUvzDuQnJi2niK O23vkCKfjjBVrRKtvTEUD+eVJkuOyjOcHzspR9O/Q+tiAvWvtl6SYhQPPMWreZ1W3rRY wyXr73Q9Mju4qvu9zbKeCLkzqpN3wjJaVKF6TdDNHccWV65+0x6yV84+B30Y+jtGz1m+ R7PfLmVtVKoeS7/2FGRF1OGnsG/7wCCdz3KQImVME+w/JpHGN0pCfzLCaoLyxMPhE4xm esgrbQgdrCg7IBcIBbCjlmNYvpuSHdIJEfwLh/u01HYCyzvXzkjbsGTzht5EdJKGWyAF HpqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750162152; x=1750766952; 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=1c2pwJ2/pvZAcb35TUJkkg9SHD7IYnZRmkc2mtIWLBc=; b=XtCBRtRtfWWXvy4FU9VJIkdqaL+8uE+DGE5UWP4cnq6YYLXeGEJTZfrkFsyht7yHGa qHh6SWSLgpHO07BM+z4g6fhG8TtcBjLGFAglmUorzbQFfGnWSwh5ukoInjGszLxCUWmp B/os8wpkdAJk3pqhHu4/YEfXsvQXO7UwBEoqP1z0WpW+e0W80afU0qrRLs8msIYLGYaI CYgwAH+BAG4xInZRSwIeclryggArP1uC66PxZ+z+UGmcnYdMtUY6qQEl8BPmx5YIEpfE LIMm4APyzZkp2YLvS8qSbz7I+5VR7oc2bwY1WwD14H2cz4fJjagG7yjywLjf5Rldj7b9 e4VQ== X-Gm-Message-State: AOJu0YxBPhA3mNncUgX8RSYD+IZW1KrHVOrOI+n/kwr/8S7f+E6nLS6T 5MY9PqdBa7Ux9INolBwvCd/ItwUTG1BOs8n1den619Hd3xsOZ8HtJiVy2LopQPc5MYU= X-Gm-Gg: ASbGncu5yyXNdcx2xwlrlSePKVHA5Vm4pISRRnHdVFDeQejS9DfNRJ2TEo9C+WinGbl 54lj7U8ROhOg4TXto0LLIHmM4RSWFrdDn/+WAo34HkiS0Z0VwQdFubb5ZWAysiYWn0CkkLHDZBv s4FtqqVbbS2UsrSWR8ZVjOWNAGRLLpHu+Htbe/jbvWtBo4qOqxtJJQzurz1jn3O7IOHke4TwwiY w77aUZqgSimxVvnJN+ILg8sde0L2MRO6HRuXwIvUPyHf9ZLFmDn0azyo1jldfFhbyPuNNRq9ff/ nzQjxyyzktLsX8e59t/gvBHRKuWwduXV4x9aXNRvi/sYHPYoRQq4ZbIFhqNkMmSlef21byQv X-Received: by 2002:a05:600c:3513:b0:453:a88:d509 with SMTP id 5b1f17b1804b1-4533ca7443cmr161529635e9.10.1750162151824; Tue, 17 Jun 2025 05:09:11 -0700 (PDT) Received: from localhost ([2001:8a0:6a5a:6c00:eb29:af93:a639:c827]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4532e232b68sm172017075e9.10.2025.06.17.05.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jun 2025 05:09:11 -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 v6 4/4] efi: add EFI_DEBUG_IMAGE_INFO for debug Date: Tue, 17 Jun 2025 13:08:55 +0100 Message-Id: <20250617120855.87492-5-paulliu@debian.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250617120855.87492-1-paulliu@debian.org> References: <20250617120855.87492-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. V6: refine the code. Handling the error of efi_allocate_pool. --- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 8 ++ lib/efi_loader/efi_debug_support.c | 137 +++++++++++++++++++++++++++++ 4 files changed, 152 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..303b7543e16 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2129,6 +2129,12 @@ efi_status_t EFIAPI efi_load_image(bool boot_policy, *image_handle = NULL; free(info); } + + if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT) && *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 +3365,8 @@ 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 f2dfcc5e6b2..d8df95abf95 100644 --- a/lib/efi_loader/efi_debug_support.c +++ b/lib/efi_loader/efi_debug_support.c @@ -17,6 +17,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,133 @@ 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 accommodate 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. */ + ret = efi_allocate_pool(EFI_BOOT_SERVICES_DATA, + sizeof(union efi_debug_image_info), + (void **)(&(*table)[index].normal_image)); + if (ret == EFI_SUCCESS && (*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; + } else { + log_err("Adding new efi_debug_image_info failed\n"); + return ret; + } + + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + + return EFI_SUCCESS; +} + +/** + * efi_core_remove_debug_image_info_entry() - Remove an efi_debug_image_info entry. + * + * @image_handle: image handle for the image being removed + **/ +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; +}