1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
5 * EFI information obtained here:
6 * http://wiki.phoenix.com/wiki/index.php/EFI_BOOT_SERVICES
12 #include <debug_uart.h>
14 #include <linux/err.h>
15 #include <linux/types.h>
20 * Unfortunately we cannot access any code outside what is built especially
21 * for the stub. lib/string.c is already being built for the U-Boot payload
22 * so it uses the wrong compiler flags. Add our own memset() here.
24 static void efi_memset(void *ptr, int ch, int size)
33 * Since the EFI stub cannot access most of the U-Boot code, add our own
34 * simple console output functions here. The EFI app will not use these since
35 * it can use the normal console.
37 void efi_putc(struct efi_priv *priv, const char ch)
39 struct efi_simple_text_output_protocol *con = priv->sys_table->con_out;
44 con->output_string(con, ucode);
47 void efi_puts(struct efi_priv *priv, const char *str)
50 efi_putc(priv, *str++);
53 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
54 struct efi_system_table *sys_table)
56 efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_PROTOCOL_GUID;
57 struct efi_boot_services *boot = sys_table->boottime;
58 struct efi_loaded_image *loaded_image;
61 efi_memset(priv, '\0', sizeof(*priv));
62 priv->sys_table = sys_table;
63 priv->boot = sys_table->boottime;
64 priv->parent_image = image;
65 priv->run = sys_table->runtime;
67 efi_puts(priv, "U-Boot EFI ");
68 efi_puts(priv, banner);
71 ret = boot->open_protocol(priv->parent_image, &loaded_image_guid,
72 (void **)&loaded_image, priv->parent_image,
73 NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
75 efi_puts(priv, "Failed to get loaded image protocol\n");
78 priv->image_data_type = loaded_image->image_data_type;
83 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp)
85 struct efi_boot_services *boot = priv->boot;
88 *retp = boot->allocate_pool(priv->image_data_type, size, &buf);
93 void efi_free(struct efi_priv *priv, void *ptr)
95 struct efi_boot_services *boot = priv->boot;