diff mbox series

[RFC,04/13] cmd: bootefi: carve out binary execution interface

Message ID 20231026053052.622453-5-takahiro.akashi@linaro.org
State Superseded
Headers show
Series cmd: bootefi: refactor the code for bootmgr | expand

Commit Message

AKASHI Takahiro Oct. 26, 2023, 5:30 a.m. UTC
Carve binary execution code out of do_bootefi_image().

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 cmd/bootefi.c | 46 ++++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 14 deletions(-)

Comments

Ilias Apalodimas Oct. 27, 2023, 12:45 p.m. UTC | #1
Akashi-san

On Thu, 26 Oct 2023 at 08:31, AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
>
> Carve binary execution code out of do_bootefi_image().

Patch looks correct, but please update with the reasons for this.

Thanks
/Ilias
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>  cmd/bootefi.c | 46 ++++++++++++++++++++++++++++++++--------------
>  1 file changed, 32 insertions(+), 14 deletions(-)
>
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index 899ed90f6817..8b0bd07f1ff8 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -503,6 +503,36 @@ out:
>         return (ret != EFI_SUCCESS) ? ret : ret2;
>  }
>
> +/**
> + * efi_binary_run() - run loaded UEFI image
> + *
> + * @image:     memory address of the UEFI image
> + * @size:      size of the UEFI image
> + *
> + * 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
> + */
> +static efi_status_t efi_binary_run(void *image, size_t size, void *fdt)
> +{
> +       efi_status_t ret;
> +
> +       /* Initialize EFI drivers */
> +       ret = efi_init_obj_list();
> +       if (ret != EFI_SUCCESS) {
> +               log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
> +                       ret & ~EFI_ERROR_MASK);
> +               return ret;
> +       }
> +
> +       ret = efi_install_fdt(fdt);
> +       if (ret != EFI_SUCCESS)
> +               return ret;
> +
> +       return efi_run_image(image, size);
> +}
> +
>  static efi_status_t bootefi_run_prepare(const char *load_options_path,
>                 struct efi_device_path *device_path,
>                 struct efi_device_path *image_path,
> @@ -684,23 +714,11 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
>                 }
>         }
>
> -       /* Initialize EFI drivers */
> -       ret = efi_init_obj_list();
> -       if (ret != EFI_SUCCESS) {
> -               log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
> -                       ret & ~EFI_ERROR_MASK);
> -               return CMD_RET_FAILURE;
> -       }
> +       ret = efi_binary_run(image_buf, size, fdt);
>
> -       ret = efi_install_fdt(fdt);
>         if (ret == EFI_INVALID_PARAMETER)
>                 return CMD_RET_USAGE;
> -       else if (ret != EFI_SUCCESS)
> -               return CMD_RET_FAILURE;
> -
> -       ret = efi_run_image(image_buf, size);
> -
> -       if (ret != EFI_SUCCESS)
> +       else if (ret)
>                 return CMD_RET_FAILURE;
>
>         return CMD_RET_SUCCESS;
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/cmd/bootefi.c b/cmd/bootefi.c
index 899ed90f6817..8b0bd07f1ff8 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -503,6 +503,36 @@  out:
 	return (ret != EFI_SUCCESS) ? ret : ret2;
 }
 
+/**
+ * efi_binary_run() - run loaded UEFI image
+ *
+ * @image:	memory address of the UEFI image
+ * @size:	size of the UEFI image
+ *
+ * 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
+ */
+static efi_status_t efi_binary_run(void *image, size_t size, void *fdt)
+{
+	efi_status_t ret;
+
+	/* Initialize EFI drivers */
+	ret = efi_init_obj_list();
+	if (ret != EFI_SUCCESS) {
+		log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
+			ret & ~EFI_ERROR_MASK);
+		return ret;
+	}
+
+	ret = efi_install_fdt(fdt);
+	if (ret != EFI_SUCCESS)
+		return ret;
+
+	return efi_run_image(image, size);
+}
+
 static efi_status_t bootefi_run_prepare(const char *load_options_path,
 		struct efi_device_path *device_path,
 		struct efi_device_path *image_path,
@@ -684,23 +714,11 @@  static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 	}
 
-	/* Initialize EFI drivers */
-	ret = efi_init_obj_list();
-	if (ret != EFI_SUCCESS) {
-		log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
-			ret & ~EFI_ERROR_MASK);
-		return CMD_RET_FAILURE;
-	}
+	ret = efi_binary_run(image_buf, size, fdt);
 
-	ret = efi_install_fdt(fdt);
 	if (ret == EFI_INVALID_PARAMETER)
 		return CMD_RET_USAGE;
-	else if (ret != EFI_SUCCESS)
-		return CMD_RET_FAILURE;
-
-	ret = efi_run_image(image_buf, size);
-
-	if (ret != EFI_SUCCESS)
+	else if (ret)
 		return CMD_RET_FAILURE;
 
 	return CMD_RET_SUCCESS;