efi: Move efi_store_memory_map() to the stub

This function is not called from the app at present. Even if it were, it
would be called later, after stdio is working, so there is no need to
use printhex2() and the like.

Move the function into the stub.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-08-07 15:28:05 -06:00
parent c6883b8a71
commit bd5194356b
3 changed files with 57 additions and 59 deletions

View File

@@ -191,51 +191,3 @@ void efi_free_pool(void *ptr)
efi_free(priv, ptr);
}
int efi_store_memory_map(struct efi_priv *priv)
{
struct efi_boot_services *boot = priv->sys_table->boottime;
efi_uintn_t size, desc_size;
efi_status_t ret;
/* Get the memory map so we can switch off EFI */
size = 0;
ret = boot->get_memory_map(&size, NULL, &priv->memmap_key,
&priv->memmap_desc_size,
&priv->memmap_version);
if (ret != EFI_BUFFER_TOO_SMALL) {
/*
* Note this function avoids using printf() since it is not
* available in the stub
*/
printhex2(EFI_BITS_PER_LONG);
putc(' ');
printhex2(ret);
puts(" No memory map\n");
return ret;
}
/*
* Since doing a malloc() may change the memory map and also we want to
* be able to read the memory map in efi_call_exit_boot_services()
* below, after more changes have happened
*/
priv->memmap_alloc = size + 1024;
priv->memmap_size = priv->memmap_alloc;
priv->memmap_desc = efi_malloc(priv, size, &ret);
if (!priv->memmap_desc) {
printhex2(ret);
puts(" No memory for memory descriptor\n");
return ret;
}
ret = boot->get_memory_map(&priv->memmap_size, priv->memmap_desc,
&priv->memmap_key, &desc_size,
&priv->memmap_version);
if (ret) {
printhex2(ret);
puts(" Can't get memory map\n");
return ret;
}
return 0;
}

View File

@@ -127,6 +127,63 @@ static void efi_copy_code(struct efi_priv *priv)
(ulong)_binary_u_boot_bin_start);
}
/**
* efi_store_memory_map() - Collect the memory-map info from EFI
*
* Collect the memory info and store it for later use, e.g. in calling
* exit_boot_services()
*
* @priv: Pointer to private EFI structure
* Returns: 0 if OK, non-zero on error
*/
static int efi_store_memory_map(struct efi_priv *priv)
{
struct efi_boot_services *boot = priv->sys_table->boottime;
efi_uintn_t size, desc_size;
efi_status_t ret;
/* Get the memory map so we can switch off EFI */
size = 0;
ret = boot->get_memory_map(&size, NULL, &priv->memmap_key,
&priv->memmap_desc_size,
&priv->memmap_version);
if (ret != EFI_BUFFER_TOO_SMALL) {
/*
* Note this function avoids using printf() since it is not
* available in the stub
*/
printhex2(EFI_BITS_PER_LONG);
putc(' ');
printhex2(ret);
puts(" No memory map\n");
return ret;
}
/*
* Since doing a malloc() may change the memory map and also we want to
* be able to read the memory map in efi_call_exit_boot_services()
* below, after more changes have happened
*/
priv->memmap_alloc = size + 1024;
priv->memmap_size = priv->memmap_alloc;
priv->memmap_desc = efi_malloc(priv, size, &ret);
if (!priv->memmap_desc) {
printhex2(ret);
puts(" No memory for memory descriptor\n");
return ret;
}
ret = boot->get_memory_map(&priv->memmap_size, priv->memmap_desc,
&priv->memmap_key, &desc_size,
&priv->memmap_version);
if (ret) {
printhex2(ret);
puts(" Can't get memory map\n");
return ret;
}
return 0;
}
/**
* efi_main() - Start an EFI image
*