From 9f00d38ce7600a162e37156ee6d5a050857a3a9f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 17 Jan 2025 01:09:51 +0100 Subject: efi_loader: correct logging StartImage() When logging running an image, e.g. `bootefi hello` the indent is not correctly reset. Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/efi_boottime.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 723a9b58691..db544382137 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -3256,11 +3256,10 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, * To get ready to call EFI_EXIT below we have to execute the * missed out steps of EFI_CALL. */ - assert(__efi_entry_check()); - EFI_PRINT("%lu returned by started image\n", - (unsigned long)((uintptr_t)exit_status & - ~EFI_ERROR_MASK)); + EFI_RETURN(exit_status); + current_image = parent_image; + return EFI_EXIT(exit_status); } -- cgit v1.2.3 From e9c34fab18a9a0022b36729afd8e262e062764e2 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 16 Jan 2025 20:26:59 +0100 Subject: efi_loader: use LOGC_EFI consistently The log category should be LOGC_EFI all over the EFI sub-system. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- lib/efi_driver/efi_block_device.c | 2 ++ lib/efi_driver/efi_uclass.c | 2 ++ lib/efi_loader/efi_acpi.c | 2 ++ lib/efi_loader/efi_boottime.c | 2 ++ lib/efi_loader/efi_conformance.c | 2 ++ lib/efi_loader/efi_device_path_to_text.c | 2 ++ lib/efi_loader/efi_device_path_utilities.c | 2 ++ lib/efi_loader/efi_dt_fixup.c | 2 ++ lib/efi_loader/efi_esrt.c | 2 ++ lib/efi_loader/efi_fdt.c | 2 ++ lib/efi_loader/efi_file.c | 2 ++ lib/efi_loader/efi_firmware.c | 2 ++ lib/efi_loader/efi_gop.c | 2 ++ lib/efi_loader/efi_helper.c | 1 + lib/efi_loader/efi_hii.c | 2 ++ lib/efi_loader/efi_hii_config.c | 2 ++ lib/efi_loader/efi_http.c | 2 ++ lib/efi_loader/efi_ipconfig.c | 2 ++ lib/efi_loader/efi_load_initrd.c | 1 + lib/efi_loader/efi_net.c | 2 ++ lib/efi_loader/efi_riscv.c | 1 + lib/efi_loader/efi_root_node.c | 2 ++ lib/efi_loader/efi_runtime.c | 2 ++ lib/efi_loader/efi_signature.c | 2 ++ lib/efi_loader/efi_string.c | 2 ++ lib/efi_loader/efi_tcg2.c | 1 + lib/efi_loader/efi_unicode_collation.c | 2 ++ lib/efi_loader/efi_var_common.c | 2 ++ lib/efi_loader/efi_var_mem.c | 2 ++ lib/efi_loader/efi_variable_tee.c | 2 ++ lib/efi_loader/efi_watchdog.c | 2 ++ 31 files changed, 58 insertions(+) (limited to 'lib') diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c index 19a5ee24794..d3c668dc183 100644 --- a/lib/efi_driver/efi_block_device.c +++ b/lib/efi_driver/efi_block_device.c @@ -28,6 +28,8 @@ * iPXE uses the simple file protocol to load Grub or the Linux Kernel. */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_driver/efi_uclass.c b/lib/efi_driver/efi_uclass.c index e1e28df20b2..495be53cb77 100644 --- a/lib/efi_driver/efi_uclass.c +++ b/lib/efi_driver/efi_uclass.c @@ -17,6 +17,8 @@ * controllers. */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_acpi.c b/lib/efi_loader/efi_acpi.c index ff305a6b13e..4422b31ac6a 100644 --- a/lib/efi_loader/efi_acpi.c +++ b/lib/efi_loader/efi_acpi.c @@ -5,6 +5,8 @@ * Copyright (C) 2018, Bin Meng */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index db544382137..5164cb15986 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -5,6 +5,8 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_conformance.c b/lib/efi_loader/efi_conformance.c index 167067e26cd..2bae93a94bd 100644 --- a/lib/efi_loader/efi_conformance.c +++ b/lib/efi_loader/efi_conformance.c @@ -5,6 +5,8 @@ * Copyright (C) 2022 Arm Ltd. */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c index 481a9712d9d..f6889cb7399 100644 --- a/lib/efi_loader/efi_device_path_to_text.c +++ b/lib/efi_loader/efi_device_path_to_text.c @@ -5,6 +5,8 @@ * Copyright (c) 2017 Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_device_path_utilities.c b/lib/efi_loader/efi_device_path_utilities.c index ac250bbfcc9..552c5bb1f05 100644 --- a/lib/efi_loader/efi_device_path_utilities.c +++ b/lib/efi_loader/efi_device_path_utilities.c @@ -5,6 +5,8 @@ * Copyright (c) 2017 Leif Lindholm */ +#define LOG_CATEGORY LOGC_EFI + #include const efi_guid_t efi_guid_device_path_utilities_protocol = diff --git a/lib/efi_loader/efi_dt_fixup.c b/lib/efi_loader/efi_dt_fixup.c index 0dac94b0c6c..26928cfc454 100644 --- a/lib/efi_loader/efi_dt_fixup.c +++ b/lib/efi_loader/efi_dt_fixup.c @@ -5,6 +5,8 @@ * Copyright (c) 2020 Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_esrt.c b/lib/efi_loader/efi_esrt.c index 443bd999ce1..e235c8fe91c 100644 --- a/lib/efi_loader/efi_esrt.c +++ b/lib/efi_loader/efi_esrt.c @@ -5,6 +5,8 @@ * Copyright (C) 2021 Arm Ltd. */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_fdt.c b/lib/efi_loader/efi_fdt.c index f882622fdad..1ba6641d821 100644 --- a/lib/efi_loader/efi_fdt.c +++ b/lib/efi_loader/efi_fdt.c @@ -6,6 +6,8 @@ * Written by Simon Glass */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index 95b3c890ee9..201fa5f8f3c 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -5,6 +5,8 @@ * Copyright (c) 2017 Rob Clark */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 112775daf4c..5a754c9cd03 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -6,6 +6,8 @@ * Author: AKASHI Takahiro */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_gop.c b/lib/efi_loader/efi_gop.c index 41e12fa7246..4593975be5a 100644 --- a/lib/efi_loader/efi_gop.c +++ b/lib/efi_loader/efi_gop.c @@ -5,6 +5,8 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index bf96f61d3d0..04b2efc4a3b 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -4,6 +4,7 @@ */ #define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_hii.c b/lib/efi_loader/efi_hii.c index 74e402df1b8..44235970a7c 100644 --- a/lib/efi_loader/efi_hii.c +++ b/lib/efi_loader/efi_hii.c @@ -6,6 +6,8 @@ * Copyright (c) 2018 AKASHI Takahiro, Linaro Limited */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_hii_config.c b/lib/efi_loader/efi_hii_config.c index ae0f3ecd3b1..37d8c6629e2 100644 --- a/lib/efi_loader/efi_hii_config.c +++ b/lib/efi_loader/efi_hii_config.c @@ -10,6 +10,8 @@ * the Makefile. */ +#define LOG_CATEGORY LOGC_EFI + #include const efi_guid_t efi_guid_hii_config_routing_protocol diff --git a/lib/efi_loader/efi_http.c b/lib/efi_loader/efi_http.c index 694e1993418..88816256b03 100644 --- a/lib/efi_loader/efi_http.c +++ b/lib/efi_loader/efi_http.c @@ -7,6 +7,8 @@ * IP4_CONFIG2_PROTOCOL */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_ipconfig.c b/lib/efi_loader/efi_ipconfig.c index 0b247a4c028..f1c092daafd 100644 --- a/lib/efi_loader/efi_ipconfig.c +++ b/lib/efi_loader/efi_ipconfig.c @@ -4,6 +4,8 @@ * */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 23508431c83..fb8cc7bcbe3 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -4,6 +4,7 @@ */ #define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index 67593ef50c0..ce9272fa240 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -15,6 +15,8 @@ * Reset(): EfiSimpleNetworkInitialized -> EfiSimpleNetworkInitialized */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_riscv.c b/lib/efi_loader/efi_riscv.c index 4d398c5be34..6f2ccf4f7e6 100644 --- a/lib/efi_loader/efi_riscv.c +++ b/lib/efi_loader/efi_riscv.c @@ -7,6 +7,7 @@ */ #define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_root_node.c b/lib/efi_loader/efi_root_node.c index 4d7fb74b5d6..74225edad29 100644 --- a/lib/efi_loader/efi_root_node.c +++ b/lib/efi_loader/efi_root_node.c @@ -5,6 +5,8 @@ * Copyright (c) 2018 Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 05369c47b01..35eb6a77766 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -5,6 +5,8 @@ * Copyright (c) 2016 Alexander Graf */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_signature.c b/lib/efi_loader/efi_signature.c index 184eac8cddb..93a4f257016 100644 --- a/lib/efi_loader/efi_signature.c +++ b/lib/efi_loader/efi_signature.c @@ -4,6 +4,8 @@ * Copyright (c) 2019 Linaro Limited, Author: AKASHI Takahiro */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_string.c b/lib/efi_loader/efi_string.c index 413e329b600..50d1daf33a9 100644 --- a/lib/efi_loader/efi_string.c +++ b/lib/efi_loader/efi_string.c @@ -5,6 +5,8 @@ * Copyright (c) 2020 AKASHI Takahiro, Linaro Limited */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c index a15c73162ee..c697b53441a 100644 --- a/lib/efi_loader/efi_tcg2.c +++ b/lib/efi_loader/efi_tcg2.c @@ -8,6 +8,7 @@ */ #define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_unicode_collation.c b/lib/efi_loader/efi_unicode_collation.c index d48700a352b..df2a988ee39 100644 --- a/lib/efi_loader/efi_unicode_collation.c +++ b/lib/efi_loader/efi_unicode_collation.c @@ -5,6 +5,8 @@ * Copyright (c) 2018 Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index ea8d2a4cf98..4b34a58b4cf 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -5,6 +5,8 @@ * Copyright (c) 2020 Linaro Limited, Author: AKASHI Takahiro */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_var_mem.c b/lib/efi_loader/efi_var_mem.c index 139e16aad7c..b265d95dd6b 100644 --- a/lib/efi_loader/efi_var_mem.c +++ b/lib/efi_loader/efi_var_mem.c @@ -5,6 +5,8 @@ * Copyright (c) 2020, Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include #include #include diff --git a/lib/efi_loader/efi_variable_tee.c b/lib/efi_loader/efi_variable_tee.c index 8b6b0a39086..0d090d051dd 100644 --- a/lib/efi_loader/efi_variable_tee.c +++ b/lib/efi_loader/efi_variable_tee.c @@ -10,6 +10,8 @@ * Abdellatif El Khlifi */ +#define LOG_CATEGORY LOGC_EFI + #if CONFIG_IS_ENABLED(ARM_FFA_TRANSPORT) #include #endif diff --git a/lib/efi_loader/efi_watchdog.c b/lib/efi_loader/efi_watchdog.c index f5fb9117717..c21d8086074 100644 --- a/lib/efi_loader/efi_watchdog.c +++ b/lib/efi_loader/efi_watchdog.c @@ -5,6 +5,8 @@ * Copyright (c) 2017 Heinrich Schuchardt */ +#define LOG_CATEGORY LOGC_EFI + #include /* Conversion factor from seconds to multiples of 100ns */ -- cgit v1.2.3 From e20349a38caf429f3109a6a02529573472f521ae Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 17 Jan 2025 21:34:01 +0100 Subject: efi_loader: reduce UEFI size if HAS_BOARD_SIZE_LIMIT=y If a board has a strict size limit, disable * Unicode capitalization and * HII protocols by default to reduce the image size. Reviewed-by: Ilias Apalodimas Signed-off-by: Heinrich Schuchardt --- lib/efi_loader/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 798dced475e..ad0bbdd8a77 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -387,7 +387,7 @@ config EFI_DT_FIXUP config EFI_LOADER_HII bool "HII protocols" - default y + default y if !HAS_BOARD_SIZE_LIMIT help The Human Interface Infrastructure is a complicated framework that allows UEFI applications to draw fancy menus and hook strings using @@ -407,7 +407,7 @@ if EFI_UNICODE_COLLATION_PROTOCOL2 config EFI_UNICODE_CAPITALIZATION bool "Support Unicode capitalization" - default y + default y if !HAS_BOARD_SIZE_LIMIT help Select this option to enable correct handling of the capitalization of Unicode codepoints in the range 0x0000-0xffff. If this option is not -- cgit v1.2.3 From a70759898a0ee9750d418da78ff0ebcd432e9bb5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Jan 2025 15:07:20 -0700 Subject: efi_loader: Update efi_run_image() to accept image and device path Provide these globals as parameters to this function, on the way to making it possible to start an image without relying on the globals. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_bootbin.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index 428991df88f..71591dd54b9 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -157,9 +157,13 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path, * * @source_buffer: memory address of the UEFI image * @source_size: size of the UEFI image + * @dp_dev: EFI device-path + * @dp_img: EFI image-path * Return: status code */ -static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) +static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img) { efi_handle_t mem_handle = NULL, handle; struct efi_device_path *file_path = NULL; @@ -167,7 +171,7 @@ static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) efi_status_t ret; u16 *load_options; - if (!bootefi_device_path || !bootefi_image_path) { + if (!dp_img || !dp_img) { log_debug("Not loaded from disk\n"); /* * Special case for efi payload not loaded from disk, @@ -188,9 +192,8 @@ static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) goto out; msg_path = file_path; } else { - file_path = efi_dp_concat(bootefi_device_path, - bootefi_image_path, 0); - msg_path = bootefi_image_path; + file_path = efi_dp_concat(dp_img, dp_img, 0); + msg_path = dp_img; log_debug("Loaded from disk\n"); } @@ -252,5 +255,6 @@ efi_status_t efi_binary_run(void *image, size_t size, void *fdt) if (ret != EFI_SUCCESS) return ret; - return efi_run_image(image, size); + return efi_run_image(image, size, bootefi_device_path, + bootefi_image_path); } -- cgit v1.2.3 From b9f42821af4dfc0988c39cb4d0ae28118da2c312 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Jan 2025 15:07:21 -0700 Subject: efi_loader: Add a version of efi_binary_run() with more parameters This uses a few global variables at present. With the bootflow we have the required parameters, so add a function which accepts these. Update the existing function to call the new one with the globals. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas --- lib/efi_loader/efi_bootbin.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index 71591dd54b9..789da8bcda0 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -228,18 +228,22 @@ out: } /** - * efi_binary_run() - run loaded UEFI image + * efi_binary_run_dp() - run loaded UEFI image * * @image: memory address of the UEFI image * @size: size of the UEFI image * @fdt: device-tree + * @dp_dev: EFI device-path + * @dp_img: EFI image-path * * Execute an EFI binary image loaded at @image. * @size may be zero if the binary is loaded with U-Boot load command. * * Return: status code */ -efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img) { efi_status_t ret; @@ -255,6 +259,23 @@ efi_status_t efi_binary_run(void *image, size_t size, void *fdt) if (ret != EFI_SUCCESS) return ret; - return efi_run_image(image, size, bootefi_device_path, - bootefi_image_path); + return efi_run_image(image, size, dp_dev, dp_img); +} + +/** + * efi_binary_run() - run loaded UEFI image + * + * @image: memory address of the UEFI image + * @size: size of the UEFI image + * @fdt: device-tree + * + * Execute an EFI binary image loaded at @image. + * @size may be zero if the binary is loaded with U-Boot load command. + * + * Return: status code + */ +efi_status_t efi_binary_run(void *image, size_t size, void *fdt) +{ + return efi_binary_run_dp(image, size, fdt, bootefi_device_path, + bootefi_image_path); } -- cgit v1.2.3 From 5f67c8800e8ea56ab161a7b643f54190556e70bc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Jan 2025 15:07:22 -0700 Subject: efi_loader: Move the fallback code from efi_run_image() This code is only needed if an invalid image/device path is passed in. Move the code out to a caller where this can be dealt with. The normal flow will provide these parameters. Signed-off-by: Simon Glass --- lib/efi_loader/efi_bootbin.c | 89 +++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 42 deletions(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index 789da8bcda0..dce154e728a 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -165,37 +165,13 @@ static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, struct efi_device_path *dp_dev, struct efi_device_path *dp_img) { - efi_handle_t mem_handle = NULL, handle; - struct efi_device_path *file_path = NULL; - struct efi_device_path *msg_path; + efi_handle_t handle; + struct efi_device_path *msg_path, *file_path; efi_status_t ret; u16 *load_options; - if (!dp_img || !dp_img) { - log_debug("Not loaded from disk\n"); - /* - * Special case for efi payload not loaded from disk, - * such as 'bootefi hello' or for example payload - * loaded directly into memory via JTAG, etc: - */ - file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, - (uintptr_t)source_buffer, - source_size); - /* - * Make sure that device for device_path exist - * in load_image(). Otherwise, shell and grub will fail. - */ - ret = efi_install_multiple_protocol_interfaces(&mem_handle, - &efi_guid_device_path, - file_path, NULL); - if (ret != EFI_SUCCESS) - goto out; - msg_path = file_path; - } else { - file_path = efi_dp_concat(dp_img, dp_img, 0); - msg_path = dp_img; - log_debug("Loaded from disk\n"); - } + file_path = efi_dp_concat(dp_dev, dp_img, 0); + msg_path = dp_img; log_info("Booting %pD\n", msg_path); @@ -214,15 +190,6 @@ static efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size, ret = do_bootefi_exec(handle, load_options); out: - if (mem_handle) { - efi_status_t r; - - r = efi_uninstall_multiple_protocol_interfaces( - mem_handle, &efi_guid_device_path, file_path, NULL); - if (r != EFI_SUCCESS) - log_err("Uninstalling protocol interfaces failed\n"); - } - efi_free_pool(file_path); return ret; } @@ -241,9 +208,9 @@ out: * * Return: status code */ -efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, - struct efi_device_path *dp_dev, - struct efi_device_path *dp_img) +static efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, + struct efi_device_path *dp_dev, + struct efi_device_path *dp_img) { efi_status_t ret; @@ -276,6 +243,44 @@ efi_status_t efi_binary_run_dp(void *image, size_t size, void *fdt, */ efi_status_t efi_binary_run(void *image, size_t size, void *fdt) { - return efi_binary_run_dp(image, size, fdt, bootefi_device_path, - bootefi_image_path); + efi_handle_t mem_handle = NULL; + struct efi_device_path *file_path = NULL; + efi_status_t ret; + + if (!bootefi_device_path || !bootefi_image_path) { + log_debug("Not loaded from disk\n"); + /* + * Special case for efi payload not loaded from disk, + * such as 'bootefi hello' or for example payload + * loaded directly into memory via JTAG, etc: + */ + file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image, size); + /* + * Make sure that device for device_path exist + * in load_image(). Otherwise, shell and grub will fail. + */ + ret = efi_install_multiple_protocol_interfaces(&mem_handle, + &efi_guid_device_path, + file_path, NULL); + if (ret != EFI_SUCCESS) + goto out; + } else { + log_debug("Loaded from disk\n"); + } + + ret = efi_binary_run_dp(image, size, fdt, bootefi_device_path, + bootefi_image_path); +out: + if (mem_handle) { + efi_status_t r; + + r = efi_uninstall_multiple_protocol_interfaces(mem_handle, + &efi_guid_device_path, file_path, NULL); + if (r != EFI_SUCCESS) + log_err("Uninstalling protocol interfaces failed\n"); + } + efi_free_pool(file_path); + + return ret; } -- cgit v1.2.3 From a2338955fc1d3bb6de86ab4fb6e7c55ff189f4f0 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Jan 2025 15:07:23 -0700 Subject: efi_loader: Pass in the required parameters from EFI bootmeth Rather than setting up the global variables and then making the call, pass them into function directly. This cleans up the code and makes it all a bit easier to understand. Signed-off-by: Simon Glass --- lib/efi_loader/efi_bootbin.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index dce154e728a..fdde536af7a 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -6,13 +6,16 @@ #define LOG_CATEGORY LOGC_EFI +#include #include +#include #include #include #include #include #include #include +#include static struct efi_device_path *bootefi_image_path; static struct efi_device_path *bootefi_device_path; @@ -284,3 +287,71 @@ out: return ret; } + +/** + * calc_dev_name() - Calculate the device name to give to EFI + * + * If not supported, this shows an error. + * + * Return name, or NULL if not supported + */ +static const char *calc_dev_name(struct bootflow *bflow) +{ + const struct udevice *media_dev; + + media_dev = dev_get_parent(bflow->dev); + + if (!bflow->blk) { + log_err("Cannot boot EFI app on media '%s'\n", + dev_get_uclass_name(media_dev)); + + return NULL; + } + + if (device_get_uclass_id(media_dev) == UCLASS_MASS_STORAGE) + return "usb"; + + return blk_get_uclass_name(device_get_uclass_id(media_dev)); +} + +efi_status_t efi_bootflow_run(struct bootflow *bflow) +{ + struct efi_device_path *device, *image; + const struct udevice *media_dev; + struct blk_desc *desc = NULL; + const char *dev_name; + char devnum_str[9]; + efi_status_t ret; + void *fdt; + + media_dev = dev_get_parent(bflow->dev); + if (bflow->blk) { + desc = dev_get_uclass_plat(bflow->blk); + + snprintf(devnum_str, sizeof(devnum_str), "%x:%x", + desc ? desc->devnum : dev_seq(media_dev), bflow->part); + } else { + *devnum_str = '\0'; + } + + dev_name = calc_dev_name(bflow); + log_debug("dev_name '%s' devnum_str '%s' fname '%s' media_dev '%s'\n", + dev_name, devnum_str, bflow->fname, media_dev->name); + if (!dev_name) + return EFI_UNSUPPORTED; + ret = calculate_paths(dev_name, devnum_str, bflow->fname, &device, + &image); + if (ret) + return ret; + + if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) { + log_debug("Booting with built-in fdt\n"); + fdt = EFI_FDT_USE_INTERNAL; + } else { + log_debug("Booting with external fdt\n"); + fdt = map_sysmem(bflow->fdt_addr, 0); + } + ret = efi_binary_run_dp(bflow->buf, bflow->size, fdt, device, image); + + return ret; +} -- cgit v1.2.3 From 21de624eb89c647a21b06a5b0f5b186838be1d17 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 23 Jan 2025 15:07:24 -0700 Subject: bootmeth_efi: Support PXE booting Finish off the implementation so it is possible to boot an EFI app over a network. Signed-off-by: Simon Glass --- lib/efi_loader/efi_bootbin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index fdde536af7a..10ec5e9ada3 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -302,6 +302,9 @@ static const char *calc_dev_name(struct bootflow *bflow) media_dev = dev_get_parent(bflow->dev); if (!bflow->blk) { + if (device_get_uclass_id(media_dev) == UCLASS_ETH) + return "Net"; + log_err("Cannot boot EFI app on media '%s'\n", dev_get_uclass_name(media_dev)); @@ -342,7 +345,7 @@ efi_status_t efi_bootflow_run(struct bootflow *bflow) ret = calculate_paths(dev_name, devnum_str, bflow->fname, &device, &image); if (ret) - return ret; + return EFI_UNSUPPORTED; if (bflow->flags & BOOTFLOWF_USE_BUILTIN_FDT) { log_debug("Booting with built-in fdt\n"); -- cgit v1.2.3