efi_loader: use logging for bootefi command

Log messages of the bootefi command instead of simply printing them to the
console.

Do not show "## Application terminated" message when the UEFI binary
completed successfully.

Adjust the python tests testing for '## Application terminated'.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
This commit is contained in:
Heinrich Schuchardt 2020-07-17 20:21:00 +02:00
parent bf758125d8
commit c001837400
3 changed files with 32 additions and 28 deletions

View File

@ -5,6 +5,8 @@
* Copyright (c) 2016 Alexander Graf * Copyright (c) 2016 Alexander Graf
*/ */
#define LOG_CATEGORY LOGC_EFI
#include <common.h> #include <common.h>
#include <charset.h> #include <charset.h>
#include <command.h> #include <command.h>
@ -14,6 +16,7 @@
#include <env.h> #include <env.h>
#include <errno.h> #include <errno.h>
#include <image.h> #include <image.h>
#include <log.h>
#include <malloc.h> #include <malloc.h>
#include <linux/libfdt.h> #include <linux/libfdt.h>
#include <linux/libfdt_env.h> #include <linux/libfdt_env.h>
@ -62,7 +65,7 @@ static efi_status_t set_load_options(efi_handle_t handle, const char *env_var,
size = utf8_utf16_strlen(env) + 1; size = utf8_utf16_strlen(env) + 1;
loaded_image_info->load_options = calloc(size, sizeof(u16)); loaded_image_info->load_options = calloc(size, sizeof(u16));
if (!loaded_image_info->load_options) { if (!loaded_image_info->load_options) {
printf("ERROR: Out of memory\n"); log_err("ERROR: Out of memory\n");
EFI_CALL(systab.boottime->close_protocol(handle, EFI_CALL(systab.boottime->close_protocol(handle,
&efi_guid_loaded_image, &efi_guid_loaded_image,
efi_root, NULL)); efi_root, NULL));
@ -137,7 +140,7 @@ static efi_status_t copy_fdt(void **fdtp)
EFI_ACPI_RECLAIM_MEMORY, fdt_pages, EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
&new_fdt_addr); &new_fdt_addr);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
printf("ERROR: Failed to reserve space for FDT\n"); log_err("ERROR: Failed to reserve space for FDT\n");
goto done; goto done;
} }
} }
@ -156,8 +159,8 @@ static void efi_reserve_memory(u64 addr, u64 size)
addr = (uintptr_t)map_sysmem(addr, 0); addr = (uintptr_t)map_sysmem(addr, 0);
if (efi_add_memory_map(addr, size, if (efi_add_memory_map(addr, size,
EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS) EFI_RESERVED_MEMORY_TYPE) != EFI_SUCCESS)
printf("Reserved memory mapping failed addr %llx size %llx\n", log_err("Reserved memory mapping failed addr %llx size %llx\n",
addr, size); addr, size);
} }
/** /**
@ -252,7 +255,7 @@ efi_status_t efi_install_fdt(void *fdt)
*/ */
#if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
if (fdt) { if (fdt) {
printf("ERROR: can't have ACPI table and device tree.\n"); log_err("ERROR: can't have ACPI table and device tree.\n");
return EFI_LOAD_ERROR; return EFI_LOAD_ERROR;
} }
#else #else
@ -272,13 +275,13 @@ efi_status_t efi_install_fdt(void *fdt)
if (!fdt_opt) { if (!fdt_opt) {
fdt_opt = env_get("fdtcontroladdr"); fdt_opt = env_get("fdtcontroladdr");
if (!fdt_opt) { if (!fdt_opt) {
printf("ERROR: need device tree\n"); log_err("ERROR: need device tree\n");
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }
} }
fdt_addr = simple_strtoul(fdt_opt, NULL, 16); fdt_addr = simple_strtoul(fdt_opt, NULL, 16);
if (!fdt_addr) { if (!fdt_addr) {
printf("ERROR: invalid $fdt_addr or $fdtcontroladdr\n"); log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n");
return EFI_LOAD_ERROR; return EFI_LOAD_ERROR;
} }
fdt = map_sysmem(fdt_addr, 0); fdt = map_sysmem(fdt_addr, 0);
@ -286,19 +289,19 @@ efi_status_t efi_install_fdt(void *fdt)
/* Install device tree */ /* Install device tree */
if (fdt_check_header(fdt)) { if (fdt_check_header(fdt)) {
printf("ERROR: invalid device tree\n"); log_err("ERROR: invalid device tree\n");
return EFI_LOAD_ERROR; return EFI_LOAD_ERROR;
} }
/* Prepare device tree for payload */ /* Prepare device tree for payload */
ret = copy_fdt(&fdt); ret = copy_fdt(&fdt);
if (ret) { if (ret) {
printf("ERROR: out of memory\n"); log_err("ERROR: out of memory\n");
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
if (image_setup_libfdt(&img, fdt, 0, NULL)) { if (image_setup_libfdt(&img, fdt, 0, NULL)) {
printf("ERROR: failed to process device tree\n"); log_err("ERROR: failed to process device tree\n");
return EFI_LOAD_ERROR; return EFI_LOAD_ERROR;
} }
@ -308,7 +311,7 @@ efi_status_t efi_install_fdt(void *fdt)
/* Install device tree as UEFI table */ /* Install device tree as UEFI table */
ret = efi_install_configuration_table(&efi_guid_fdt, fdt); ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
printf("ERROR: failed to install device tree\n"); log_err("ERROR: failed to install device tree\n");
return ret; return ret;
} }
#endif /* GENERATE_ACPI_TABLE */ #endif /* GENERATE_ACPI_TABLE */
@ -339,10 +342,13 @@ static efi_status_t do_bootefi_exec(efi_handle_t handle)
/* Call our payload! */ /* Call our payload! */
ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data)); ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data));
printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); if (ret != EFI_SUCCESS) {
if (ret && exit_data) { log_err("## Application failed, r = %lu\n",
printf("## %ls\n", exit_data); ret & ~EFI_ERROR_MASK);
efi_free_pool(exit_data); if (exit_data) {
log_err("## %ls\n", exit_data);
efi_free_pool(exit_data);
}
} }
efi_restore_gd(); efi_restore_gd();
@ -364,7 +370,7 @@ static int do_efibootmgr(void)
ret = efi_bootmgr_load(&handle); ret = efi_bootmgr_load(&handle);
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
printf("EFI boot manager: Cannot load any image\n"); log_notice("EFI boot manager: Cannot load any image\n");
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
@ -611,8 +617,8 @@ static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
/* Initialize EFI drivers */ /* Initialize EFI drivers */
ret = efi_init_obj_list(); ret = efi_init_obj_list();
if (ret != EFI_SUCCESS) { if (ret != EFI_SUCCESS) {
printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
ret & ~EFI_ERROR_MASK); ret & ~EFI_ERROR_MASK);
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }

View File

@ -420,12 +420,11 @@ def test_efi_fit_launch(u_boot_console):
fit_config = 'config-efi-fdt' if enable_fdt else 'config-efi-nofdt' fit_config = 'config-efi-fdt' if enable_fdt else 'config-efi-nofdt'
# Try booting. # Try booting.
cons.run_command( output = cons.run_command('bootm %x#%s' % (addr, fit_config))
'bootm %x#%s' % (addr, fit_config), wait_for_prompt=False)
if enable_fdt: if enable_fdt:
cons.wait_for('Booting using the fdt blob') assert 'Booting using the fdt blob' in output
cons.wait_for('Hello, world') assert 'Hello, world' in output
cons.wait_for('## Application terminated, r = 0') assert '## Application failed' not in output
cons.restart_uboot() cons.restart_uboot()
cons = u_boot_console cons = u_boot_console

View File

@ -161,8 +161,8 @@ def test_efi_helloworld_net(u_boot_console):
output = u_boot_console.run_command('bootefi %x' % addr) output = u_boot_console.run_command('bootefi %x' % addr)
expected_text = 'Hello, world' expected_text = 'Hello, world'
assert expected_text in output assert expected_text in output
expected_text = '## Application terminated, r = 0' expected_text = '## Application failed'
assert expected_text in output assert expected_text not in output
@pytest.mark.buildconfigspec('cmd_bootefi_hello') @pytest.mark.buildconfigspec('cmd_bootefi_hello')
def test_efi_helloworld_builtin(u_boot_console): def test_efi_helloworld_builtin(u_boot_console):
@ -198,8 +198,7 @@ def test_efi_grub_net(u_boot_console):
# Then exit cleanly # Then exit cleanly
u_boot_console.wait_for('grub>') u_boot_console.wait_for('grub>')
output = u_boot_console.run_command('exit', wait_for_prompt=False, wait_for_echo=False) u_boot_console.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
u_boot_console.wait_for('r = 0') u_boot_console.wait_for('=>')
# And give us our U-Boot prompt back # And give us our U-Boot prompt back
u_boot_console.run_command('') u_boot_console.run_command('')