Compare commits

...

8 Commits
vbh3 ... efip

Author SHA1 Message Date
Simon Glass
0a09ff35b8 efi_loader: Test that active-DMA devices are removed
When exit-boot-services is called, active devices should be removed.

Update testapp to call this method and check that the USB controller is
removed as expected.

Series-to: u-boot
Series-cc: heinrich, ilias
Cover-letter:
efi_loader: Complete the bootflow_efi() test
This test was hamstrung in code review so this series is an attempt to
complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still
uses the defunct board_quiesce_devices() so a nice cleanup would be to
call the bootm function instead, with suitable modifications. That would
allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so
far.
END
2025-01-06 05:45:59 -07:00
Simon Glass
2c43bef7c1 efi_loader: Check that the bootflow is not removed by app
The bootflow should not be affected by the app running and returning.
Add a check that it is still valid after the app completes execution.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 13:24:56 -07:00
Simon Glass
fe023fbdae efi_loader: Update testapp to get memory map correctly
Allocate enough memory for the memory map so that it can be received
successfully.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 13:24:56 -07:00
Simon Glass
a5a806a3ad efi_loader: Check memory allocations in bootflow_efi test()
Add checks that all memory allocations complete successfully and that
only expected parameters are provided. Check that memory addresses are
within range.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 13:24:56 -07:00
Simon Glass
77bf846ebe efi_loader: Correct bounce-buffer setup
This should set the bounce buffer to a pointer, not an address. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 13:24:50 -07:00
Simon Glass
559e094354 efi_loader: Return the memory map in pointer format
An EFI app expects pointers to be returned, cast to u64. The conversion
to use addresses missed this, so fix the call.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 13:24:49 -07:00
Simon Glass
8394d4f70a efi_loader: Fix display of addresses in log
The allocate/free-pages functions return an address, so there is no need
to convert it. Fix this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Fixes: c824a96d76 ("efi_loader: Use the log with memory-related...")
2025-01-05 10:58:45 -07:00
Simon Glass
881dd52cf3 sandbox: Make USB controller as having active DMA
Set the DM_FLAG_ACTIVE_DMA flag on this device so that it is removed
before booting.

Signed-off-by: Simon Glass <sjg@chromium.org>
2025-01-05 10:58:27 -07:00
5 changed files with 122 additions and 8 deletions

View File

@@ -180,4 +180,5 @@ U_BOOT_DRIVER(usb_sandbox) = {
.probe = sandbox_usb_probe,
.ops = &sandbox_usb_ops,
.priv_auto = sizeof(struct sandbox_usb_ctrl),
.flags = DM_FLAG_ACTIVE_DMA,
};

View File

@@ -340,8 +340,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
show_ulong("pgs", (ulong)rec->pages);
show_addr("mem", (ulong)rec->memory);
if (rec_hdr->ended) {
show_addr("*mem",
(ulong)map_to_sysmem((void *)rec->e_memory));
show_addr("*mem", rec->e_memory);
show_ret(rec_hdr->e_ret);
}
break;
@@ -349,7 +348,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
case EFILT_FREE_PAGES: {
struct efil_free_pages *rec = start;
show_addr("mem", map_to_sysmem((void *)rec->memory));
show_addr("mem", rec->memory);
show_ulong("pag", (ulong)rec->pages);
if (rec_hdr->ended)
show_ret(rec_hdr->e_ret);

View File

@@ -735,10 +735,11 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
list_for_each_entry(lmem, &efi_mem, link) {
memory_map->type = lmem->type;
memory_map->reserved = 0;
memory_map->physical_start = lmem->base;
memory_map->physical_start = (u64)(ulong)map_sysmem(lmem->base,
lmem->num_pages * EFI_PAGE_SIZE);
/* virtual and physical are always the same */
memory_map->virtual_start = lmem->base;
memory_map->virtual_start = memory_map->physical_start;
memory_map->num_pages = lmem->num_pages;
memory_map->attribute = lmem->attribute;
memory_map--;
@@ -836,11 +837,11 @@ int efi_memory_init(void)
uint64_t efi_bounce_buffer_addr = 0xffffffff;
if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_BOOT_SERVICES_DATA,
(64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
SZ_64M >> EFI_PAGE_SHIFT,
&efi_bounce_buffer_addr) != EFI_SUCCESS)
return -1;
efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
efi_bounce_buffer = map_sysmem(efi_bounce_buffer_addr, SZ_64M);
#endif
return 0;

View File

@@ -28,7 +28,12 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
struct efi_system_table *systab)
{
struct efi_loaded_image *loaded_image;
struct efi_mem_desc *map;
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;
@@ -48,6 +53,38 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
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);
if (ret != EFI_BUFFER_TOO_SMALL) {
con_out->output_string(con_out, u"map error A\n");
return ret;
}
ret = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
(void **)&map);
if (ret) {
con_out->output_string(con_out, u"map error B\n");
return ret;
}
/* Allocate extra space for newly allocated memory */
map_size += sizeof(struct efi_mem_desc);
ret = boottime->get_memory_map(&map_size, map, &map_key, &desc_size,
&desc_version);
if (ret) {
con_out->output_string(con_out, u"map error C\n");
return ret;
}
/* exit boot services so that this part of U-Boot can be tested */
con_out->output_string(con_out, u"Exiting boot services\n");
ret = boottime->exit_boot_services(handle, map_key);
if (ret) {
con_out->output_string(con_out, u"Failed exit-boot-services\n");
return ret;
}
/* now exit for real */
con_out->output_string(con_out, u"Exiting test app\n");
ret = boottime->exit(handle, ret, 0, NULL);

View File

@@ -6,6 +6,7 @@
* Written by Simon Glass <sjg@chromium.org>
*/
#include <bloblist.h>
#include <bootdev.h>
#include <bootflow.h>
#include <bootmeth.h>
@@ -14,6 +15,7 @@
#include <dm.h>
#include <efi.h>
#include <efi_loader.h>
#include <efi_log.h>
#include <expo.h>
#include <mapmem.h>
#ifdef CONFIG_SANDBOX
@@ -21,6 +23,7 @@
#endif
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <dm/uclass-internal.h>
#include <linux/libfdt.h>
#include <test/suites.h>
#include <test/ut.h>
@@ -1271,10 +1274,14 @@ BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
/* Test EFI bootmeth */
static int bootflow_efi(struct unit_test_state *uts)
{
struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
static const char *order[] = {"mmc1", "usb", NULL};
struct efil_rec_hdr *rec_hdr;
struct bootstd_priv *std;
struct udevice *bootstd;
const char **old_order;
struct udevice *usb;
int i;
ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
std = dev_get_priv(bootstd);
@@ -1310,6 +1317,10 @@ static int bootflow_efi(struct unit_test_state *uts)
systab.fw_vendor = test_vendor;
/* the USB block-device should have beeen probed */
ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
ut_assert(device_active(usb));
ut_asserteq(1, run_command("bootflow boot", 0));
ut_assert_nextline(
"** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi");
@@ -1320,12 +1331,77 @@ static int bootflow_efi(struct unit_test_state *uts)
/* TODO: Why the \r ? */
ut_assert_nextline("U-Boot test app for EFI_LOADER\r");
ut_assert_nextline("Exiting boot services");
ut_assert_nextline("Exiting test app");
ut_assert_nextline("Boot failed (err=-14)");
ut_assert_console_end();
ut_assertok(bootstd_test_drop_bootdev_order(uts));
/* make sure the bootflow is still present */
ut_assertnonnull(std->cur_bootflow);
/* the USB block-device should have beeen removed */
ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
ut_assert(!device_active(usb));
/* check memory allocations are as expected */
if (!hdr)
return 0;
for (i = 0, rec_hdr = (void *)hdr + sizeof(*hdr);
(void *)rec_hdr - (void *)hdr < hdr->upto;
i++, rec_hdr = (void *)rec_hdr + rec_hdr->size) {
void *start = (void *)rec_hdr + sizeof(struct efil_rec_hdr);
switch (rec_hdr->tag) {
case EFILT_ALLOCATE_PAGES: {
struct efil_allocate_pages *rec = start;
ut_assert(rec_hdr->ended);
ut_assertok(rec_hdr->e_ret);
ut_asserteq(EFI_ALLOCATE_ANY_PAGES, rec->type);
log_debug("rec->memory_type %d\n", rec->memory_type);
ut_assert(rec->memory_type == EFI_RUNTIME_SERVICES_DATA ||
rec->memory_type == EFI_BOOT_SERVICES_DATA ||
rec->memory_type == EFI_ACPI_MEMORY_NVS ||
rec->memory_type == EFI_LOADER_CODE);
ut_assert(rec->e_memory < gd->ram_size);
break;
}
case EFILT_FREE_PAGES: {
struct efil_free_pages *rec = start;
ut_assert(rec_hdr->ended);
ut_assertok(rec_hdr->e_ret);
ut_assert(rec->memory < gd->ram_size);
break;
}
case EFILT_ALLOCATE_POOL: {
struct efil_allocate_pool *rec = start;
ut_assert(rec_hdr->ended);
ut_assertok(rec_hdr->e_ret);
log_debug("rec->pool_type %d\n", rec->pool_type);
ut_assert(rec->pool_type == EFI_RUNTIME_SERVICES_DATA ||
rec->pool_type == EFI_BOOT_SERVICES_DATA ||
rec->pool_type == EFI_ACPI_MEMORY_NVS);
ut_assert(map_to_sysmem((void *)rec->e_buffer) <
gd->ram_size);
break;
}
case EFILT_FREE_POOL: {
struct efil_free_pool *rec = start;
ut_assert(rec_hdr->ended);
ut_assertok(rec_hdr->e_ret);
ut_assert(map_to_sysmem((void *)rec->buffer) <
gd->ram_size);
break;
}
default:
break;
}
}
return 0;
}