2 * Copyright (c) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
6 * EFI information obtained here:
7 * http://wiki.phoenix.com/wiki/index.php/EFI_BOOT_SERVICES
13 #include <debug_uart.h>
15 #include <linux/err.h>
16 #include <linux/types.h>
20 DECLARE_GLOBAL_DATA_PTR;
23 * Unfortunately we cannot access any code outside what is built especially
24 * for the stub. lib/string.c is already being built for the U-Boot payload
25 * so it uses the wrong compiler flags. Add our own memset() here.
27 static void efi_memset(void *ptr, int ch, int size)
36 * Since the EFI stub cannot access most of the U-Boot code, add our own
37 * simple console output functions here. The EFI app will not use these since
38 * it can use the normal console.
40 void efi_putc(struct efi_priv *priv, const char ch)
42 struct efi_simple_text_output_protocol *con = priv->sys_table->con_out;
47 con->output_string(con, ucode);
50 void efi_puts(struct efi_priv *priv, const char *str)
53 efi_putc(priv, *str++);
56 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
57 struct efi_system_table *sys_table)
59 efi_guid_t loaded_image_guid = LOADED_IMAGE_PROTOCOL_GUID;
60 struct efi_boot_services *boot = sys_table->boottime;
61 struct efi_loaded_image *loaded_image;
64 efi_memset(priv, '\0', sizeof(*priv));
65 priv->sys_table = sys_table;
66 priv->boot = sys_table->boottime;
67 priv->parent_image = image;
68 priv->run = sys_table->runtime;
70 efi_puts(priv, "U-Boot EFI ");
71 efi_puts(priv, banner);
74 ret = boot->open_protocol(priv->parent_image, &loaded_image_guid,
75 (void **)&loaded_image, &priv->parent_image,
76 NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
78 efi_puts(priv, "Failed to get loaded image protocol\n");
81 priv->image_data_type = loaded_image->image_data_type;
86 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp)
88 struct efi_boot_services *boot = priv->boot;
91 *retp = boot->allocate_pool(priv->image_data_type, size, &buf);
96 void efi_free(struct efi_priv *priv, void *ptr)
98 struct efi_boot_services *boot = priv->boot;
100 boot->free_pool(ptr);