All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi_loader (v2): Expose relocated address for gdb debugging purposes
@ 2022-03-24 19:00 Alexander von Gluck IV
  2022-03-30 20:09 ` Heinrich Schuchardt
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander von Gluck IV @ 2022-03-24 19:00 UTC (permalink / raw)
  To: u-boot; +Cc: Alexander von Gluck IV

* 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] efi_loader (v2): Expose relocated address for gdb debugging purposes
  2022-03-24 19:00 [PATCH] efi_loader (v2): Expose relocated address for gdb debugging purposes Alexander von Gluck IV
@ 2022-03-30 20:09 ` Heinrich Schuchardt
  0 siblings, 0 replies; 2+ messages in thread
From: Heinrich Schuchardt @ 2022-03-30 20:09 UTC (permalink / raw)
  To: Alexander von Gluck IV, u-boot



On 3/24/22 20:00, Alexander von Gluck IV wrote:
> * 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);

This will mess up the output in menu driven EFI applications like SCT.

Best regards

Heinrich

>   	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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-30 20:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 19:00 [PATCH] efi_loader (v2): Expose relocated address for gdb debugging purposes Alexander von Gluck IV
2022-03-30 20:09 ` Heinrich Schuchardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.