efi: Create a common efi_main() implementation for the stub
At present x86 and ARM have different implementations, but they are similar enough that it is not too hard to unify them. Create a new common function, with arch-specific pieces at the start (setting up the address to which to copy U-Boot) and end (to jump to U-Boot). For now, nothing uses this code. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -119,3 +119,97 @@ void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type, void *ptr1,
|
||||
memcpy((void *)(hdr + 1) + size1, ptr2, size2);
|
||||
priv->info->total_size = (ulong)priv->next_hdr - (ulong)priv->info;
|
||||
}
|
||||
|
||||
static void efi_copy_code(struct efi_priv *priv)
|
||||
{
|
||||
memcpy((void *)priv->jump_addr, _binary_u_boot_bin_start,
|
||||
(ulong)_binary_u_boot_bin_end -
|
||||
(ulong)_binary_u_boot_bin_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* efi_main_common() - Start an EFI image
|
||||
*
|
||||
* This function is called by our EFI start-up code. It handles running
|
||||
* U-Boot. If it returns, EFI will continue.
|
||||
*/
|
||||
efi_status_t EFIAPI efi_main_common(efi_handle_t image,
|
||||
struct efi_system_table *sys_table)
|
||||
{
|
||||
struct efi_priv local_priv, *priv = &local_priv;
|
||||
struct efi_boot_services *boot = sys_table->boottime;
|
||||
struct efi_entry_memmap map;
|
||||
struct efi_gop *gop;
|
||||
struct efi_entry_gopmode mode;
|
||||
struct efi_entry_systable table;
|
||||
efi_guid_t efi_gop_guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
|
||||
efi_status_t ret;
|
||||
|
||||
/* initially we can use the EFI UART */
|
||||
use_hw_uart = false;
|
||||
|
||||
ret = efi_init(priv, "Payload", image, sys_table);
|
||||
if (ret) {
|
||||
printhex2(ret);
|
||||
puts(" efi_init() failed\n");
|
||||
return ret;
|
||||
}
|
||||
efi_set_priv(priv);
|
||||
|
||||
#if 0 /* to be enabled */
|
||||
ret = arch_efi_main_init(priv, boot);
|
||||
if (ret)
|
||||
return ret;
|
||||
#endif
|
||||
ret = efi_store_memory_map(priv);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = setup_info_table(priv, priv->memmap_size + 128);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = boot->locate_protocol(&efi_gop_guid, NULL, (void **)&gop);
|
||||
if (ret) {
|
||||
puts(" GOP unavailable\n");
|
||||
} else {
|
||||
mode.fb_base = gop->mode->fb_base;
|
||||
mode.fb_size = gop->mode->fb_size;
|
||||
mode.info_size = gop->mode->info_size;
|
||||
add_entry_addr(priv, EFIET_GOP_MODE, &mode, sizeof(mode),
|
||||
gop->mode->info,
|
||||
sizeof(struct efi_gop_mode_info));
|
||||
}
|
||||
|
||||
table.sys_table = (ulong)sys_table;
|
||||
add_entry_addr(priv, EFIET_SYS_TABLE, &table, sizeof(table), NULL, 0);
|
||||
|
||||
ret = efi_stub_exit_boot_services();
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* The EFI UART won't work now, switch to a debug one */
|
||||
use_hw_uart = true;
|
||||
|
||||
map.version = priv->memmap_version;
|
||||
map.desc_size = priv->memmap_desc_size;
|
||||
add_entry_addr(priv, EFIET_MEMORY_MAP, &map, sizeof(map),
|
||||
priv->memmap_desc, priv->memmap_size);
|
||||
add_entry_addr(priv, EFIET_END, NULL, 0, 0, 0);
|
||||
|
||||
efi_copy_code(priv);
|
||||
|
||||
/* This will only work if you patched your own debug uart into this file. */
|
||||
#ifdef DEBUG
|
||||
puts("EFI table at ");
|
||||
printhex8((ulong)priv->info);
|
||||
puts(" size ");
|
||||
printhex8(priv->info->total_size);
|
||||
putc('\n');
|
||||
#endif
|
||||
#if 0 /* to be enabled */
|
||||
arch_efi_jump_to_payload(priv);
|
||||
#endif
|
||||
|
||||
return EFI_LOAD_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user