From patchwork Thu May 29 04:05:17 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: 893116 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e0d:0:b0:3a4:ee3f:8f15 with SMTP id p13csp340898wrt; Wed, 28 May 2025 21:05:53 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVsTT8Bb3Mz56vs/qvzFgtyJbwfilEFjoPBAzNhhNwufI+PogWMe1vEzVkPan7YTV7OJPRVw==@linaro.org X-Google-Smtp-Source: AGHT+IFZJL4oCT+JaDcyzbk91NDLCMcLc3pRNMO3rAPk5lejd/PmQeGMiCt3/E6GA5sT+J5rrgfw X-Received: by 2002:a05:6a20:9f08:b0:215:e1a0:805f with SMTP id adf61e73a8af0-21aad937af0mr7488051637.31.1748491553143; Wed, 28 May 2025 21:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1748491553; cv=none; d=google.com; s=arc-20240605; b=QkOcWk+UTE1i93k2gTlEa10h5vKSDv1KiWVeqNdR/YUTZkM/pfutGqY/Iuuxn3lKgW pKhnt2T3G0Te3xGVdvx6t/bAJnGIiwBKW33XKeaeVNPutUReCYthExk+oXBN5TN5Kd4Y /7wbrW1AkOMYjs0/3dJ+I8WptHcB5t+F0FLYXGVHC94ivZ3nlCVBoO8QC/0zHOTWRqXz UOjjzHFrPnPFfYM7RMoGRviSddt3HfiNiBRp0fAp6jucIcCI9Myvi+yQJFu01DVcEiDs O5BnjDYmluk77Bs2SNDMRyCR8tR4pJAxomrjSOJyyV6m988cgyd7B6E2YDptdUAZF7vR 9C4w== 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=V89A9UTG3YMXEddLVjU26j9qzklW25Xyyhm8bQ2C7Uk=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=I99yECYV2q/Jwkommv9ZWMOyZfXSm6QPw/CZY2D3E8Ji/B6T3hYX/6enFeTmW/OjnS IFlJ79pgyBv6v1ex1NO5hLo7HtR2lgOcUlSMrtgiEjPEVz/xgtzaHa1zInOF6VPkep8n 48Mnk9PLxjJ1rd5RIIjya0KGBkKQ+QjBmLyrCslgpjEvJV5M4b8s6WcBRCaB04Vqi9ks ofslQKDq4umZQD3fFUFis3XrZr3Ou5Jpppmow5wTcEX2uB3A6GSGy/Rhr3X8MIHK1Ew5 FN6qoHgMZ3PXH6oRGw2zc3Iu64OcDZN8g2bqw/4RaSauKnwERiJ6GO7Ljs618JmIHCW6 MJEg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=Moc4cmnz; 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 41be03b00d2f7-b2d98718d2fsi3706613a12.101.2025.05.28.21.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:05:53 -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=Moc4cmnz; 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 2729D83658; Thu, 29 May 2025 06:05:39 +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="Moc4cmnz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F03F583641; Thu, 29 May 2025 06:05:37 +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=-2.0 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-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) (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 998C8835B9 for ; Thu, 29 May 2025 06:05:35 +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-pl1-x635.google.com with SMTP id d9443c01a7336-23035b3edf1so4747975ad.3 for ; Wed, 28 May 2025 21:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748491533; x=1749096333; 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=V89A9UTG3YMXEddLVjU26j9qzklW25Xyyhm8bQ2C7Uk=; b=Moc4cmnzYRc2jnk/MPwnNLXiHVL0ngR+NmrwbXAbFWN3vJ6SuZwkD1Rc6lPgP9ql37 fEsYzzOsQ8Ptof1dKCUJI7i0lLEr3+YvmvkS2sVUne6BYKdkSrO/ZdC8KI41NyXAh1xu XUYomekPJITAZUV+qRc+hgXQlH1iUNLIUz7yFjTjMN1CQ3o/pBtvuo/KQpJApiZ/dHTr nMfYmY6RjuGdsO/0I+XmK3qPtmfOz35+F9T15CRGuWJlC+R0DKK03AfxBLQP7NXqsGV8 8u7/RwZ85H249aNGxwk7PqNoWPjzRuCWYbt5wME1ygxMhVPRQ03CiTWcYRUVDxmgH53r cAzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748491533; x=1749096333; 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=V89A9UTG3YMXEddLVjU26j9qzklW25Xyyhm8bQ2C7Uk=; b=fSWNYFXQmMq+h/13v7TZFmCIKP3fnkVsjCjtNXASXI4g/vRHSCbgk68y6z130V9Vxs bvMtYCYp+8oZtCOE6qoze+bBouxc7xIfRS6UUnXkD/inLY6Cwhzrg1uoxRvbd9E7shf4 UymZyqquTnrt6JZdz6C47X/hWdTE0dVYDK71RshDyWqUpIX7fm456V2WEAEmj5QFqhXs 3oxOGebz1tvW4xw7AJ6LcB3TNCfT5NEGzHOyLHTmfwLe9lv9tgSLnyql3n5jGQO908br evfAnuuVKn2vtG9npIO6K/UjbDUByWRCc6y8dD/MRirI284laLKGd4R2pZgTGTm6CH87 nkSw== X-Gm-Message-State: AOJu0Yxwebrrvip8v3uIudeg6tbPeWt9HLB46nuwjz7dC+NlmHKDH9rk gUb51sjDwzHo0oEJ/y/MxRP6iveQoohyz05wCM3in+tae92LjWaspGWNkNkFKcAx X-Gm-Gg: ASbGncuZqMfVZzJzW06qEhIuinVe5pcq4LqAkaAWVcuCW29HJVbvg9dhfDDCpLVdkUP AVMouqKwBmgcbA4k6nCBWzPOKznHl4k3X3IgMCpVvfnhVXQBlC9z0mt4QrMuYw6tpz+wA+P9Zer y5i5OBRfydU8HxgrjEJ1538uN755pEbD1i9WxyAuXuzygFS89qWcWGypjBZj2DfaxwH/ubbxofX /cloETI0LXz00U/RZ3dkQ+t+/QqfSpFYT8sK1M8y5OJXdm5FkHRxrmuH2ffFYn756wJVSPCjNa0 hIu8qAuRxFexy5+GHi9lcPO9pUr6lY7KM5sXhYC9KHf4f7Q= X-Received: by 2002:a17:902:d4d0:b0:234:b41e:37a2 with SMTP id d9443c01a7336-234d2a62c4cmr68412715ad.11.1748491533491; Wed, 28 May 2025 21:05:33 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-23506cd3535sm3587545ad.120.2025.05.28.21.05.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:05:32 -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 v4 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug Date: Thu, 29 May 2025 12:05:17 +0800 Message-ID: <20250529040520.3799600-2-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250529040520.3799600-1-paulliu@debian.org> References: <20250529040520.3799600-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. --- include/efi_api.h | 16 +++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 +++++++ lib/efi_loader/efi_boottime.c | 37 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++++ 5 files changed, 70 insertions(+) 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..d878fc9021d 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -71,6 +71,13 @@ config EFI_SECURE_BOOT config EFI_SIGNATURE_SUPPORT bool +config EFI_DEBUG_SUPPORT_TABLE + bool "EFI Debug Support Table" + help + Select this option if you want to setup the EFI Debug Support + Table 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/efi_boottime.c b/lib/efi_loader/efi_boottime.c index dbebb37dc04..16e921781e9 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -4001,6 +4001,8 @@ struct efi_system_table __efi_runtime_data systab = { .tables = NULL, }; +struct efi_system_table_pointer __efi_runtime_data * systab_pointer = NULL; + /** * efi_initialize_system_table() - Initialize system table * @@ -4035,3 +4037,38 @@ efi_status_t efi_initialize_system_table(void) return ret; } + +/** + * efi_initialize_system_table() - Initialize system table pointer + * + * Return: status code + */ +efi_status_t efi_initialize_system_table_pointer(void) +{ + const int size_4MB = 0x00400000; + u64 addr; + u32 crc32_value; + + /* Allocate configuration table array */ + addr = (u64)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..a6b37d994f6 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_TABLE)) { + 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 Thu May 29 04:05:18 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: 893117 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e0d:0:b0:3a4:ee3f:8f15 with SMTP id p13csp340958wrt; Wed, 28 May 2025 21:06:05 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWdRGbwZH3zqw64lwfAX2T7vzTsLyGnb41PowrbU02qMBSIN9FwCFMM5kUBqrVB6G0dt/X2sA==@linaro.org X-Google-Smtp-Source: AGHT+IFmPnrtEFOXsz5301e6uu2Tnpsios8DCIIwfhe0kTxHivHdf66w0LWtr1vA9R49XwiTqR0R X-Received: by 2002:a17:903:1311:b0:234:bca7:2921 with SMTP id d9443c01a7336-234bca736d0mr74093145ad.33.1748491564793; Wed, 28 May 2025 21:06:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1748491564; cv=none; d=google.com; s=arc-20240605; b=MEEiCR79hlFf5BctCEiXdYZNSdjxkNiSO212YzTdVbuRG2o0maZ+bPDRtWVWAPF4Rw WRx6yhm4ZGBqV8wqP3gBvtCW3gUwJax+wwGkvAPSQ4efTQISb4DhkwTtjJcr4ms0ivhV 15gfQmRQABw3Nl+jNjT243Cl/4vpmFBwxbv4TbvtRscbw++pWAjHZeKsypHpeEzTXdAK 0EXZN9gK3lvrahDLMnTp3Th/6be5dqFodYUH5HsLuL3AGzncBLKcROTExnXDMW9xeMiX JHJIB3mzTYz9KyWWDv2p/rqmhnK9SsQI2B8RDly62JURSumfbuCKG7owSSSggF3BUKxE AItQ== 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=PbQ0JgyWeTa8yr1I6otTZhj93ooreegHVhFql5kSI3c=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=fsHLr5E63m9z1FeY/mVqWRbJkEAaEFuSnbj8A1jS4nH2t6uPR898zYTn3pVytQyA6G WfPUX9MHI6xDH4XbZ/o7qDZiKTn9fvO6svaHYWhFwyv73bIb2PxfBhE+Y62pTFGsoKTT JGQz58gNChAHwGwsZJYEcKGWGPxVfC6GV1RR+KLnmqFlp1BhKlJKhzY2vK6LuXaK62Ng Z4vG1kdQna6K8a8q+4fPbZxZOx9j8VS806fuGIg5Y4WNJ9X1FHuX15QNY2yIbJbI7hu+ vCHkZy0TQsiZkXkQkNQhwK7PyJQsBQDAbsR/g9OShTUBaU0mDdW4rIvMzb+Xj2xjJO/K tinw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=f9VJeIwg; 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 d9443c01a7336-23506c58b04si8953855ad.467.2025.05.28.21.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:06:04 -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=f9VJeIwg; 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 74D5B835EA; Thu, 29 May 2025 06:05:43 +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="f9VJeIwg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 805CB835B9; Thu, 29 May 2025 06:05:41 +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=-2.0 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-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (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 03B918354B for ; Thu, 29 May 2025 06:05:39 +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-x42c.google.com with SMTP id d2e1a72fcca58-73c17c770a7so458973b3a.2 for ; Wed, 28 May 2025 21:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748491537; x=1749096337; 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=PbQ0JgyWeTa8yr1I6otTZhj93ooreegHVhFql5kSI3c=; b=f9VJeIwgrIY9GRL8BUQMZe2JLB8yDc50osmGfDkhuNq6dzAN26LfZzOTEaZ8WxYLVz irveyYrRfxqLKP36OczPCKg4VLvY/l8fsQ/MlB4w7jT3IbiYmGoJFddsRdquULE/Qv4E QsxtAqwBGBvQ1ArSq9veBBjClTFTwx7OIkfWsbYwNtcZN8MLpOWDZlfzakbUYhctzLH3 fK8nbd2OMnm56a5H7DuIJjUNwUOwsfIArha/mrVYXe/nnVcMlQ6NnPIEWWtj7mGlRUmw 21vPZNyB6rgGNRgqxE3iw7bMMr+O76ZCo/lw83bXmWrTozemt7c6WSb17N31S/C8aMbH Zn/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748491537; x=1749096337; 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=PbQ0JgyWeTa8yr1I6otTZhj93ooreegHVhFql5kSI3c=; b=PMbW/2YdETKM8S6PEIPNLGFqva8pH8zEvwBAl9CPZrarhyAykp2kobnEHkDK6zqOWJ co5IlXihYnHqGRp+bbmcq/YFXkwd1ss612z7OFBZHn9QtmsT9xIhLZOjK7s6EJoJpukU ORbdC8ZqohXrL42UK/Fa5+QORiwA+1lc89uLqzQXEqb0VivwJW2+CU8VEqljQLPScIEz zbVe65KQA+0DH8zQQy4P75jO/gk2SspWJ5SiAXAborj6Tjy/35NQn3X/nAGBKDgCtFPI mxj1hLkTJhr3ZhWAjEasI2VL2WlCKY7KhP7kB1YhB0N0Afj58JylfPcgOX/8qiL82jUV 1ZHQ== X-Gm-Message-State: AOJu0Yzqnv5n6/IgHLmZaWP/toEtFUOrRfYvYnaCxFM/eiJsRu15FYgP svQLQFeDWpSBs5hMtp32TRQ2ty3sWQokiCXu9eUt+wJ6VIrk4P0/Xe6xztpQJNNk X-Gm-Gg: ASbGncv4taKiPo0XHJiHFeArEg8a86CZ5YoQOQn+wktPO8zHJE1YeEiehcrbmSQ0LTE byFuDm7HL2UDZp/F7DO1utBksfoIguOrPALWOGQYl7Xx3rlJ5v0r3JzqzJVlyT4wJ+WQMLdovxw RUVh9LfQJTb21zCZkyX3G/1+K2o9Sm0eEqVhjhSQSHsY8RBMhcKzvOplR72cSh8fer2xjHChUO5 UCDe8UbqYGHwTwdg5Dxcf6FBIMDaLdMddBcmajLGOc4Yv3liJIyotztuF6l/q8zuWHwRtkm/Zgn EGYZJOTpYTn7x0Hq3ZatxLtFeu/AhHSXX8sXbUzRZdWjB1Jn3duMzKJiSw== X-Received: by 2002:a05:6a21:4781:b0:1f5:a3e8:64d3 with SMTP id adf61e73a8af0-2188c28e2a4mr28392077637.21.1748491536624; Wed, 28 May 2025 21:05:36 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-747affadf70sm408774b3a.91.2025.05.28.21.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:05:36 -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 v4 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug Date: Thu, 29 May 2025 12:05:18 +0800 Message-ID: <20250529040520.3799600-3-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250529040520.3799600-1-paulliu@debian.org> References: <20250529040520.3799600-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. --- include/efi_api.h | 53 ++++++++++++++++++++++++++++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/efi_setup.c | 17 ++++++++++++ 3 files changed, 72 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_setup.c b/lib/efi_loader/efi_setup.c index a6b37d994f6..e949100593f 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -18,6 +18,15 @@ efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED; +struct efi_debug_image_info_table_header efi_m_debug_info_table_header = { + 0, + 0, + NULL +}; + +const efi_guid_t efi_debug_image_info_table_guid = + EFI_DEBUG_IMAGE_INFO_TABLE_GUID; + /* * Allow unaligned memory access. * @@ -280,10 +289,18 @@ efi_status_t efi_init_obj_list(void) /* Initialize system table pointer */ if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT_TABLE)) { + 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 Thu May 29 04:05:19 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: 893118 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e0d:0:b0:3a4:ee3f:8f15 with SMTP id p13csp340996wrt; Wed, 28 May 2025 21:06:16 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVfbP92ZYWYNcD5hTAAzlRgRp+RzPX9hg+aGHvIHp7nN4abA2ThcF/1dx9BjZpBqK7Eaa9sXA==@linaro.org X-Google-Smtp-Source: AGHT+IFv0L3PByKjIxaPe0XD9XT0Ydz2UqyU0RykYcKCiAKDjfo0fZNaYBkIBtet12bI62fqQn1n X-Received: by 2002:a05:6a00:843:b0:736:4e0a:7e82 with SMTP id d2e1a72fcca58-745fdead9bamr25305543b3a.10.1748491576268; Wed, 28 May 2025 21:06:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1748491576; cv=none; d=google.com; s=arc-20240605; b=RCvMD6zWHdwmKrN+EMF14AQV31li0NWdBPY0PRbrb6c754mxweFKsFqAjhUq77G2aP yvzUdTgRvKuUxvzJOZZevaS+3RbaCK3nugMLZGZae+Zvddf1PW7d/zwoE2G7q7vz9A1t o03g+423p2laSoa3+4Ko9wLA73Lcg8EoieheHBwnG+aEYdZWyBt9iJ9ayCT9OeqfdU9o 4tLkKqg4KNpNVyXMaG5luvpIXPfBMDGH0CzK3cw2TIqsnA+kbyJ+T/aBnVrfUUzzXtgU qnYFeD26h5MUGt2PaThcStIrhYBRfr881IAXPvhsuTM6O8W698fwIX0IInCrjJOj1oS5 f22Q== 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=lN3MX72jbyqbCVfLMFJ69d1E9UCtGFQlbT3Doou6HtOCZ0RMWlPyXZ69AZ1q73WvaG Jt5nquKzYdtsMavlqBiBp/tUeYRQ8no9LGQARngpJ95XiXHMWh+Wc9D6o44ftYllkSKL ULdbWuxmg9s4HU+zjmjTmP3t5rK6fPfcm1tvgSb2LlsGdft7A9NrDgPlBi7iK4k1MT6g KwfsFRZdQx0WuGiZjEEBnt2JKI8jgPmnMHOg5KvPgYEy6L17r8sHnuF9reqaUOzazRnD LG621i8tm7dHLLMZ6iBjytfezeiwUJtzfoTPJdBU+3YQ1Chdw28yLi2Ey03s5/cpV5Hz f0WA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b="fepik/v8"; 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 41be03b00d2f7-b2d98718db3si3750431a12.90.2025.05.28.21.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:06:16 -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="fepik/v8"; 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 CD9EC835A5; Thu, 29 May 2025 06:05:49 +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="fepik/v8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3983E83641; Thu, 29 May 2025 06:05:44 +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=-2.0 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 E3BB38354B for ; Thu, 29 May 2025 06:05:41 +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-311ef4fb43dso359429a91.3 for ; Wed, 28 May 2025 21:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748491540; x=1749096340; 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=fepik/v84yibxdYIVSM8XT9/Til9YK5yYH7FV1GoQuh8DiM41FeB9O3puoxmRywstC r0pm9Fj2G8l9YYQzPoVPfvAi3f7TEffNtzSOOd/eJi2pLU18fs1Vj8WNbMJqPiblML5+ qlstCqxaQ7VINoFR1SoURnXL6gKhe2valEWmwvdPjzCt51ingFF64qrt8Sf0upCbl+u/ 4QUmIrVef+l5av7pwbbqRDU4U2suF4mF7xS+rtI+ef+ao/cAVdqwqvdlSKpiK2P4vIg8 wUoZyuQ81gDQuC8FMc7FQHvbZ049PLy3XihYASVI5HoqKoMONgHbzUvDRtDYNsm1C/Xw pibg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748491540; x=1749096340; 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=Ok+ljNZ0u0qspeYccLC2KpphusnX2bwgbrqFMNYjpgcIq8NzI132y8HF8nIWN3Foaa nPH2Q+3H/FtXipCc6+Qh7+8gYB49FdWHYvwmY+ZtAtOWE440q0nT0bIjAuAWTJIMDPGU smFhw0oVvRtKQewEQun/v7CctPxoIYyWm6waFi1xQrqUu2zVQXhodcwl4BzGdsMBMZCG QwsagtZImXidO2EIClT47CgfZM8wVKtciwM8H4blwhyvs68PPXK/f7DsEfW6cJOp9+ru KsY+65KKwabcMr6L4FasICtQscPeZds3LY7lylXFD4BVVvVXl/S+MfGhqb00qZtnlJjP LKFg== X-Gm-Message-State: AOJu0Yx8m9QZI2sFac3pYYGhUloeH9uUtQ371YDUBJ/th+Cu5QakhVPS P+ZRmfGB6z4ExTYU/Q7gwEIs2B7JteygNDLHurAG0GEg37lBlZSvmlG21pjSEzqA X-Gm-Gg: ASbGncsm5moPiIvr95cWvMVSXq5WjWtlTHJpXOoRAj2XUPryp5WKsG6P93h/h5CdqSJ rCrSQFfOrb0COM/jfLo1DphKwLF6BVi+bKqyZMQso3O5Unbb34L9tY7wwgd9XEyrAjgYeaaLWUZ CTnrN01FQ4VzwPAw/+9kdXZ9XZUkvczxiCra0lPODxdT4HQNoL9sB3+zQF4fXYKYrL5NHS+85ox L0GbdHPSxS7tgATRbdczQ+5lDRIB/9yDxw148kBSdS0OSkKRIgMrw1cCdak9Pa1GNWGh2hts4Ir uns2xtQpokud3uU3lC/QHgNcyXcefHf+7WpaRpELqvkVb3M= X-Received: by 2002:a17:90b:224e:b0:311:df4b:4b7a with SMTP id 98e67ed59e1d1-311df4b4dcemr8154307a91.29.1748491539750; Wed, 28 May 2025 21:05:39 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3121b71deafsm504158a91.16.2025.05.28.21.05.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:05:39 -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 v4 3/4] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory Date: Thu, 29 May 2025 12:05:19 +0800 Message-ID: <20250529040520.3799600-4-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250529040520.3799600-1-paulliu@debian.org> References: <20250529040520.3799600-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 Thu May 29 04:05:20 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: 893119 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e0d:0:b0:3a4:ee3f:8f15 with SMTP id p13csp341031wrt; Wed, 28 May 2025 21:06:28 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUu0cfFAcHRRj/QZwWd+qbzbxsH49X9y8fIu/4nS3DHmkn+qFu4VKFked1gZvCGM64ZZsS7mw==@linaro.org X-Google-Smtp-Source: AGHT+IH5RhLqIsogu0RONbUWOjgCuRXqTTswgrXetn/QNC1SZ/6wx5eWmienI3wzbP76OmmhVD5d X-Received: by 2002:a17:903:4291:b0:234:b44c:d3c8 with SMTP id d9443c01a7336-234b44cd695mr79699125ad.37.1748491587864; Wed, 28 May 2025 21:06:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1748491587; cv=none; d=google.com; s=arc-20240605; b=eJOcNr7Z7vYmDTXX/5GdnmR69GqQuotaTpWyFc+xD3LqYY5UBPi5tElrEEFqB+tigF UW8C+kB5jmUsP5ZKXCKw8XKDX/LVkp9Z1SSuQPVmpONsFTrCRQpI2kpdK9E8x53YkjIF ANa9cA+quxQ19n6ALQ+CSZTYF2g2Gki1wjiKjf7+9QOq1uVLw/I/6Ba9ijqz9aK2JDY6 AC+2hw/PZ2bq9K0YRswo569Gp/kimcEXp5KdkJRTaU2gEB8ZT06QsUgKJpDIsRvHI5kB A8xUCgZ53Qq62Y5h8iqLoIto+Ex5EDYJOTlAEZa5IYaIKvlQfAHW900bqvy6RIWd3awb 6MbQ== 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=0wdiZK9jFbwRUV4k4Emk7tY1Ok0I3xYosUxumMHZR1w=; fh=0OGUXlCirN47PXkSyTSV4KNpm8J6ckvzictniQ+qXW0=; b=eXP3JpLCSmynV5PObY3XghzELsrC+CBGxJRv0NI487KErC09Ad0rEDROBwEE+uh458 0kqAPoyOhmpilUMY/ky5rvpvx52vurQMKwJutxgZF2Av+7Mu4xKcYfw6h0JIFS+5QWm+ J1xszObHLgo5wjE2MQ29dVx8+/aSGk0votimzMTycSaYNijhV3a/VGtRfWWEKM7g5Bwi EUcwQfiW76sUfbQkPZzTOQ+lqrs+LTSnpuhnPfF5UQoc09+/fVp0FvTf0wnuaCMMtdsp 4pzLkm0E7mkXXwaEFVsNpIHCqr5VGjXI2+Ygmjfu4ICmEvPLTyvsWvZcZux/p/ifKQ/V DZIg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b="B/49Ka93"; 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 d9443c01a7336-23506a39baasi9658115ad.100.2025.05.28.21.06.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:06:27 -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="B/49Ka93"; 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 2D815836A9; Thu, 29 May 2025 06:05:50 +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="B/49Ka93"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A2B078365E; Thu, 29 May 2025 06:05:47 +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=-2.0 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-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 2D128835A5 for ; Thu, 29 May 2025 06:05:45 +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-pl1-x62f.google.com with SMTP id d9443c01a7336-2347b7d6aeeso6636525ad.2 for ; Wed, 28 May 2025 21:05:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1748491543; x=1749096343; 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=0wdiZK9jFbwRUV4k4Emk7tY1Ok0I3xYosUxumMHZR1w=; b=B/49Ka93UX6r1PH+mCLAAl0vLhDQ6POBZhJgsT4hhPhdmEGZy2KJdvx/sZZ/q2OFD2 en6GjqytSPssDtTgtujAJmOwtYYkMhki+S35Wuq0sfuKEDQkecoXHcOHNHQIv9dIdMfq rlbzrVcYb5P2AbedpWT47DXhMaoDWTHxvce6BM1T9otUULY3ds/GTNjbabk4pBbGZPWI FFyuWxPnIRAHMOhquR7dmyVWjPk2ia/cc3hcAM4u8IfEkPA2jPoAjQKW1/GGEPngA5sP gF7s5lXVmR05G7/ebE1+EEUjUC/l7GPRZeqhvBTxxpdUeW6TCafZWmn/i61fSDlS8GyQ fAiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748491543; x=1749096343; 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=0wdiZK9jFbwRUV4k4Emk7tY1Ok0I3xYosUxumMHZR1w=; b=pxbcGpYovLR+jgg1adCVSg1uHwrNLPgvl9tZ45g5Tawo62Og+1MX4KlXZ/AxS9ay6O uyg8NR5IGPZgUU6di97rUnpqB/8kStZpyoS3ajuxJ17CF44c0lsAwwmVakx12nJad/ug GIrUuVnYZzpAMpqecwXZ8i1cub4W7U+JlagSV41Nrx8Jwc3qFnIpX2tgSaUa49V4o0dR RZ4232N6QvQLm+UxbE+OC2+yis7lud7F/qpe26BQginRRQ15ksPtW2UfTR+frYwFecLU DB04KL95QLA71h/qLSuaV5EDPq6aFvryjHvRzaGHd+V6jdexnJuALfKQNzHDjncnHs3j aLBw== X-Gm-Message-State: AOJu0Yy8sKZm8NBvaFfE6fbH3yyXDcF7r/OfMvnFBILCl1ZEd5ds0mfH WgM5kZtAOhebuvx37VXgRiO1HTQr7kO5vD2ABynXaN8fbpgim16K05UMRIXYgTmU X-Gm-Gg: ASbGncsvoiRywQUFTw6tnpeWHZf59Hw1v0DT50RFw8GPe6wAIxeIwSxT4AElVbHa0Gg tTO6VQO6SXwB2vatWq8yMs7tJKo5OcBdxWbRo9+uAZpUJW9J9obmJI64kKO+ui3pdcgAMBLLutS c6vbWqKSVFI+qRM5CyeWFfgNC0jVK81K94YoAZdcNl2BBLrrtUvWx8CtljTZ89ihBLaBScEjFex MMHFofxD6KQgIQdD9fegJfPX9464T94+Dx+qqgDcad9OXnAsvomzepdT2UDF+c+ALFIFqb3yv5D nlxdbfpbpl/rP2D7g2orLCpKcyIABiE9d/hnGIGDV54U8RI= X-Received: by 2002:a17:902:e5cb:b0:234:c549:da10 with SMTP id d9443c01a7336-234c549dbedmr99337535ad.47.1748491542798; Wed, 28 May 2025 21:05:42 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-23506cd75c7sm3611195ad.113.2025.05.28.21.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 May 2025 21:05:42 -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 v4 4/4] efi: add EFI_DEBUG_IMAGE_INFO for debug Date: Thu, 29 May 2025 12:05:20 +0800 Message-ID: <20250529040520.3799600-5-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250529040520.3799600-1-paulliu@debian.org> References: <20250529040520.3799600-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(). --- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 137 ++++++++++++++++++++++++++++++++++ 3 files changed, 144 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 16e921781e9..ebd2dab6e41 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_TABLE)) { + 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_TABLE)) { + efi_core_remove_debug_image_info_entry(image_handle); + } switch (efiobj->type) { case EFI_OBJECT_TYPE_STARTED_IMAGE: /* Call the unload function */ @@ -4038,6 +4049,13 @@ efi_status_t efi_initialize_system_table(void) return ret; } +/* 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() - Initialize system table pointer * @@ -4072,3 +4090,122 @@ efi_status_t efi_initialize_system_table_pointer(void) return EFI_SUCCESS; } + +/** + * Add a new efi_loaded_image structure to the efi_debug_image_info Table. + * Re-Allocates the table if it's not large enough to accomidate another + * entry. + * + * @param image_info_type type of debug image information + * @param loaded_image pointer to the loaded image protocol for the image + * being loaded + * @param image_handle image handle for the image being loaded + * @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; +}