[U-Boot] [PATCH v2 16/16] efi: sandbox: Add a simple 'bootefi test' command

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Dec 4 21:53:29 UTC 2017



On 12/04/2017 10:28 PM, Simon Glass wrote:
> This jumps to test code which can call directly into the EFI support. It
> does not need a separate image so it is easy to write tests with it.
> 
> For now the test just outputs a message. To try it:

Hello Simon,

why do we need "bootefi test"?
What do you plan to do here which we cannot do in "bootefi selftest?
I think we should unify both.

Best regards

Heinrich

> 
> ./sandbox/u-boot -c "bootefi test"
> U-Boot 2017.09-00204-g696c9855fe (Sep 17 2017 - 16:43:53 -0600)
> 
> DRAM:  128 MiB
> MMC:
> Using default environment
> 
> In:    serial
> Out:   serial
> Err:   serial
> SCSI:  Net:   No ethernet found.
> IDE:   Bus 0: not available
> Found 0 disks
> Hello, world!
> Test passed
> 
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
> 
> Changes in v2:
> - Rebase to master
> 
>   cmd/bootefi.c             | 25 +++++++++++++++++++++++--
>   configs/sandbox_defconfig |  1 +
>   include/efi_loader.h      |  3 +++
>   lib/efi_loader/Kconfig    | 10 ++++++++++
>   lib/efi_loader/Makefile   |  1 +
>   lib/efi_loader/efi_test.c | 17 +++++++++++++++++
>   6 files changed, 55 insertions(+), 2 deletions(-)
>   create mode 100644 lib/efi_loader/efi_test.c
> 
> diff --git a/cmd/bootefi.c b/cmd/bootefi.c
> index a4686f17f0..a77d8b256e 100644
> --- a/cmd/bootefi.c
> +++ b/cmd/bootefi.c
> @@ -148,13 +148,11 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt,
>   	struct efi_object loaded_image_info_obj = {};
>   	struct efi_device_path *memdp = NULL;
>   	ulong ret;
> -
>   	ulong (*entry)(void *image_handle, struct efi_system_table *st)
>   		asmlinkage;
>   	ulong fdt_pages, fdt_size, fdt_start, fdt_end;
>   	const efi_guid_t fdt_guid = EFI_FDT_GUID;
>   	bootm_headers_t img = { 0 };
> -	int ret;
>   
>   	/*
>   	 * Special case for efi payload not loaded from disk, such as
> @@ -318,6 +316,29 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>   		memcpy((char *)addr, __efi_helloworld_begin, size);
>   	} else
>   #endif
> +	if (IS_ENABLED(CONFIG_BOOTEFI_TEST) && !strcmp(argv[1], "test")) {
> +		int ret;
> +
> +		/* Initialize and populate EFI object list */
> +		if (efi_init_obj_list())
> +			return CMD_RET_FAILURE;
> +
> +		struct efi_loaded_image loaded_image_info = {};
> +		struct efi_object loaded_image_info_obj = {};
> +
> +		efi_setup_loaded_image(&loaded_image_info,
> +				       &loaded_image_info_obj,
> +				       bootefi_device_path, bootefi_image_path);
> +
> +		ret = efi_test(&loaded_image_info, &systab);
> +		if (ret) {
> +			printf("Test failed: err=%d\n", ret);
> +			return CMD_RET_FAILURE;
> +		}
> +		printf("Test passed\n");
> +
> +		return 0;
> +	}
>   #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
>   	if (!strcmp(argv[1], "selftest")) {
>   		struct efi_loaded_image loaded_image_info = {};
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index 08eec8ecc6..ccf142c51d 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -194,3 +194,4 @@ CONFIG_UT_TIME=y
>   CONFIG_UT_DM=y
>   CONFIG_UT_ENV=y
>   CONFIG_UT_OVERLAY=y
> +CONFIG_CMD_BOOTEFI_SELFTEST=y
> diff --git a/include/efi_loader.h b/include/efi_loader.h
> index 35f8f84401..90018fbe9e 100644
> --- a/include/efi_loader.h
> +++ b/include/efi_loader.h
> @@ -335,6 +335,9 @@ efi_status_t EFIAPI efi_set_variable(s16 *variable_name,
>   void *efi_bootmgr_load(struct efi_device_path **device_path,
>   		       struct efi_device_path **file_path);
>   
> +/* Perform EFI tests */
> +int efi_test(efi_handle_t image_handle, struct efi_system_table *systab);
> +
>   #else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */
>   
>   /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */
> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
> index dee0a96a98..659b2b18f4 100644
> --- a/lib/efi_loader/Kconfig
> +++ b/lib/efi_loader/Kconfig
> @@ -16,3 +16,13 @@ config EFI_LOADER_BOUNCE_BUFFER
>   	  Some hardware does not support DMA to full 64bit addresses. For this
>   	  hardware we can create a bounce buffer so that payloads don't have to
>   	  worry about platform details.
> +
> +config BOOTEFI_TEST
> +	bool "Provide a test for the EFI loader"
> +	depends on EFI_LOADER && SANDBOX
> +	default y
> +	help
> +	  Provides a test of the EFI loader functionality accessed via the
> +	  command line ('bootefi test'). This runs within U-Boot so does not
> +	  need a separate EFI application to work. It aims to include coverage
> +	  of all EFI code which can be accessed within sandbox.
> diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
> index ddb978f650..14ef85cc67 100644
> --- a/lib/efi_loader/Makefile
> +++ b/lib/efi_loader/Makefile
> @@ -23,3 +23,4 @@ obj-$(CONFIG_DM_VIDEO) += efi_gop.o
>   obj-$(CONFIG_PARTITIONS) += efi_disk.o
>   obj-$(CONFIG_NET) += efi_net.o
>   obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o
> +obj-$(CONFIG_BOOTEFI_TEST) += efi_test.o
> diff --git a/lib/efi_loader/efi_test.c b/lib/efi_loader/efi_test.c
> new file mode 100644
> index 0000000000..3fdce78b05
> --- /dev/null
> +++ b/lib/efi_loader/efi_test.c
> @@ -0,0 +1,17 @@
> +/*
> + * Copyright (c) 2017, Google Inc. All rights reserved.
> + *
> + * SPDX-License-Identifier:     GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <efi_api.h>
> +
> +int efi_test(efi_handle_t image_handle, struct efi_system_table *systable)
> +{
> +	struct efi_simple_text_output_protocol *con_out = systable->con_out;
> +
> +	con_out->output_string(con_out, L"Hello, world!\n");
> +
> +	return 0;
> +}
> 


More information about the U-Boot mailing list