efi_loader: Add a test app
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. There was a considerable amount of discussion about whether it is OK to call exit-boot-services and then return to U-Boot. This is not normally done in a real application, since exit-boot-services is used to completely disconnect from U-Boot. For now, this part is skipped. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:

committed by
Heinrich Schuchardt

parent
b1e9a8bba4
commit
34d2faaef6
@@ -567,6 +567,16 @@ config BOOTEFI_HELLO_COMPILE
|
|||||||
No additional space will be required in the resulting U-Boot binary
|
No additional space will be required in the resulting U-Boot binary
|
||||||
when this option is enabled.
|
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
|
endif
|
||||||
|
|
||||||
source "lib/efi/Kconfig"
|
source "lib/efi/Kconfig"
|
||||||
|
@@ -20,6 +20,7 @@ apps-$(CONFIG_EFI_LOAD_FILE2_INITRD) += initrddump
|
|||||||
ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
|
ifeq ($(CONFIG_GENERATE_ACPI_TABLE),)
|
||||||
apps-y += dtbdump
|
apps-y += dtbdump
|
||||||
endif
|
endif
|
||||||
|
apps-$(CONFIG_BOOTEFI_TESTAPP_COMPILE) += testapp
|
||||||
|
|
||||||
obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
|
obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
|
||||||
obj-$(CONFIG_EFI_BOOTMGR) += efi_bootmgr.o
|
obj-$(CONFIG_EFI_BOOTMGR) += efi_bootmgr.o
|
||||||
|
56
lib/efi_loader/testapp.c
Normal file
56
lib/efi_loader/testapp.c
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
/*
|
||||||
|
* EFI test 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;
|
||||||
|
|
||||||
|
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:
|
||||||
|
con_out->output_string(con_out, u"Exiting test app\n");
|
||||||
|
ret = boottime->exit(handle, ret, 0, NULL);
|
||||||
|
|
||||||
|
/* We should never arrive here */
|
||||||
|
return ret;
|
||||||
|
}
|
Reference in New Issue
Block a user