From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35B2AC433EF for ; Thu, 24 Mar 2022 19:00:34 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0300183FA8; Thu, 24 Mar 2022 20:00:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=unixzen.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=unixzen.com header.i=@unixzen.com header.b="wnLE8r17"; dkim=pass (1024-bit key) header.d=unixzen.com header.i=@unixzen.com header.b="p8rs/PhQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 315A684064; Thu, 24 Mar 2022 20:00:30 +0100 (CET) Received: from mx.dal1.terarocket.io (mx.dal1.terarocket.io [108.61.222.170]) by phobos.denx.de (Postfix) with ESMTP id 9135E83F99 for ; Thu, 24 Mar 2022 20:00:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=unixzen.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kallisti5@unixzen.com Received: by mx.dal1.terarocket.io (Postfix, from userid 1001) id B62E75E779; Thu, 24 Mar 2022 19:00:26 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mx.dal1.terarocket.io B62E75E779 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unixzen.com; s=default; t=1648148426; bh=NTkMHroxRCvpXt89nxTJvcMYN/8QcJW6LAb2XM9uXGg=; h=From:To:Cc:Subject:Date:From; b=wnLE8r1722rW3GIk0etiSeuEur5rndvPfVEoDc4obAYuurXQG0mxJubnaqb1JR/0k IgxA6W94Xt6g9TtT+y91vsd3jFW3lztK8Digvr9u14aa/8PLLYtXPZNgjzrAb6ttZI reUC+wCXoLV38NkTLW5xBcoqceCxaP+uDgaS4bmA= Received: from eris.discord.local (cpe-70-112-18-26.austin.res.rr.com [70.112.18.26]) by mx.dal1.terarocket.io (Postfix) with ESMTPSA id C70BC5E4C8; Thu, 24 Mar 2022 19:00:25 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mx.dal1.terarocket.io C70BC5E4C8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unixzen.com; s=default; t=1648148425; bh=NTkMHroxRCvpXt89nxTJvcMYN/8QcJW6LAb2XM9uXGg=; h=From:To:Cc:Subject:Date:From; b=p8rs/PhQsBWcfTbJpa80ihOxKK+Y/tHJrSbnr73z12dUE+pxs3mXlHJtFeU52BEVp cBAP0lU7SX6m9ydaVVVh8dBHPa7B8uXft8eh3JmpvFTvnAqzKeHE/pVAULF/Pyk1kn KQCa6Vnz0oor4PqpJnEfi63CoTHoqiSRKRtG5kX0= From: Alexander von Gluck IV To: u-boot@lists.denx.de Cc: Alexander von Gluck IV Subject: [PATCH] efi_loader (v2): Expose relocated address for gdb debugging purposes Date: Thu, 24 Mar 2022 14:00:19 -0500 Message-Id: <20220324190019.956611-1-kallisti5@unixzen.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.5 at phobos.denx.de X-Virus-Status: Clean * If users want to debug EFI applications via qemu + GDB, they need to know the relocated address of the application to align their symbols to in GDB via add-symbol-file. * This exposes where EFI applications are relocated to enable debugging EFI applications via qemu + gdb * Usage is generally determining the address, then add-symbol-file (efi loader) (address) * The address can change, but is generally consistent with the same qemu version and u-boot binary. (allowing you to boot once, find the address, then reboot with qemu -s -S --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_boottime.c | 1 + lib/efi_loader/efi_image_loader.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/include/efi_loader.h b/include/efi_loader.h index f4860e87fc..2ca2bf3adb 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -403,6 +403,7 @@ enum efi_image_auth_status { * @exit_data_size: exit data size passed to Exit() * @exit_data: exit data passed to Exit() * @exit_jmp: long jump buffer for returning from started image + * @reloc_addr: relocated address of the image * @entry: entry address of the relocated image * @image_type: indicates if the image is an applicition or a driver * @auth_status: indicates if the image is authenticated @@ -413,6 +414,8 @@ struct efi_loaded_image_obj { efi_uintn_t *exit_data_size; u16 **exit_data; struct jmp_buf_data *exit_jmp; + + u64 reloc_addr; EFIAPI efi_status_t (*entry)(efi_handle_t image_handle, struct efi_system_table *st); u16 image_type; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 20b69699fe..6fac8c576e 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3057,6 +3057,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, current_image = image_handle; image_obj->header.type = EFI_OBJECT_TYPE_STARTED_IMAGE; + log_info("EFI image relocated to 0x%llx\n", image_obj->reloc_addr); EFI_PRINT("Jumping into 0x%p\n", image_obj->entry); ret = EFI_CALL(image_obj->entry(image_handle, &systab)); diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c index 773bd0677c..65e5b7e40b 100644 --- a/lib/efi_loader/efi_image_loader.c +++ b/lib/efi_loader/efi_image_loader.c @@ -906,6 +906,7 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, ret = EFI_OUT_OF_RESOURCES; goto err; } + handle->reloc_addr = (u64)efi_reloc; handle->entry = efi_reloc + opt->AddressOfEntryPoint; rel_size = opt->DataDirectory[rel_idx].Size; rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; @@ -922,6 +923,8 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle, ret = EFI_OUT_OF_RESOURCES; goto err; } + + handle->reloc_addr = (u64)efi_reloc; handle->entry = efi_reloc + opt->AddressOfEntryPoint; rel_size = opt->DataDirectory[rel_idx].Size; rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress; -- 2.35.1