[PATCH 6/7] WIP: efi: Allow helloworld to exit boot services

Heinrich Schuchardt xypron.glpk at gmx.de
Tue Nov 21 18:17:16 CET 2023


On 11/21/23 12:35, Simon Glass wrote:
> This allows testing of the exit_boot_services call, providing more
> coverage of the EFI bootmeth.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>

I would prefer to keep helloworld.efi benign.

Please, create a new EFI binary for testing ExitBootServices().

> ---
>
>   lib/efi_loader/helloworld.c | 36 +++++++++++++++++++++++++++++++++++-
>   1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/lib/efi_loader/helloworld.c b/lib/efi_loader/helloworld.c
> index 1135d3a3c37e..1fb5fb5a62f2 100644
> --- a/lib/efi_loader/helloworld.c
> +++ b/lib/efi_loader/helloworld.c
> @@ -206,6 +206,26 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
>   			(con_out, u"Cannot open loaded image protocol\r\n");
>   		goto out;
>   	}
> +
> +	{
> +		ulong ptr = (ulong)loaded_image;
> +		u16 str[80];
> +		int i;
> +
> +		for (i = 0; i < 8; i++) {
> +			uint digit = (ptr >> ((7 - i) * 4)) & 0xf;
> +
> +			if (digit > 9)
> +				digit = 'a' + digit - 10;
> +			else
> +				digit += '0';
> +			str[i] = digit;
> +		}
> +		str[i] = 0;
> +		con_out->output_string(con_out, str);
> +		con_out->output_string(con_out, u"\n");
> +	}
> +
>   	print_load_options(loaded_image);
>
>   	/* Get the device path to text protocol */
> @@ -243,7 +263,21 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
>   		goto out;
>
>   out:
> -	boottime->exit(handle, ret, 0, NULL);
> +	/*
> +	 * TODO: Use vendor string to decide whether to call exit-boot-services
> +	 */
> +	efi_uintn_t map_size = 0;
> +	efi_uintn_t map_key;
> +	efi_uintn_t desc_size;
> +	u32 desc_version;
> +
> +	ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
> +				       &desc_version);
> +	con_out->output_string(con_out, u"Exiting boot sevices\n");
> +
> +	boottime->exit_boot_services(handle, map_key);
> +
> +	ret = boottime->exit(handle, ret, 0, NULL);

After ExitBootServices() you must not call boot services.

Call runtime->reset_system(EFI_RESET_COLD, EFI_SUCCESS, 0, NULL) instead.

Best regards

Heinrich

>
>   	/* We should never arrive here */
>   	return ret;



More information about the U-Boot mailing list