From patchwork Thu Apr 24 20:19:24 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: 883961 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp3631430wrs; Thu, 24 Apr 2025 13:20:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXkczbMBOBdYCnRJGYw7cEd6ir1KanSwQYg+LjQ35LvjXd5HMqXsFoOQOutmq0MZlp7Fyb19w==@linaro.org X-Google-Smtp-Source: AGHT+IF0PmXIgz0cC5OPuNzhrXvqwKMqTxi2V4FoRkfoF8gRE7coV2ZVohi1mPMEFGONanyUVGbK X-Received: by 2002:a05:6000:290d:b0:3a0:65bc:3543 with SMTP id ffacd0b85a97d-3a072afc393mr510382f8f.35.1745526004621; Thu, 24 Apr 2025 13:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745526004; cv=none; d=google.com; s=arc-20240605; b=Ql+IeA3Hy3SZeh1+WEKj0jkQS62s6P9G3ICLcmrTMPgeJVyn6iSQTM4Jj15wpe4NSv 08DXDb3of+Tqc+/pNM4ojXBBaHZzgWaVdb/whCL6KFBJRAsN0XSwzA5R+YgnmNTSV6mm t9I8vhu05RAzs8qFzKqMYVfyCrMPfSc+d7swOXRPkInKtMLzw2PBci/jV/+llY2QXCId 85A4fee+Udrk8IqF0UQvTFQ9JIi88KR0v8aewtZGhouma+UiHQPiJpYvudTLdJC6cka3 HE961DzwjZXqSQeJ3x8SXrUMldGYzbpQqj+TiWQYAY0rZi/jN70CkwvJBUsmwgmH2RlY thtw== 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=j7CUD5mTR6NvTEpbFCKEGhRSLhxcJ1slxKlB6mjaUrk=; fh=yXVQQdlQRM26TTYMoA2yrv//F921MlR4o2VBZ4jl39k=; b=ItPUaHNMqRYZSUGDVA90KhrB7cb0qjg3b/5NSNCpRm7cJlzQMvttCp5f0dchQXY/Gj t8sWpCQxaoCFDPkGHcP2Hr4fjpA/D0BJil65nMco2jdbA2572BVJ+ejFznHn/ozG/M2f xPIRuApPqKV7T5+JoJKUYcrzpbLdJL+v3LG/b+i4uebB31RDMUvrUt1X5SojkVQPUssA CS0Uqoc7uwo/Zm/vKznp77Rz2bCZzduohovhSo8nsqj+nkTF6gkgM6aummwpg5V/iBzF TCjAp5Y0VVp5sRGrGgZIOCuxX2nOI0tnB6+9wFPMxKw/XGwMdxdgwDnMsQsmXeYf4hHm V8KQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=US544qc1; 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-3a073bbf2c7si172047f8f.0.2025.04.24.13.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:20: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=US544qc1; 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 636CD81E14; Thu, 24 Apr 2025 22:19:44 +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="US544qc1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4041881D5D; Thu, 24 Apr 2025 22:19:43 +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 D01E58056A for ; Thu, 24 Apr 2025 22:19:40 +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-224341bbc1dso19547955ad.3 for ; Thu, 24 Apr 2025 13:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745525979; x=1746130779; 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=j7CUD5mTR6NvTEpbFCKEGhRSLhxcJ1slxKlB6mjaUrk=; b=US544qc1ShyVg/qrgx9YU8NJAbpUnkTgfaMHY8eEFuqQAoQjNdGq64u5jZ2DSU/CR2 4h7Gi4PAwu3rkQXzH3OlhDPmo4l968ErAfjRySVrDra3mn80EOzI75KjD4j46jiEX3KO CPFaNNnSAZS8L+bmU16x/Yo5+um6JJMDVN3UDdPDpB0Ziimx10s0BHSP65JIfVUCb8dN I6rwqAY6m0h5dSih1uqbJaRcj9eQMSqvyWDYK3TbwnTMeOR0XAhngO1m/ct1Ue2oAdvV 3BNaoSuY7wmknz6xX5RCE91Cim4KCwY6s7SUK6LpHz1sDroQ1DSjEchAud+pQENLJ6Uw 4nXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745525979; x=1746130779; 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=j7CUD5mTR6NvTEpbFCKEGhRSLhxcJ1slxKlB6mjaUrk=; b=PtQ9TTrd2Gq159TZdJ9upUo7TC/OwO9YWR/LfwU/U5g5RXTLtaxN5oI3WRHMCxmEtD dYg2yKRRTr12vtq1PA9oTNsLxpuOP9B9t70aX3uSnh2qvetMtb9ERgVLTg7AGVxb3eWQ NKKUrXuln0PdvqSZDhtpx3GKFTs3mvYbtj/L9imNGpWdJneX9JxLG5fzdtpJoMVfw1ed Wmvk+4T0NSSr9Tug7O75Jz1B9+8hnLFg1oexaM0WKnzTjBq9E1U2DH2Ow3zrCLU3hTJS kUQ9dmBY1waQGZ+MxIblubG9gmWYlFBhiS+rVq2ZNl9stiYMBzq1tVFQUhUT4UeYziIM hxAg== X-Gm-Message-State: AOJu0Yy5+apN84WVWxTmpsB+2Qv29jnTeHOUj5chHrBgXazJWDehuQF/ tizFCTiCAHOp1vVHlGYbvx11Myo+s3QN0HMFGujk27Fk/sMy/UWCRoRgQg== X-Gm-Gg: ASbGnct5jQL/5dvbHjvQOTXa2h3RS2ZquYPDaNy2RaSS+0exO289S2SP3LwOn7X8Xcl HJNn3pMk8rOn3WgJZ1RQlNvgzl9Hawt/691tUM2wE6FsuseIWEhkHKMe0muQa5eJywhWdjJKWxT raCwMUn4CddCiN/LRgFKHaBv8MDWgGZ2nl/sYtUPibspNdBBCCBGXD2pTtSUk6DuVGmRczY+gIF iIUljNcJ3X13ckYHInAXHkiLwJtlb1/bkoN/9zm+Lqmf1YnBLmFbA0aSOIahAQGPR6a3hGD0I7O hgJOV4Mp/87iOJYs/oVqPmzqTdwpMtIo1GQZ X-Received: by 2002:a17:903:244f:b0:223:f408:c3cf with SMTP id d9443c01a7336-22db3bec08cmr60144795ad.21.1745525978830; Thu, 24 Apr 2025 13:19:38 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-22db5221cbbsm17868255ad.221.2025.04.24.13.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:19:38 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas Subject: [PATCH v2 1/3] efi: add EFI_SYSTEM_TABLE_POINTER for debug Date: Fri, 25 Apr 2025 04:19:24 +0800 Message-ID: <20250424201927.2027257-2-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250424201927.2027257-1-paulliu@debian.org> References: <20250424201927.2027257-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 debugger to locate the address of EFI_SYSTEM_TABLE. This feature is described in UEFI SPEC version 2.10. Section 18.4.2. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas --- V2: add Kconfig options to turn on/off this feature. --- include/efi_api.h | 6 +++++ include/efi_loader.h | 2 ++ lib/efi_loader/Kconfig | 7 ++++++ lib/efi_loader/efi_boottime.c | 44 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 9 +++++++ 5 files changed, 68 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index eb61eafa028..5017d9037cd 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -259,6 +259,12 @@ struct efi_capsule_result_variable_header { efi_status_t capsule_status; } __packed; +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 1d75d97ebbc..370bc042f70 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -615,6 +615,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 d4f6b56afaa..94a75981389 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -70,6 +70,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 5164cb15986..366bc0d2b1d 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,45 @@ efi_status_t efi_initialize_system_table(void) return ret; } + +/** + * efi_initialize_system_table() - Initialize system table + * + * 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); + + /* 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)); + + /* + * These entries will be set to NULL in ExitBootServices(). To avoid + * relocation in SetVirtualAddressMap(), set them dynamically. + */ + 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 aa59bc7779d..6be23ca43bf 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -259,6 +259,15 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + /* Initialize system table */ + if (IS_ENABLED(CONFIG_EFI_DEBUG_SUPPORT_TABLE)) { + ret = efi_initialize_system_table_pointer(); + if (ret != EFI_SUCCESS) { + printf("EFI init system table pointer fail\n"); + goto out; + } + } + if (IS_ENABLED(CONFIG_EFI_ECPT)) { ret = efi_ecpt_register(); if (ret != EFI_SUCCESS) From patchwork Thu Apr 24 20:19:25 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: 883960 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp3631397wrs; Thu, 24 Apr 2025 13:20:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVlI2RMHNM+/BmuETUaahb7oMevigWibVjfJfSFv4IYl50kVA79CATJXZsNBwUg0aLFN04SFA==@linaro.org X-Google-Smtp-Source: AGHT+IHBczuX/G36nhdKipE93eQUdPuENQ4RRd6VzXOIJmVDKKsiKVBS8CI7+54i1CNvtqKw27ao X-Received: by 2002:a05:6000:1ace:b0:390:fe8b:f442 with SMTP id ffacd0b85a97d-3a072bfab3fmr580489f8f.54.1745526000252; Thu, 24 Apr 2025 13:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745526000; cv=none; d=google.com; s=arc-20240605; b=K8MEXk9ZtprRu7Q1fiD9kseT6uwkgj4KvbNxpSPMaUyOhwwHi9Ehz4v26nSLfA267e VVXAW7BRmeHqBRKD5GjRH5UYnwxpp5qihC+lX4ay8fAIrnHUsocOxSL9/UQZFLKh+Err NDbdHN2874R3E4ehWDLbJC2EFuDBsinfsii5Kn4Yp8tIjxdBjF8JqDHFo7y60PeDLBtR N4RXgfEq+yhQKAa2M5tUYn9kkwUXZ1vHdRmyIp3UKACjneacYPJgPv4bQH0krnMLD/rZ 0dWCbb4JE0Z8u4bSKcmyg7ktzn3iAfWGsKW3V/akEoTT2BKP6CN0PIBQiXdg64/QATlZ xqvw== 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=jSX/9sQGbKqDWDDqeHEWYA9ns/DUT3sg+GNNs1iBoWM=; fh=yXVQQdlQRM26TTYMoA2yrv//F921MlR4o2VBZ4jl39k=; b=VHwdfZ+qAxKfIQk9K2SmhVTlgCsxY6RW27sb1GKiUmF32S5DWpJ/ePjD/2Q+IZ2sVI SdP1bpJWxLQ4L//GBgjyBI7soJns3Mub6hQS/0PQmOVAX33w03B5k6UM5eifhSFEUqb5 wj6Yob/XDUANysl2vBj+UNRqzg3yy+HYiN62LI8H0Xp4jJw6td5K+in0b7OrxIV27Shp UQ2B5rMFomnm6ToEpLv9A+whSmOkEcHFFU+8f3PRZpmLFMr3yLCEIoH6URz1uL1pK6+w aLvck4lB9leMU1un6o2kvW9jyvGZgZessIvatFL03I57kvidWOol7Bi1l6iCLBM9V+f3 8hWA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b="c/nfdVzH"; 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-3a073e5634asi122960f8f.491.2025.04.24.13.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:20:00 -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="c/nfdVzH"; 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 AB14282064; Thu, 24 Apr 2025 22:19:47 +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="c/nfdVzH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A2EC281E25; Thu, 24 Apr 2025 22:19:46 +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-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 425EC8056A for ; Thu, 24 Apr 2025 22:19:44 +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-x1036.google.com with SMTP id 98e67ed59e1d1-306b6ae4fb3so1614702a91.1 for ; Thu, 24 Apr 2025 13:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745525982; x=1746130782; 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=jSX/9sQGbKqDWDDqeHEWYA9ns/DUT3sg+GNNs1iBoWM=; b=c/nfdVzHr1oHWlrQ9RkLKcztY0wu0WzfEk1y6j843mQ5ICxwu7ZpllFD1qowTvw0Sc A3fF/i/aClQHgUU4VCURIw17ewYGsuVMrkVFLZ6grBN59RjEfizC5TJs+ryrVmbK/E9I kE2LWZzg35xrOd1Itz+PujMpxwYV+6P/JmOQ+j1UtkZyGznGAbXV2PRFPh0h1/dBoA3S tZxl184LuGMuapFjlYbF6Ae/YhjEW32H5Blujjwud5ZOCdOVxJ4xVfx3CtUCQMyHpUKc ozmkRYzCWJhlz3vCMosjKI3egEwuzJvYB3A0C8Fewx+jPf0Vafp6EO4hXqUhq6TD44u+ k6JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745525982; x=1746130782; 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=jSX/9sQGbKqDWDDqeHEWYA9ns/DUT3sg+GNNs1iBoWM=; b=r6lNujCoyQjOvW3IgVShnUo5gIbd1err+WPvWTTaB8LyzVuZ4/GxQyRe/m8H+VbyRp +0fyHnM5lxzDWtjES0YK6UmFWdic12w8+u/tpk4yAFYBZxgUi2C2mxZMvDawkjjF44fe Ucxyw/MWWRAMI7MTG19eoLotDUqQXgJM9L9fBF8JRmela0Yry6frjcDGg6BuAy2xvoL8 GvN6aPB8xh7KiJGoum+XdXP8ycpld78wJI9r+ndeb1kvwmXpO2AP5PXGaKi1a4aC+Oli X9yPs+ehxbL4SlBnCtD/DR61QR8JanJdDZ5FDxcM9Oj4TpyTHmhoHgq5tkCrv/P1V6Ic 4CnA== X-Gm-Message-State: AOJu0YxpHAI9aiDSQrh4DphAEQ6yy8VyC1d0MIZp0BMziD02OPiHP2yD O9se6OyWCJWZYvNIcZ5k88La9B1ssrZy2YcJdUNGSyx4ZyDfxDMdRRwuqA== X-Gm-Gg: ASbGnctIhXsvfefFN41oHEVYTQ/IuHTasi8c+sMhYjnzicBwT/tLktp78J5kAbd75bl PJAI9Z+0CGHfbUtWSx3j3gE3nHQCtQR543jgAD/PyG44zPlPo5p13dubX99I4eU2kAkVQvVzAYr OlzRsA7dI2YIgc8+veI+soStRlRkikE4A+Y7HjZUMKyovVZsB0wTBEyu6BA174ZfmGfT0wCZmnN 2ySegvvl8QxxRx2w9+9l7k7wcpxLax3OuBV8s0EuqTCIDHVIDFHvJAtmaEtyU6a6Sw+rjFPMIQU 6B+NBvfzdmoKGy/yetgCgPp7j7Ic/dJk3SXv X-Received: by 2002:a17:90b:3851:b0:2ff:58b8:5c46 with SMTP id 98e67ed59e1d1-309f5534319mr1385606a91.8.1745525981643; Thu, 24 Apr 2025 13:19:41 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-309f7754d52sm39217a91.19.2025.04.24.13.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:19:41 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas Subject: [PATCH v2 2/3] efi: add EFI_DEBUG_IMAGE_INFO_TABLE for debug Date: Fri, 25 Apr 2025 04:19:25 +0800 Message-ID: <20250424201927.2027257-3-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250424201927.2027257-1-paulliu@debian.org> References: <20250424201927.2027257-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. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas --- include/efi_api.h | 24 ++++++++++++++++++++++++ lib/efi_loader/efi_boottime.c | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 5017d9037cd..0f4245091f1 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; @@ -564,6 +568,26 @@ 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 { + u32 image_info_type; + struct efi_loaded_image *loaded_image_protocol_instance; + efi_handle_t image_handle; +}; + +union efi_debug_image_info { + u32 *image_info_type; + struct efi_debug_image_info_normal *normal_image; +}; + +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/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 366bc0d2b1d..e2665459e44 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -4038,6 +4038,16 @@ efi_status_t efi_initialize_system_table(void) return ret; } +struct efi_debug_image_info_table_header __efi_runtime_data +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; + /** * efi_initialize_system_table() - Initialize system table * @@ -4053,6 +4063,8 @@ efi_status_t efi_initialize_system_table_pointer(void) u64 addr; u64 aligned_addr; u32 crc32_value; + efi_guid_t debug_image_info_table_guid = + efi_debug_image_info_table_guid; /* Allocate configuration table array */ ret = efi_allocate_pages(EFI_ALLOCATE_ANY_PAGES, @@ -4077,5 +4089,9 @@ efi_status_t efi_initialize_system_table_pointer(void) (const unsigned char *)systab_pointer, sizeof(struct efi_system_table_pointer)); systab_pointer->crc32 = crc32_value; + + ret = efi_install_configuration_table(&debug_image_info_table_guid, + &efi_m_debug_info_table_header); + return ret; } From patchwork Thu Apr 24 20:19:26 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: 883962 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp3631465wrs; Thu, 24 Apr 2025 13:20:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVJHxe/L20/R4WyUj6DPUZpuH61/jfFagKz1k+reNhw3n7heI2KA3teMhm7PbvDFOUk9y1c7A==@linaro.org X-Google-Smtp-Source: AGHT+IFjCx4TyYBemgCvzL+0oab76h+JoLgRzk/MkotEAEHHB1Z5ls4W0dz3yLL2RjNFhvHSYAAb X-Received: by 2002:a05:6000:40ce:b0:39c:1257:dbab with SMTP id ffacd0b85a97d-3a072bfa569mr540275f8f.59.1745526008754; Thu, 24 Apr 2025 13:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1745526008; cv=none; d=google.com; s=arc-20240605; b=GHOxb1UPl8Tj/Dy0OpGbmPkLV12MmIcCEtNr5/4SbImiC/hH7Ezg0c2poYmfw/c41+ NvJ0nU8EF6W6IiyALFDq1jRiByPBnysD9LOtpcSXSx60x/Bw0CT9qMOXJR5oMgiDH2zo fHt5tLAUKglf+slfELUpAZE/xmVd88jrA2OQcxAmzhxIuv0zMK6sEjg1u9e/9nIDOSUn erklZrL+OjRBlzg0EPtn+n4zsE0tmh5uJvhInHdlc4boVorYuaTfzj7/MW3kgBg2fCZ8 ZFwDTE6r9Zkue68Wu+jgbjn7vot9PZ9MRWTdgELQNH7UXrpkAwMo+AQNJrE91txhPL2F m5/A== 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=EqJ2/jVSMdtrxFKacJweFgaP6e++72nWfTIVTkeRVss=; fh=yXVQQdlQRM26TTYMoA2yrv//F921MlR4o2VBZ4jl39k=; b=YMiZsNa2tAWAibjJ7ABQ9Hf+VC1lHqfYwjmljW3yMFFsrSmiCeoejhcxmIx+cntEpD w3iI0Z7EmZo9PgElVoQOnWaxLgoDxvHxWAJy+4uux2Ke2G1RwEJLcS3aAVxP0NizfXge DMBuvbQxwgMkTXV+Ghoq+iCEt7U79XtI0Ck6PISfTcQddYAf1yZppwmk7J0e1/OkJ/qL MLOhElxdTLZN6mZOtQ26D/3HZROGcOoEWxiyS6V94U32ceTZUjKiC6UVbIMyEa75a4n8 +yFxg5NrCMAZr0HU8AM0OGS25oPcrZLYVYp2kInlkkNWiY/UkOVjAXCstuq5BnnJqSUv JRgg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20230601 header.b=BsLNVm0k; 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-3a073c91f8fsi150302f8f.147.2025.04.24.13.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:20:08 -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=BsLNVm0k; 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 020FC80BA8; Thu, 24 Apr 2025 22:19:51 +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="BsLNVm0k"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3AD958056A; Thu, 24 Apr 2025 22:19:49 +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-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) (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 C1AA081D5D for ; Thu, 24 Apr 2025 22:19:46 +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-x430.google.com with SMTP id d2e1a72fcca58-7396f13b750so1614560b3a.1 for ; Thu, 24 Apr 2025 13:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745525985; x=1746130785; 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=EqJ2/jVSMdtrxFKacJweFgaP6e++72nWfTIVTkeRVss=; b=BsLNVm0k7fioSNQw1PzXO+qPzNOWyvgzzYuv0gIKQOthlrUST+M/7BFnOZxYdmMMOs y4hI3zopBmzGJvtJfWSyKz7PF2E9YMu9Wnkk7gBchlkvIL0ef5sPqfcgUEOMzjJfqaNA TKssS5/wHAlTiNBILHETyk0dNv3pSDI4UqxlQ+D6KwEKUn1m5tcHPp/TYdtdvBEAyEy7 Ul2JFCdJVVtp0X2lsesekfFJ8Q89rtIK6IBM8eYvuO6sBYi5UVMbrDa88rck1U3Vo6FF 33XNhx37DOyy106zfjNrJS31RHYHZYdodQouXe2wjm8OsMjTCCK4VrvX8Wcn+udL8X1a a4Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745525985; x=1746130785; 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=EqJ2/jVSMdtrxFKacJweFgaP6e++72nWfTIVTkeRVss=; b=C3iEEeUZzKU7NmTPUEvNoepxSMdVIB38StHM5wkXYbZYSVJ/Xa3GI6dZvl8jWGns/u JWeQrfxJN2kR62VstVxzQPq2MyyOIw51ml6zRUANTPHtivlf0HdFaY4OPU+6w0VQnVP9 iJyDfGOKKQ63zd/ryoEZVnH1myO5WQw8etKjISoIcxmf3qmhpuc0q29QEYZ4zqRn6a1A YNKaXpnOOjlTaI91IwCVzuvk1cGBYvo2NCj6/oE3zMIMO4lYu6lDU3WNgZIzyk3gE0Qf VUfeAy2TI8cXKQH62O6AcBrnqOUlS66/ggEnNH9DTy6PAqnfP4edTctoN2iqe1FXQ4Gj kXyw== X-Gm-Message-State: AOJu0YyANYRD9qHXFFCvNbGpr5L/RCNmnXwn5y8FaI513hKTHLFWk0X/ VBkQF1ElW3RgQu6s3FikaXaLFy2/cpseTdYm0R9aIHrROsRJeNqo1+98Mw== X-Gm-Gg: ASbGncvQ3C/v1u1PSitswtT0sTmg/LjRHGbWq0tghZBBLaFmGV1J/DrQN8fyjsBXJ7Z kSni+agTnq/ZhS9O/WbYLDnif0Y3P+Xo0+uUE8BmUa1p++JcKEppbl/WVY/1odE4qRzFCJeUAS9 Vty8QXvnt2ShlU/Z7NREIFj+ktXQ6RzPO6I6p041Gh86apn7h/OXRAlQHLQjpaEVDAZNsp7nWP6 9d8QANfCdLF7OM7KbA3bvph21LPS4ToWMxY2ZFLr6/HD+dE9sx8A0gY/vdpzX10GxRm1goOCtfa QlAQUhg9ZwPOpJQmagx5v0Ak42E18jQ7FFil X-Received: by 2002:a05:6a00:4685:b0:73e:30dc:bb9b with SMTP id d2e1a72fcca58-73e30dd11cdmr1608707b3a.2.1745525984806; Thu, 24 Apr 2025 13:19:44 -0700 (PDT) Received: from localhost ([61.71.79.124]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73e25a99a9esm1884419b3a.140.2025.04.24.13.19.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Apr 2025 13:19:44 -0700 (PDT) From: "Ying-Chun Liu (PaulLiu)" To: u-boot@lists.denx.de Cc: "Ying-Chun Liu (PaulLiu)" , Heinrich Schuchardt , Ilias Apalodimas Subject: [PATCH v2 3/3] efi: add EFI_DEBUG_IMAGE_INFO for debug Date: Fri, 25 Apr 2025 04:19:26 +0800 Message-ID: <20250424201927.2027257-4-paulliu@debian.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250424201927.2027257-1-paulliu@debian.org> References: <20250424201927.2027257-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. Signed-off-by: Ying-Chun Liu (PaulLiu) Cc: Heinrich Schuchardt Cc: Ilias Apalodimas --- V2: use Kconfig options to turn on/off this feature. --- include/efi_api.h | 2 + include/efi_loader.h | 5 ++ lib/efi_loader/efi_boottime.c | 140 ++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) diff --git a/include/efi_api.h b/include/efi_api.h index 0f4245091f1..ba87af17c1f 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -571,6 +571,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 { u32 image_info_type; struct efi_loaded_image *loaded_image_protocol_instance; diff --git a/include/efi_loader.h b/include/efi_loader.h index 370bc042f70..babe23a8a83 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -617,6 +617,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 */ +void 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 e2665459e44..0d4df5ee6ae 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2130,6 +2130,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 */ @@ -4045,6 +4056,10 @@ efi_m_debug_info_table_header = { NULL }; +static u32 efi_m_max_table_entries; + +#define EFI_DEBUG_TABLE_ENTRY_SIZE (sizeof(void *)) + const efi_guid_t efi_debug_image_info_table_guid = EFI_DEBUG_IMAGE_INFO_TABLE_GUID; @@ -4095,3 +4110,128 @@ 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 + **/ +void 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) { + /* We still have empty entries in the Table, find the first + * empty entry. + */ + index = 0; + while (table[index].normal_image) + index++; + } else { + /* table is full, re-allocate another page for a larger + * table. + */ + table_size = efi_m_max_table_entries * EFI_DEBUG_TABLE_ENTRY_SIZE; + efi_allocate_pool(EFI_RUNTIME_SERVICES_DATA, + table_size + EFI_PAGE_SIZE, + (void **)&new_table); + + if (!new_table) { + efi_m_debug_info_table_header.update_status &= + ~EFI_DEBUG_IMAGE_INFO_UPDATE_IN_PROGRESS; + return; + } + + memset(new_table, 0, table_size + EFI_PAGE_SIZE); + + /* Copy the old table into the new one. */ + memcpy(new_table, table, table_size); + /* Free the old table. */ + efi_free_pool(table); + /* 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. + */ + index = efi_m_max_table_entries; + efi_m_max_table_entries += + EFI_PAGE_SIZE / EFI_DEBUG_TABLE_ENTRY_SIZE; + } + + /* Allocate data for new entry. */ + efi_allocate_pool(EFI_RUNTIME_SERVICES_DATA, + sizeof(struct efi_debug_image_info_normal), + (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; +} + +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 record, then NULL the + * pointer to indicate the slot is free. + */ + efi_free_pool(table[index].normal_image); + table[index].normal_image = NULL; + + /* 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--; + 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; +}