From patchwork Thu May 22 01:17:45 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: 891698 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2404409wrm; Wed, 21 May 2025 18:18:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVLk8bcdRPvP08wpT2GHh5N6+GvzkGtoS3QTYviX5p+w0TsXaKsDtY1/Bq0hoY3h6aRekOLTg==@linaro.org X-Google-Smtp-Source: AGHT+IHPjOCm0ffbQaZ3CQ5UHkDfBE5mbdwZYG7sfpjVLdSJq7MhmVSXjYL21b7aKsW6iX6M+Y2J X-Received: by 2002:a05:6000:401f:b0:3a0:b807:73f5 with SMTP id ffacd0b85a97d-3a35c847cd2mr19431208f8f.41.1747876694010; Wed, 21 May 2025 18:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747876693; cv=none; d=google.com; s=arc-20240605; b=YbofKUIiabJ19ClIFRjCgaw2aYd2SnoMf18OxbX4g9gLVbYsDuaLioEVVILutOP2GL +KTe77gAbtDE9ZhniY9Ct97S7GIWmdtLBEgOqo3X9UkFhmKKddIFmckrWy6wgQTsiNxI 3DUeZdI4pLp8OPB9v9G1XY5WNyWQtm8VIoCz6nK3rzte0WsJPoek/EhNcylMztSm3Fze tqZpzUDhGK1aWz7VyWAX2qjl7SSwT3cVd5ypGBMHc0lt6448k69nHTCf3SFIAS3o2u2e PZSGlyP76fS2BwpEhvhHe2oaMVKbkaJHCpFh9pFPvq+nwLOMO5XpuCW0oU69mz32LCRz 7qRw== 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=IYutLCDIdafRVL2TSuzMgXBpCNm8L8Ne2g8KNqDuj7k=; fh=qX5ZZPHEMXWmb4A5/dTtVKkSjWWl13aZe4Ej/wmUqYQ=; b=QjHbG7GUqfH3aAl6/R0x8RaKlHCW58N7847Hw7YK+efo4NUgJocFUeGTGTJplJuuDF szv5BvK0EvuPdGz/jQQYAR7Bg5H8ns/8WqesYqGWkLiTXDkiFB6/ByPYnHrnxexzprp5 0hIP91q7kVDe/JUE0rg3OBzpmFJjBsoE1m2QEJnZE3dqEQ8zpxuJjFemonz/nvaJOpn5 5EwJV75oOO6IfpUEnHzWrMZoLCbjULrO8M4rQKoZKX4uP/NeAB1rVi86W+xZvQkkIYow RGuAnMWatvsgJXY2KulBX6MsU3lFfGe+g1u66i6AJi7RvChSOTSy+lQHdW5iAKmMv6PS QUvA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=cAVc1xIp; 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 ffacd0b85a97d-3a35ca9390asi10555429f8f.883.2025.05.21.18.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:13 -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=cAVc1xIp; 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 8A07682F8E; Thu, 22 May 2025 03:18:06 +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="cAVc1xIp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AE56F82F84; Thu, 22 May 2025 03:18:05 +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-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 4B47E82E7D for ; Thu, 22 May 2025 03:18:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-30dfd9e7fa8so8913992a91.2 for ; Wed, 21 May 2025 18:18:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747876681; x=1748481481; 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=IYutLCDIdafRVL2TSuzMgXBpCNm8L8Ne2g8KNqDuj7k=; b=cAVc1xIp3VdZZ2WaDe6l+dVJPUd3N1R5PGJeKlS2jD9xOZh8MS2DDpqGwclWkJ4BxM Dx+btFUIgOBnKa7eC1Oj8KhbaLPY/PiSvMk8Mqc0PkOKE9SSolQUlvZ/+1auXaLAcBvr AMHxetoK0Tm4DbOhF07NlFrKZUwrpkT9BL7lI+cbnSInGqPCEeYVmIU850se/juv6j5F PHE2UW14NmNqwSpxyxrOy6+wY+Qv82nZPhGSFXAgazzTBxvvlvKS/qMwdS1VXjIO/A5r 0frVeS5+9rgmyP5jFRZgPakIu3qm2fBSA4Mc5/aSRSOcYXbUxcx+hL8Wb0r4tZtlkojV SrCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747876681; x=1748481481; 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=IYutLCDIdafRVL2TSuzMgXBpCNm8L8Ne2g8KNqDuj7k=; b=pjwXPEJ4wQ4qVXm5q7gvvU/iLme8J+VEYDfg9UjBOeIykQZdoDrj+TvYOOA7Y62y8f V02W67dmM4Ltc4ZqGb2i8yGMbvFfAn1xrW1XFRhgc39pOCZin+9dMZ6Qlwz79TLkGcW7 DGktcAyzFMjvnIcD2ei8wsj0PTZ1yERuiKYg7sbNk+oOd15al2tmCz/+XB8Lz6x0o6AL YXSGD04+eLVVYmk4Fpwj76w7VHiLoG6b0JtPZymqXixq4YKRZYnAtNN/CA3+QtbSrgVk YSVDfQnAc4FjVgPmE+KpiW4DJ7fYsuqfRSYpnJ0M0o1g7jMNUIQst2+GgDPfZ8n3MbjY ymdA== X-Gm-Message-State: AOJu0YxaZxYWt32/Jw6vqnItw7cwpc9YAdGzGrtxzbFtgV2JC6oQMFlM xTDPEEfO+dyYcA96tJgvJqK97QCN88NwEME/IqeTp0RUtNujPIAPR5Jdpd4Xvg== X-Gm-Gg: ASbGncsCXc31hRks5YID/mqw2wTLm10+TSLtwskPN5JlEsOwzxQDY3TDn7ZsWti/rc3 kWjJ8ZhxemEogo1tdOxrKpXvugpWdLeuKSbhaEVC4efV24yjlP0IosDAIUJap3WXoA9q8+2m2lR RCVBus1YfqhzT4SNAMcmWkyWh8J7GXFL/UUAgZVfWlS3eDY8iKx/6ehs3mlUhYxYc5X+/u5JFUQ 529hn1ZQOY0icmqjI6B/7NUJkfPJ9M5M1D3NiD/Ia/THq6WwJGBUaL1nZUNSdXA6vBG7H3CHBEo LFnysm80ZW2HRdMFp6LZC9Y88DEQcGLn5ToEJVsiZ3wZSCE= X-Received: by 2002:a17:90b:5603:b0:2ee:9b2c:3253 with SMTP id 98e67ed59e1d1-30e8323cd14mr30849833a91.30.1747876680435; Wed, 21 May 2025 18:18:00 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-30f364fff49sm4680523a91.36.2025.05.21.18.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:00 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson Subject: [PATCH v3 1/4] efi: add EFI_SYSTEM_TABLE_POINTER for debug Date: Thu, 22 May 2025 09:17:45 +0800 Message-ID: <20250522011749.3498970-2-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522011749.3498970-1-paulliu@debian.org> References: <20250522011749.3498970-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 --- V2: add Kconfig options to turn on/off this feature. V3: make efi_initialize_system_table_pointer() do the job as described. --- include/efi_api.h | 16 ++++++++++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 ++++++ lib/efi_loader/efi_boottime.c | 46 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 ++++++ 5 files changed, 79 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..5a4349f8679 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,47 @@ 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) +{ + efi_status_t ret; + const int size_4MB = 0x00400000; + int pages = efi_size_in_pages(sizeof(struct efi_system_table_pointer)); + int alignment_mask = size_4MB - 1; + int real_pages = pages + efi_size_in_pages(size_4MB); + u64 addr; + u64 aligned_addr; + u32 crc32_value; + + /* Allocate configuration table array */ + ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, + EFI_RUNTIME_SERVICES_DATA, + real_pages, + &addr); + + if (ret != EFI_SUCCESS) { + log_err("Installing EFI system table pointer failed\n"); + return ret; + } + + /* alignment to 4MB boundary */ + aligned_addr = (addr + alignment_mask) & ~alignment_mask; + + systab_pointer = (struct efi_system_table_pointer *)aligned_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; + systab_pointer->crc32 = 0; + crc32_value = crc32(0, + (const unsigned char *)systab_pointer, + sizeof(struct efi_system_table_pointer)); + systab_pointer->crc32 = crc32_value; + + return ret; +} 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 22 01:17:46 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: 891699 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2404452wrm; Wed, 21 May 2025 18:18:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXPgBeDLPARarTehSc4VkbO/OAK1vFSHFEjzJ9puh7HL7gS6iiPPoqmkDZ53XdHqX4rHqJVLw==@linaro.org X-Google-Smtp-Source: AGHT+IHEdI5c+ERhI/VPj6AKUhVUQxAUbCCHuw7q7byYPhg11bA8SYN/lfXjkBj72HNNmlY1m0ta X-Received: by 2002:a05:6000:3104:b0:3a3:7351:6f2c with SMTP id ffacd0b85a97d-3a373517138mr11111164f8f.49.1747876703095; Wed, 21 May 2025 18:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747876703; cv=none; d=google.com; s=arc-20240605; b=F5D3dIQUyzQYBY9J3+Cc+HHFX/vJ5QtwUUB5t6w52LYeZGT1RPktQ4dt/F6Gdr8ts6 fvuOC1lmpYaBoaYqv3NZNYg962h4xDrQxRHeas8bcoPSEjAB+6hHaruTQuAUNRBZ2zsk 98LUz9NyebSOv8wWD+qRjICO1j3OzuKsoo8Y4NWRORkKwIjj/oWmAUQK6XHI1Li3j3n+ a6lNNYrzK0ywYCcgNcWDC4Xhugg+lCkYAcYkKCpbT/rDFP/zanU3PNWZh3yPQHyjMCzv BrHnbcNP4T3Tos8E6G72VsaW4/jvaqto1qu1TLypdLhAaCWecY5ZDe97OWYKGWBA6Oi3 fqAg== 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=ieF40tIbs22ObwJys8yA/rI/S452SE7+TAVp1vEihuo=; fh=qX5ZZPHEMXWmb4A5/dTtVKkSjWWl13aZe4Ej/wmUqYQ=; b=OeEFgSQlVgbvrAVpAOohyDmeDvkjSReE8GNeCAPo8yZEV3YZIUNTJQ2zcrrTf+Xpxz DkM/Ybqo10eAwlYNZllu7J9cwL+E9tEb8JxXsrYq3dudQGGj+UGTzUrRXlR7meUsFnHS 2+seqNJ0aececcG2JLy+UJOTU8op4l5V5099wYPDAJsTtLKLMUVX/464bWcCpoFPA4Cq 9BgEcvDSSl9y5z4C7PM/dzNNtb3vhY8Tkv04Cq3wcwP5mMxBOoX+UU67bBSRENT8bLIq kxJcUFQKdIBHhg4H+3N/6wJ0XuiBfLVeldWLxYKqjNmQ5ZSPlX1NDWalVt8pJhwdby5R 3bfg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=e8Z1VZbr; 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 ffacd0b85a97d-3a35ca4bf35si10537088f8f.52.2025.05.21.18.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:23 -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=e8Z1VZbr; 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 D5BB382F7D; Thu, 22 May 2025 03:18:08 +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="e8Z1VZbr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2DDDC8006D; Thu, 22 May 2025 03:18:07 +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-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 C65C282F7D for ; Thu, 22 May 2025 03:18:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-879d2e419b9so6350397a12.2 for ; Wed, 21 May 2025 18:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747876683; x=1748481483; 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=ieF40tIbs22ObwJys8yA/rI/S452SE7+TAVp1vEihuo=; b=e8Z1VZbro/Ny7VhcEFUM+ISQ8IkyAwIiq57RYxh/sDmqy6kNA0OZANpjTZFakOKOPN 33Mfw63r+NnkwzVT7wsbOlO202+Ksibxutd1gJY/ak2tmT3tQ3EL7c9ozlJ1jLOffWXW yLKbHLpHzRwg16rJJ7mKQEJVyCoa+Dbg1PsssRRp7EUkvEOjXq9TDf8RxpnEIL0MAdQr JxDtaC6pqjMpC6W4dyhTfDV3qCoUnIUvjonIOYwIA0x6nKUzNA0KzudF7sVnrbSArqg6 ELkdvvJ0QQCCZsEDbcmoxzEMb4teWo/02Df2k9Tg6eVOhOeTQXIWF0qeBsQw05nYXuk5 LQ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747876683; x=1748481483; 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=ieF40tIbs22ObwJys8yA/rI/S452SE7+TAVp1vEihuo=; b=wdSlZCV6Mh8FWT1AVlMnUpuaTQ66xkkVjonSz/DjTEvYpWg3aOReA11bDP0z1wHvuG EM2FDH8vayZvYJ1GdYJwp/Yg7BU4xNJpk9nGB+3RwABcRtLhB1mverag0DOWkWI+nY0e tnrjO0mJEqG9d7s59zcg7yai5UaYCtiA+GK/iLvW6zfkUw1niq870XBHuljcnyXr338x y3dZeH9kt2uJhGpi6vBj8m3yk+5vgwLzwkebZgrCQiC0jqfFuzir391wXsxXKtd/6cnt nfgBw+z+lIrOcroMxUIqiKD5lShUeLIC3svemFD0Zl62AYjb/ZxyFwV6xbOeQAMbFjuW 3CrA== X-Gm-Message-State: AOJu0YxL3vsSwMwh/AjWX79oS52LYf/qjmMo7xQb3Fub9gAZnzde9Fel xUebe+g4v0NnnDpzQIFaF6CuZ2eFUBzVfAyQqa0HtVhELOKbA+fEG1GJKTUZNQ== X-Gm-Gg: ASbGncumXB8rpYJbbzVfrpeOzqSf50yk/+H7w3ga5jj/Tm5r6zWZWeb2gTzJe8qSv1R +mP48O/Jne1uSL/dV9DKiqpFiAM3ectmncemORzZTutppTk/+ihO6RsBOOXYd/k4sm0ZKnli0kk zHpkg7PnsGucSuWhU46CdLb8YsE4+c+l78ARcLyiKEbDgMzz0xkCHlLOPOqDqs8XcO7KQ5h4f9v BLaykechYajEl5HItWm+IY/MDijrx6zN29+dEYIV0SxmaEMMrLNegz4C4M1tZZP3Fb3dMtFDWiy +B2uvDdVbBTlzDg23sMOkj1vq5Xm+bmkApV1ICvzvqQOi+g= X-Received: by 2002:a17:903:f8c:b0:223:50f0:b97 with SMTP id d9443c01a7336-231d45d67f2mr293244735ad.52.1747876682744; Wed, 21 May 2025 18:18:02 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-231d4e97798sm98796785ad.147.2025.05.21.18.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:02 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson Subject: [PATCH v3 2/4] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug Date: Thu, 22 May 2025 09:17:46 +0800 Message-ID: <20250522011749.3498970-3-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522011749.3498970-1-paulliu@debian.org> References: <20250522011749.3498970-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 --- 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 22 01:17:47 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: 891700 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2404514wrm; Wed, 21 May 2025 18:18:32 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXzkK1LE6vI/rTcw4Sevrjc3mf+n8EpM3x4Sn7dEpgZkF5RQF/Jt4N+MzzMxuYQV0+YfQl9jw==@linaro.org X-Google-Smtp-Source: AGHT+IFPEjbR2+XhqZ7FP6gE1baCYij+p80U+gM7UAh7wf9Vniyfvdt+rpZFD8x68eGcV/fbjCwJ X-Received: by 2002:a5d:588c:0:b0:3a3:7152:c665 with SMTP id ffacd0b85a97d-3a37152c6b0mr11806334f8f.54.1747876712551; Wed, 21 May 2025 18:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747876712; cv=none; d=google.com; s=arc-20240605; b=ax+2tzF3SWzZRQ8yuTYWfN6c06UxQiNTShIBT15PPddCi2608oKa4pbGte/fwWSp7i FD2e/azIiQuU5J8pLMAVCO6NewC2/7bteL3pkBMxkAkDr/veAX9YP36JUUpGvKTB62lu EJKdayBt/Zpgp69nPi1ff3JheRCCUHiKrZXCQtO1vRc5BeKvx6U6N6FoWV1hT7ds/v7w cU85+zO+m+vCrTLfjUvsd+0GVFW3PMLn3ADgqO5MfYhzXXToTTa/Oez5fzoqrMFrTJ0C 4sR4nwkgZMMxPTgfUiyNaxuqPJ4dpEIdZFIJOop/6NkOoi+JTd4346szmYj2WBfy6P+c Ot3w== 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=bkimbc0G1eX9h5DfGKuPBORAMalWiav523ma7qZ4mLI=; fh=qX5ZZPHEMXWmb4A5/dTtVKkSjWWl13aZe4Ej/wmUqYQ=; b=Y4LgMiLis/+EFJ4fA0/9KGIvFa+thUCAg/VSDDnAIDr8MEV27xzhVhWS9Riq4iGi1Z rNoIrptfAlFeQAE6kDqIO8bXZw8g9WiR7y9Sce0C6JGI8TMXgNAioi7jQDL0+m9DzqQt aXB2O2RrTgaf1dllVELD3Kp29TqDAX+CLg4zrXz/f4uIUUowfsjM05sKq4NTs9Iw7A5J 0YySRKL1itUSeirGG/BFTUjDjSsO3zydmXRVQCeuRFe87/OQR13gfPeKZH/wWgd7izbQ h6s3ApLZ5AaRp0AqljWLeAGTzTWM7BmYnzrfqQAmy5g59wJd07dbOnm8Hq0ZKCQqxLcc +FVg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b="htvCrlO/"; 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 ffacd0b85a97d-3a3626f21b7si10660008f8f.801.2025.05.21.18.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:32 -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="htvCrlO/"; 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 3C24082F63; Thu, 22 May 2025 03:18: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="htvCrlO/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 71D75829F5; Thu, 22 May 2025 03:18: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=-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-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 06E0E82E7D for ; Thu, 22 May 2025 03:18:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=grandpaul@gmail.com Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-b2c02e79d31so241792a12.2 for ; Wed, 21 May 2025 18:18:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747876686; x=1748481486; 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=bkimbc0G1eX9h5DfGKuPBORAMalWiav523ma7qZ4mLI=; b=htvCrlO/XVZtaZm6xNdwBjcMFP4EeJVHuhZ1/baKMvdSlTtFec0Ouz/lFkEmlTQ1n8 0VeOOakd0LuDlNeg1zMPyTbupBcEfB+T85HOA49VAB9XudDPpQUxaZ0hKthRrblnUzNl s6aFo5juMfKPVjTR2S/DLsbrcie462Qztkk/uoQ0Z/n2olgrDnHe5tN00mo4uTfpw3yv DQS0OeEkihT6rNC9tD1asRkr980toYaESMbKtSX7sHTDYwGBFBthz/VAqNj95YwZRajw 47GPPKX8JapmerOKrKXcdTWlYSva5LbGdj6wu5OXaeh5RyZLjgRBkAkhY9j1JOn8whle yVTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747876686; x=1748481486; 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=bkimbc0G1eX9h5DfGKuPBORAMalWiav523ma7qZ4mLI=; b=EcxXOfkIgEG9OEvxHx0+4854fvlOnieOhewKUer5LU5bIVQe0q30mezpSMUmEELL4G 7BMXNPUL+uzkbIwCsP79KrCWGu/smbZmC8RbC12LmfmXjtr4n5+d8CdQpAXFuAmPsB1m wXm/qagcvN7gyrlSD+J8Bj4bQxXjS3T47sS0vYxfoHojOGVX6eSxtpWUF8Z7Z94T4Kfv EqnuWvkpVuBZOMZb30R/hwkruvqXrCOH3ZWaD8ZDfi6rEusf5khqNtvDFuJbe6oGeHm3 ScdsqV2+KpkmpawiO68Y8bXdY1fb3DSwcMrqTDqo+P79tyhtMmCT6otJSqZU+q4VBA0N 7cig== X-Gm-Message-State: AOJu0Yzps5a77T2/H0DtFy+SLpaT0tOUOA4F1DGgzI0wuzgbUPOQCJ2o TppxCzAd6k58vpSuD9kbemJTZHQkgErvNjV42JKBddB6yGwMhphLoAtGAtiq8A== X-Gm-Gg: ASbGncuChRslLNja1DCcBIbSb9U4HIB6gRWvDPFhxpb+zdjjvOy/Eg/xHhwntwZ6xfo qjK+6/S2lxuMZRvIIJjyAHeFMR+93blE0AEN+tAtpRnW0ctvDnoL8KXcTANqCM5wDIxoQ/mQ2Pr 4H5AABLWiQ7NL+JLEgfrBklujy6refVzqXbX9+Z/2yQGuJ3juTcNvwmZ2Ohr9nByi9mF1kRqSrE cCtNV7a7pUxmSY3psfPnmSUKfWAGOJiGWF1Q7DlDYfx4zTwKtnx/rqdMhsHyvz/YZXcI4SktIY0 +Y5zsT48LLE8CLMo7fozWE+CDjyVK1wByBG1Ev0c3oafLL0= X-Received: by 2002:a17:903:4b4b:b0:224:a74:28d2 with SMTP id d9443c01a7336-231d452c4bbmr335429875ad.26.1747876685609; Wed, 21 May 2025 18:18:05 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-231d4eb9fb6sm98663025ad.161.2025.05.21.18.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:05 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson Subject: [PATCH v3 3/4] lib: efi_loader: efi_memory.c: add efi_realloc() for realloc memory Date: Thu, 22 May 2025 09:17:47 +0800 Message-ID: <20250522011749.3498970-4-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522011749.3498970-1-paulliu@debian.org> References: <20250522011749.3498970-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 --- include/efi_loader.h | 2 ++ lib/efi_loader/efi_memory.c | 52 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/efi_loader.h b/include/efi_loader.h index d0c72d0bc58..ff7ca5a0480 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -878,6 +878,8 @@ 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); +/* Reallocate boot service data pool memory */ +void *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..4c76df642dc 100644 --- a/lib/efi_loader/efi_memory.c +++ b/lib/efi_loader/efi_memory.c @@ -666,6 +666,58 @@ 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: pointer to allocated memory or NULL + */ +void *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) + return efi_alloc(size); + + ret = efi_check_allocated((uintptr_t)ptr, true); + if (ret != EFI_SUCCESS) + return ptr; + + 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 ptr; + } + + /* Don't realloc. The actual size in pages is the same. */ + if (alloc->num_pages == num_pages) + return ptr; + + 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); + + return new_ptr; +} + /** * efi_free_pool() - free memory from pool * From patchwork Thu May 22 01:17:48 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: 891701 Delivered-To: patch@linaro.org Received: by 2002:adf:e88a:0:b0:3a3:61c9:c5d4 with SMTP id d10csp2404553wrm; Wed, 21 May 2025 18:18:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWLdDBAyDY92ksr1dnYwJ1tfEP5vePA5hk/vvGq83urk9rp4DjsiWchmAG60jiLRuKKfySJFQ==@linaro.org X-Google-Smtp-Source: AGHT+IFJkhbPm2KJEFXeTcTjPuNHUROj52cwOyjv9KJIjEjzWMBqNOx0zO9QS3KLAdwIjIbnlvfa X-Received: by 2002:a5d:5850:0:b0:3a3:671f:3b8d with SMTP id ffacd0b85a97d-3a3671f3bdbmr14866104f8f.24.1747876721537; Wed, 21 May 2025 18:18:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1747876721; cv=none; d=google.com; s=arc-20240605; b=lqWpb2XxFNDk3056H5hy/kVXPpE8ZU4uQ38K9etFU03CnFjugJLaERZqE0yQlMiLyS +LkSw43vpGo/VXM0YL/7AhV1HsqRCb42p4eyEpVCu5ixDZ5CyxxGTq/fx2ED3aREXAfd p1L32RqByYApxbB9BPo8Xh0M+A6JHGRKL94XypveUo7lWtvd1ooKhmIOJkjz7aA7qafR 6rNyNRK8CeMrkBC+K2bDTcOi6SA1wkncvKsbKGX71HLPDMURJ/RurpAREhaNu0fyZrb+ I1W2qvdP4wIvuec1a9+d44MJwfkGzDtA4QDpabT6yNAh1OwObmBEiRmNgOB99EkaQ8GC 7lHA== 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=EWReCurJ+obBSDi8LPddyb2jrmX55tghlpf2elNaZNs=; fh=qX5ZZPHEMXWmb4A5/dTtVKkSjWWl13aZe4Ej/wmUqYQ=; b=JCXWn0mpiJJheANHow5/+AYacaPIbPr+ad1CkDlMafLPuiDEkEsLY8yoDrHrSNuHRD 3wCFW2llTKhvpbIVoY/Wb/L3yFyGawEa86HZlWIg+6Ymd7+EZRSYWAheZ25yLHeCKILv ZagjHEBQRKAiC3Ee2METTQRvBYMvsghvLp3iR9jnZCaBwC+ot00B7J3dfnEuruenOpcr ZjcUlOUY2DLqTh5pciVkNNFoqEEDCAa8uEhjj4zqMmbEzd0flt6Iwz/S97REG4WiKoFo 6se7eDgxmX9QJ98hSddQVOgccmTQFRRjuMMmF8XQ/nX4SE7pYroLnpHhcdCG7hNbWDJc F4wQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=fpgHbMl2; 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 ffacd0b85a97d-3a35ca86109si10410835f8f.435.2025.05.21.18.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:41 -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=fpgHbMl2; 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 8F0E582FC8; Thu, 22 May 2025 03:18: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="fpgHbMl2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3492582FC8; Thu, 22 May 2025 03:18: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=-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-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (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 C6A4E8006D for ; Thu, 22 May 2025 03:18:10 +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-x429.google.com with SMTP id d2e1a72fcca58-742c5eb7d1cso5783952b3a.3 for ; Wed, 21 May 2025 18:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747876688; x=1748481488; 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=EWReCurJ+obBSDi8LPddyb2jrmX55tghlpf2elNaZNs=; b=fpgHbMl28pQTgXzbi7yzqn/Aut4CJvxu5cB2eSGNUSQGm8X6e5BNZ20Obcz/j9/HON IZqcuzsMCrdEz6u0ShBdSKo/g//GXGtmkmII96dxzb+fDmtTVEvEKOOadDze3e4y50uH WCcvT7sx+Cztk3U1XIAaRn9dfNzcWXYO4VT/AxuDB9+6VqX7yGRsJ27GtWaf1wK5uRfy 9Z2tdOm3I/sySGB2ZZuZ0G1YcpqPQj/pJ7IcNkm4D0zZplLwavnbV9MPiiGq/ZGPpR1a MEoprGWntZvC0Hx7fhuwAZrO3RxtjnPYxx3ii6ConOTU0Pd6/21oSADWGDt6gQGZ2/IR xfhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747876688; x=1748481488; 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=EWReCurJ+obBSDi8LPddyb2jrmX55tghlpf2elNaZNs=; b=C/DdtuKGq+3UwcvMg2WYjsyVHGLp+gyKzFF6HL7NPlbwEMaXkv+BbAvdWd1e21FBjq 63vL0infeX6conFPRkXd1pkCGv4hVGZMl+uLdj103pjrL4EwjU1KVla6qaTsvw8g6W1h SCFbXf8wo7UfbqqfBUhZQVitid8+NYEGeiTQzYa9iYkqJG4Ydnk3J/lhhppaAsmlvltV BhSEYb/L4X8F9KWszf6JNo+k1ftFGuAI1NyeHbOv3nbYmt9RSd9Torf+bz0LF+nzrK7R ujaoXObsSmLhSwoTc78rs/FC/tp7gvNv5Tt2SGAJK8yUW+f0EZxpSNKsjnQSWu6W3+8I jzDA== X-Gm-Message-State: AOJu0Ywfqrd5K/aD/CcnjovM6PvBSqAJv60MRXoFsq+vAp5PgLdLTWEh JXy53Dd7iTN/bgXi4aVwh30CplSeynTULjkPHf3J3l0J/knu6nCH2RnVxPGczQ== X-Gm-Gg: ASbGncteQRomLnOjA9z5doGN6eNOHt+x0qASuuNVM9RGjPS9fEmZkKm4o8qOI7TPYs7 4PI5JULr1KxTkDQ61zFE+CpE6ILmOn+UVE/h16A5NOSMfuq8U6dF+Nwyg8t3LmW7GhMurMe1Ltz NIiSVWse3M7LfwVPqH+g9sAUaj9UZxuhFiGIAkydNClt1fd2X9dUJSFzW5pc1xXqAWx+HuYA9jL 9UYNXXbh+xGwCrqVmKruhDSTQpQpvDmqOj8KKhM4p/g3ygqt2MHJEbNKvP8tSaxnPRpThwUktZt WEx+1PKpeT0mxteVvZHBDhnf/EMkQzU1NTV/EgGiNNPBgfeKUWV9L07bO+Rx6hrPJdZo X-Received: by 2002:aa7:8e8a:0:b0:742:b3a6:db09 with SMTP id d2e1a72fcca58-742b3a6dbdbmr23710755b3a.16.1747876688465; Wed, 21 May 2025 18:18:08 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-742a98a3403sm10549852b3a.177.2025.05.21.18.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 May 2025 18:18:08 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas , Peter Robinson Subject: [PATCH v3 4/4] efi: add EFI_DEBUG_IMAGE_INFO for debug Date: Thu, 22 May 2025 09:17:48 +0800 Message-ID: <20250522011749.3498970-5-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250522011749.3498970-1-paulliu@debian.org> References: <20250522011749.3498970-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 --- V2: use Kconfig options to turn on/off this feature. V3: Use efi_realloc to realloc the tables. Move tables to boot time. --- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 142 ++++++++++++++++++++++++++++++++++ 3 files changed, 149 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 ff7ca5a0480..649bfc36f22 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 5a4349f8679..58fe3416817 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 * @@ -4081,3 +4099,127 @@ efi_status_t efi_initialize_system_table_pointer(void) return ret; } + +/** + * 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; + union efi_debug_image_info *new_table; + u32 index; + u32 table_size; + + /* 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; + + new_table = efi_realloc(table, table_size + EFI_PAGE_SIZE); + + if (!new_table) { + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + return EFI_OUT_OF_RESOURCES; + } + + /* Update the table header. */ + table = new_table; + efi_m_debug_info_table_header.efi_debug_image_info_table = + new_table; + + /* 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; +}