All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 7/8 v2] efi_selftest: Modify self-tests for initrd loading via Loadfile2
Date: Wed, 30 Dec 2020 21:29:43 +0100	[thread overview]
Message-ID: <fbc7e50c-7dc3-7479-9924-cdf815d54509@gmx.de> (raw)
In-Reply-To: <20201230150722.154663-8-ilias.apalodimas@linaro.org>

On 12/30/20 4:07 PM, Ilias Apalodimas wrote:
> We changed the logic of the initrd discovery and the installation of the
> protocol in the previous patch.
> Instead of a config now option it now resides in an EFI variable. Adjust
> the existing tests accordingly and add self-tests which will cover the new
> features.

A full test would comprise installing a block device of type EFI
containing a binary and an initial ram disk.

The loaded binary could check the content of the ram disk. E.g. the
CRC32 and the length could be returned via exit data by the binary.

Have a look at lib/efi_selftest/efi_selftest_block_device.c.

Best regards

Heinrich

>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>   lib/efi_selftest/efi_selftest_load_initrd.c | 100 +++++++++++++++++++-
>   1 file changed, 97 insertions(+), 3 deletions(-)
>
> diff --git a/lib/efi_selftest/efi_selftest_load_initrd.c b/lib/efi_selftest/efi_selftest_load_initrd.c
> index fe060a664402..1534c2ba24fa 100644
> --- a/lib/efi_selftest/efi_selftest_load_initrd.c
> +++ b/lib/efi_selftest/efi_selftest_load_initrd.c
> @@ -14,10 +14,12 @@
>    *
>    *   CONFIG_EFI_SELFTEST=y
>    *   CONFIG_EFI_LOAD_FILE2_INITRD=y
> - *   CONFIG_EFI_INITRD_FILESPEC="host 0:1 initrd"
>    *
> - * * Run ./u-boot and execute
> + * * Create files
> + *   mkdir init_test && cp initrd init_test/
> + *   virt-make-fs -t ext4 init_test test.img
>    *
> + * * Run ./u-boot and execute
>    *   host bind 0 image
>    *   setenv efi_selftest load initrd
>    *   bootefi selftest
> @@ -43,6 +45,7 @@
>   #include <efi_load_initrd.h>
>
>   static struct efi_boot_services *boottime;
> +static struct efi_runtime_services *runtime;
>
>   static struct efi_initrd_dp dp = {
>   	.vendor = {
> @@ -76,10 +79,13 @@ static struct efi_initrd_dp dp_invalid = {
>   	}
>   };
>
> +static efi_handle_t handle;
> +
>   static int setup(const efi_handle_t handle,
>   		 const struct efi_system_table *systable)
>   {
>   	boottime = systable->boottime;
> +	runtime = systable->runtime;
>
>   	return EFI_ST_SUCCESS;
>   }
> @@ -87,16 +93,97 @@ static int setup(const efi_handle_t handle,
>   static int execute(void)
>   {
>   	efi_guid_t lf2_proto_guid = EFI_LOAD_FILE2_PROTOCOL_GUID;
> +	efi_guid_t efi_global_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
>   	struct efi_load_file_protocol *lf2;
>   	struct efi_device_path *dp2, *dp2_invalid;
>   	efi_status_t status;
> -	efi_handle_t handle;
>   	char buffer[64];
>   	efi_uintn_t buffer_size;
>   	void *buf;
>   	u32 crc32;
> +	u16 boot_current = 0;
> +	efi_uintn_t boot_current_size = sizeof(boot_current);
> +	char path[] = "host 0 initrd";
> +	char invalid_path[] = "host 1 initrd";
> +	efi_uintn_t path_size = sizeof(path);
> +	efi_uintn_t invalid_path_size = sizeof(invalid_path);
> +	u32 attrs = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
>
>   	memset(buffer, 0, sizeof(buffer));
> +	/* Set variable BootCurrent and Initrd#### to a wrong value */
> +	status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid,
> +				       attrs, boot_current_size, &boot_current);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("SetVariable for BootCurrent failed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/*
> +	 * We don't need NV for Initrd here.
> +	 * Set the file to an invalid file path
> +	 */
> +	status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid,
> +				       attrs, invalid_path_size, invalid_path);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("SetVariable for Initrd failed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/* We only install the protocol during efibootmgr */
> +	status = efi_initrd_register(&handle);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("Failed to install initrd protocol\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/*
> +	 * We should only install the protocol if the file's found
> +	 * Right now both BootCurrent and file path are invalid
> +	 */
> +	dp2 = (struct efi_device_path *)&dp;
> +	status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle);
> +	if (status != EFI_NOT_FOUND) {
> +		efi_st_error("Initrd protocol should't be installed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/* Update BootCurrent to the correct value */
> +	boot_current = 0x0010;
> +	status = runtime->set_variable(L"BootCurrent", &efi_global_variable_guid,
> +				       attrs, boot_current_size, &boot_current);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("SetVariable for BootCurrent failed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/* re-install with invalid file path */
> +	status = efi_initrd_register(&handle);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("Failed to install initrd protocol\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/* file path is invalid */
> +	dp2 = (struct efi_device_path *)&dp;
> +	status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle);
> +	if (status != EFI_NOT_FOUND) {
> +		efi_st_error("Initrd protocol should't be installed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	/* re-install with correct values now */
> +	status = runtime->set_variable(L"Initrd0010", &efi_global_variable_guid,
> +				       attrs, path_size, path);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("SetVariable for Initrd failed\n");
> +		return EFI_ST_FAILURE;
> +	}
> +
> +	status = efi_initrd_register(&handle);
> +	if (status != EFI_SUCCESS) {
> +		efi_st_error("Failed to install initrd protocol\n");
> +		return EFI_ST_FAILURE;
> +	}
>
>   	dp2 = (struct efi_device_path *)&dp;
>   	status = boottime->locate_device_path(&lf2_proto_guid, &dp2, &handle);
> @@ -211,10 +298,17 @@ static int execute(void)
>   	return EFI_ST_SUCCESS;
>   }
>
> +static int teardown(void)
> +{
> +	efi_delete_handle(handle);
> +	return EFI_ST_SUCCESS;
> +}
> +
>   EFI_UNIT_TEST(load_initrd) = {
>   	.name = "load initrd",
>   	.phase = EFI_EXECUTE_BEFORE_BOOTTIME_EXIT,
>   	.setup = setup,
>   	.execute = execute,
> +	.teardown = teardown,
>   	.on_request = true,
>   };
>

  reply	other threads:[~2020-12-30 20:29 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30 15:07 [PATCH 0/8 v2] Change logic of EFI LoadFile2 protocol for initrd loading Ilias Apalodimas
2020-12-30 15:07 ` [PATCH 1/8 v2] efi_loader: Remove unused headers from efi_load_initrd.c Ilias Apalodimas
2020-12-30 18:21   ` Heinrich Schuchardt
2020-12-30 15:07 ` [PATCH 2/8 v2] efi_loader: Remove unconditional installation of file2 protocol for initrd Ilias Apalodimas
2020-12-30 18:15   ` Heinrich Schuchardt
2020-12-30 15:07 ` [PATCH 3/8 v2] efi_loader: Add size checks to efi_create_indexed_name() Ilias Apalodimas
2020-12-30 18:34   ` Heinrich Schuchardt
2020-12-30 21:23     ` Ilias Apalodimas
2020-12-30 15:07 ` [PATCH 4/8 v2] efi_loader: Introduce helper functions for EFI Ilias Apalodimas
2020-12-30 19:29   ` Heinrich Schuchardt
2020-12-30 21:21     ` Ilias Apalodimas
2020-12-30 15:07 ` [PATCH 5/8 v2] efi_loader: bootmgr: Use get_var from efi_helper file Ilias Apalodimas
2020-12-30 19:32   ` Heinrich Schuchardt
2020-12-30 15:07 ` [PATCH 6/8 v2] efi_loader: Replace config option with EFI variable for initrd loading Ilias Apalodimas
2020-12-30 19:38   ` Heinrich Schuchardt
2021-01-05  2:42   ` AKASHI Takahiro
2021-01-05  8:50     ` Ilias Apalodimas
2021-01-06 10:43       ` Ilias Apalodimas
2021-01-06 11:07         ` Heinrich Schuchardt
2021-01-06 12:53           ` Ilias Apalodimas
2020-12-30 15:07 ` [PATCH 7/8 v2] efi_selftest: Modify self-tests for initrd loading via Loadfile2 Ilias Apalodimas
2020-12-30 20:29   ` Heinrich Schuchardt [this message]
2020-12-30 15:07 ` [PATCH 8/8 v2] doc: uefi: Add instruction for initrd loading Ilias Apalodimas
2020-12-30 20:17   ` Heinrich Schuchardt
2020-12-30 20:44 ` [PATCH 0/8 v2] Change logic of EFI LoadFile2 protocol " Heinrich Schuchardt
2020-12-30 21:17   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fbc7e50c-7dc3-7479-9924-cdf815d54509@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.