From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@chromium.org>
Cc: Caleb Connolly <caleb.connolly@linaro.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Tom Rini <trini@konsulko.com>,
AKASHI Takahiro <akashi.tkhro@gmail.com>,
Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>,
Bin Meng <bmeng.cn@gmail.com>,
Jonathan Humphreys <j-humphreys@ti.com>,
Masahisa Kojima <kojima.masahisa@socionext.com>,
Michal Simek <michal.simek@amd.com>,
U-Boot Mailing List <u-boot@lists.denx.de>
Subject: Re: [PATCH v2 36/39] efi: Add a test app
Date: Thu, 8 Aug 2024 23:17:11 +0200 [thread overview]
Message-ID: <b8409d9e-58d6-4b2e-b0df-9b77cdded67f@gmx.de> (raw)
In-Reply-To: <CAFLszThmhENnEA6jc2q=FRoinv6t9bUWh_PcXTrxvaifJvqY6w@mail.gmail.com>
On 07.08.24 16:36, Simon Glass wrote:
> Hi Heinrich,
>
> On Tue, 6 Aug 2024 at 19:47, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>>
>> On 06.08.24 14:58, Simon Glass wrote:
>>> Add a simple app to use for testing. This is intended to do whatever it
>>> needs to for testing purposes. For now it just prints a message and
>>> exits boot services.
>>>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>> (no changes since v1)
>>>
>>> lib/efi_loader/Kconfig | 10 ++++++
>>> lib/efi_loader/Makefile | 1 +
>>> lib/efi_loader/testapp.c | 68 ++++++++++++++++++++++++++++++++++++++++
>>> 3 files changed, 79 insertions(+)
>>> create mode 100644 lib/efi_loader/testapp.c
>>>
>>> diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
>>> index ab2c1c44364..4de05c6f2d6 100644
>>> --- a/lib/efi_loader/Kconfig
>>> +++ b/lib/efi_loader/Kconfig
>>> @@ -528,4 +528,14 @@ config BOOTEFI_HELLO_COMPILE
>>> No additional space will be required in the resulting U-Boot binary
>>> when this option is enabled.
>>>
>>> +config BOOTEFI_TESTAPP_COMPILE
>>> + bool "Compile an EFI test app for testing"
>>> + default y
>>> + help
>>> + This compiles an app designed for testing. It is packed into an image
>>> + by the test.py testing frame in the setup_efi_image() function.
>>> +
>>> + No additional space will be required in the resulting U-Boot binary
>>> + when this option is enabled.
>>> +
>>> endif
>>> diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile
>>> index 00d18966f9e..87131ab911d 100644
>>> --- a/lib/efi_loader/Makefile
>>> +++ b/lib/efi_loader/Makefile
>>> @@ -20,6 +20,7 @@ apps-$(CONFIG_EFI_LOAD_FILE2_INITRD) += initrddump
>>> ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
>>> apps-y += dtbdump
>>> endif
>>> +apps-$(CONFIG_BOOTEFI_TESTAPP_COMPILE) += testapp
>>>
>>> obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
>>> obj-$(CONFIG_EFI_BOOTMGR) += efi_bootmgr.o
>>> diff --git a/lib/efi_loader/testapp.c b/lib/efi_loader/testapp.c
>>> new file mode 100644
>>> index 00000000000..feb444c92e9
>>> --- /dev/null
>>> +++ b/lib/efi_loader/testapp.c
>>> @@ -0,0 +1,68 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * Hello world EFI application
>>> + *
>>> + * Copyright 2024 Google LLC
>>> + * Written by Simon Glass <sjg@chromium.org>
>>> + *
>>> + * This test program is used to test the invocation of an EFI application.
>>> + * It writes a few messages to the console and then exits boot services
>>> + */
>>> +
>>> +#include <efi_api.h>
>>> +
>>> +static const efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
>>> +
>>> +static struct efi_system_table *systable;
>>> +static struct efi_boot_services *boottime;
>>> +static struct efi_simple_text_output_protocol *con_out;
>>> +
>>> +/**
>>> + * efi_main() - entry point of the EFI application.
>>> + *
>>> + * @handle: handle of the loaded image
>>> + * @systab: system table
>>> + * Return: status code
>>> + */
>>> +efi_status_t EFIAPI efi_main(efi_handle_t handle,
>>> + struct efi_system_table *systab)
>>> +{
>>> + struct efi_loaded_image *loaded_image;
>>> + efi_status_t ret;
>>> + efi_uintn_t map_size;
>>> + efi_uintn_t map_key;
>>> + efi_uintn_t desc_size;
>>> + u32 desc_version;
>>> +
>>> + systable = systab;
>>> + boottime = systable->boottime;
>>> + con_out = systable->con_out;
>>> +
>>> + /* Get the loaded image protocol */
>>> + ret = boottime->open_protocol(handle, &loaded_image_guid,
>>> + (void **)&loaded_image, NULL, NULL,
>>> + EFI_OPEN_PROTOCOL_GET_PROTOCOL);
>>> + if (ret != EFI_SUCCESS) {
>>> + con_out->output_string
>>> + (con_out, u"Cannot open loaded image protocol\r\n");
>>> + goto out;
>>> + }
>>> +
>>> + /* UEFI requires CR LF */
>>> + con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n");
>>> +
>>> +out:
>>> + map_size = 0;
>>> + 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");
>>> +
>>> + /* exit boot services so that this part of U-Boot can be tested */
>>> + boottime->exit_boot_services(handle, map_key);
>>> +
>>> + /* now exit for real */
>>> + ret = boottime->exit(handle, ret, 0, NULL);
>>
>> Please, have a look at chapter 7.4.6,
>> "EFI_BOOT_SERVICES.ExitBootServices" of the UEFI specification.
>>
>> After ExitBootServices() you cannot return anywhere. Boot services are
>> not available anymore. You can only invoke the UEFI runtime services
>> which include ResetSystem().
>
> Yes, understood, but this is a test, so returning is needed so that
> the test can check the output is correct.
>
ExitBootServices() calls dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL).
You cannot print anything afterwards as all devices are gone.
But you can check if a reboot occurs. This is enough to verify that a
ResetSystem() call placed after ExitBootServices() was executed.
We already have
* lib/efi_selftest/efi_selftest_exitbootservices.c
* lib/efi_selftest/efi_selftest_variables_runtime.c
* lib/efi_selftest/efi_selftest_set_virtual_address_map.c
which test different aspects of ExitBootServices() on the sandbox.
There is no need to duplicate these.
Best regards
Heinrich
next prev parent reply other threads:[~2024-08-08 21:17 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 12:58 [PATCH v2 00/39] efi: Add a test for EFI bootmeth Simon Glass
2024-08-06 12:58 ` [PATCH v2 01/39] nvmxip: Drop the message on probe Simon Glass
2024-08-06 12:58 ` [PATCH v2 02/39] nvmxip: Avoid probing on boot Simon Glass
2024-08-06 12:58 ` [PATCH v2 03/39] bootstd: Add UT_TESTF_CONSOLE_REC to bootflow tests Simon Glass
2024-08-06 12:58 ` [PATCH v2 04/39] test/py: Fix some pylint warnings in test_ut.py Simon Glass
2024-08-06 12:58 ` [PATCH v2 05/39] scripts: Update pylint.base Simon Glass
2024-08-06 12:58 ` [PATCH v2 06/39] bootstd: Create a function to reset USB Simon Glass
2024-08-07 1:56 ` Heinrich Schuchardt
2024-08-07 14:36 ` Simon Glass
2024-08-08 21:07 ` Heinrich Schuchardt
2024-08-11 14:50 ` Simon Glass
2024-08-06 12:58 ` [PATCH v2 07/39] usb: Drop old non-DM code Simon Glass
2024-08-06 12:58 ` [PATCH v2 08/39] log: Add a new log category for the console Simon Glass
2024-08-06 12:58 ` [PATCH v2 09/39] usb: Add DEV_FLAGS_DM to stdio for USB keyboard Simon Glass
2024-08-06 12:58 ` [PATCH v2 10/39] dm: usb: Deal with USB keyboard persisting across tests Simon Glass
2024-08-06 12:58 ` [PATCH v2 11/39] test: mbr: Adjust test to use lower-case hex Simon Glass
2024-08-06 12:58 ` [PATCH v2 12/39] test: mbr: Adjust test to drop 0x Simon Glass
2024-08-06 12:58 ` [PATCH v2 13/39] sandbox: Change the range used for memory-mapping tags Simon Glass
2024-08-06 12:58 ` [PATCH v2 14/39] sandbox: Update cpu to use logging Simon Glass
2024-08-06 12:58 ` [PATCH v2 15/39] sandbox: Unmap old tags Simon Glass
2024-08-06 12:58 ` [PATCH v2 16/39] sandbox: Add some debugging to pci_io Simon Glass
2024-08-06 12:58 ` [PATCH v2 17/39] sandbox: Implement reference counting for address mapping Simon Glass
2024-08-06 12:58 ` [PATCH v2 18/39] mmc: Use map_sysmem() with buffers in the mmc command Simon Glass
2024-08-06 12:58 ` [PATCH v2 19/39] read: Use map_sysmem() with buffers in the read command Simon Glass
2024-08-08 10:20 ` Ilias Apalodimas
2024-08-06 12:58 ` [PATCH v2 20/39] cmd: Fix memory-mapping in cmp command Simon Glass
2024-08-06 12:58 ` [PATCH v2 21/39] test: mbr: Unmap the buffers after use Simon Glass
2024-08-08 10:13 ` Ilias Apalodimas
2024-08-06 12:58 ` [PATCH v2 22/39] test: mbr: Use a constant for the block size Simon Glass
2024-08-08 10:15 ` Ilias Apalodimas
2024-08-06 12:58 ` [PATCH v2 23/39] test: mbr: Use RAM for the buffers Simon Glass
2024-08-06 12:58 ` [PATCH v2 24/39] test: mbr: Drop a duplicate test Simon Glass
2024-08-06 12:58 ` [PATCH v2 25/39] efi: Use puts() in cout so that console recording works Simon Glass
2024-08-07 0:37 ` Heinrich Schuchardt
2024-08-06 12:58 ` [PATCH v2 26/39] efi_loader: Put back copyright message Simon Glass
2024-08-06 12:58 ` [PATCH v2 27/39] efi_loader: Rename and move CMD_BOOTEFI_HELLO_COMPILE Simon Glass
2024-08-07 1:01 ` Heinrich Schuchardt
2024-08-06 12:58 ` [PATCH v2 28/39] efi_loader: Shorten the app rules Simon Glass
2024-08-07 1:04 ` Heinrich Schuchardt
2024-08-06 12:58 ` [PATCH v2 29/39] efi_loader: Shorten the app rules further Simon Glass
2024-08-07 1:05 ` Heinrich Schuchardt
2024-08-07 7:00 ` Ilias Apalodimas
2024-08-06 12:58 ` [PATCH v2 30/39] efi: Show the vendor in helloworld Simon Glass
2024-08-07 1:22 ` Heinrich Schuchardt
2024-08-06 12:58 ` [PATCH v2 31/39] Revert "bootdev: avoid infinite probe loop" Simon Glass
2024-08-07 1:27 ` Heinrich Schuchardt
2024-08-06 12:58 ` [PATCH v2 32/39] bootstd: Make bootdev_next_prio() continue after failure Simon Glass
2024-08-06 12:58 ` [PATCH v2 33/39] efi: Use the same filename for all sandbox builds Simon Glass
2024-08-08 10:18 ` Ilias Apalodimas
2024-08-06 12:58 ` [PATCH v2 34/39] bootstd: Add debugging for efi bootmeth Simon Glass
2024-08-06 12:58 ` [PATCH v2 35/39] efi: Disable ANSI output for tests Simon Glass
2024-08-06 12:58 ` [PATCH v2 36/39] efi: Add a test app Simon Glass
2024-08-07 1:42 ` Heinrich Schuchardt
2024-08-07 14:36 ` Simon Glass
2024-08-08 21:17 ` Heinrich Schuchardt [this message]
2024-08-11 14:50 ` Simon Glass
2024-08-06 12:58 ` [PATCH v2 37/39] efi: Avoid using sandbox virtio devices Simon Glass
2024-08-07 1:47 ` Heinrich Schuchardt
2024-08-07 1:56 ` Tom Rini
2024-08-08 18:44 ` Simon Glass
2024-08-08 20:06 ` Tom Rini
2024-08-11 14:50 ` Simon Glass
2024-08-14 17:56 ` Tom Rini
2024-08-15 20:33 ` Simon Glass
2024-08-15 22:56 ` Tom Rini
2024-08-16 1:34 ` Simon Glass
2024-08-16 23:53 ` Simon Glass
2024-08-22 15:13 ` Tom Rini
2024-08-22 17:11 ` Simon Glass
2024-08-06 12:58 ` [PATCH v2 38/39] test: Set up an image suitable for EFI testing Simon Glass
2024-08-06 12:58 ` [PATCH v2 39/39] efi: Add a test for the efi bootmeth Simon Glass
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=b8409d9e-58d6-4b2e-b0df-9b77cdded67f@gmx.de \
--to=xypron.glpk@gmx.de \
--cc=abdellatif.elkhlifi@arm.com \
--cc=akashi.tkhro@gmail.com \
--cc=bmeng.cn@gmail.com \
--cc=caleb.connolly@linaro.org \
--cc=ilias.apalodimas@linaro.org \
--cc=j-humphreys@ti.com \
--cc=kojima.masahisa@socionext.com \
--cc=michal.simek@amd.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox