
From: Simon Glass <sjg@chromium.org> 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> --- include/efi.h | 2 + include/efi_stub.h | 20 +++++++++ lib/efi_client/stub.c | 94 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/include/efi.h b/include/efi.h index 99a209e86c6..7a725343616 100644 --- a/include/efi.h +++ b/include/efi.h @@ -473,6 +473,7 @@ static inline struct efi_mem_desc *efi_get_next_mem_desc( * to U-Boot * @info_size: Size of the info list @info in bytes * @next_hdr: Pointer to where to put the next header when adding to the list + * @jump_addr: Address to jump to to start U-Boot */ struct efi_priv { efi_handle_t parent_image; @@ -496,6 +497,7 @@ struct efi_priv { struct efi_info_hdr *info; unsigned int info_size; void *next_hdr; + ulong jump_addr; }; /* diff --git a/include/efi_stub.h b/include/efi_stub.h index d788ce4984e..8dcde1b61d1 100644 --- a/include/efi_stub.h +++ b/include/efi_stub.h @@ -8,6 +8,7 @@ #ifndef _EFI_STUB_H #define _EFI_STUB_H +#include <efi.h> #include <linux/types.h> struct efi_priv; @@ -100,6 +101,25 @@ int setup_info_table(struct efi_priv *priv, int size); void add_entry_addr(struct efi_priv *priv, enum efi_entry_t type, void *ptr1, int size1, void *ptr2, int size2); +/** + * arch_efi_main_init() - Set up the stub ready for use + * + * @priv: Pointer to private information + * @boot: Boot-services table + * Return: 0 if OK, or EFI error code + */ +efi_status_t arch_efi_main_init(struct efi_priv *priv, + struct efi_boot_services *boot); + +/** + * arch_efi_jump_to_payload() - Jump to the U-Boot payload + * + * Jumps to U-Boot in an arch-specific way + * + * @priv: Pointer to private information + */ +void arch_efi_jump_to_payload(struct efi_priv *priv); + /* true if we must use the hardware UART directory (EFI not available) */ extern bool use_hw_uart; diff --git a/lib/efi_client/stub.c b/lib/efi_client/stub.c index fad669cb64d..2681714d068 100644 --- a/lib/efi_client/stub.c +++ b/lib/efi_client/stub.c @@ -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; +} -- 2.43.0