Tom Rini | f739fcd | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application loader |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Heinrich Schuchardt | f6c6df7 | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 9 | #include <bootm.h> |
| 10 | #include <charset.h> |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 13 | #include <efi_loader.h> |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 14 | #include <efi_selftest.h> |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 15 | #include <errno.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
| 17 | #include <linux/libfdt_env.h> |
Alexander Graf | 354264b | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 18 | #include <mapmem.h> |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 19 | #include <memalign.h> |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Simon Glass | e275458 | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 21 | #include <asm-generic/sections.h> |
Heinrich Schuchardt | c3b11de | 2018-04-03 21:59:32 +0200 | [diff] [blame] | 22 | #include <asm-generic/unaligned.h> |
Simon Glass | e275458 | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 23 | #include <linux/linkage.h> |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 26 | |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 27 | static struct efi_device_path *bootefi_image_path; |
| 28 | static struct efi_device_path *bootefi_device_path; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 29 | |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 30 | /* |
Heinrich Schuchardt | c3b11de | 2018-04-03 21:59:32 +0200 | [diff] [blame] | 31 | * Allow unaligned memory access. |
| 32 | * |
| 33 | * This routine is overridden by architectures providing this feature. |
| 34 | */ |
| 35 | void __weak allow_unaligned(void) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | /* |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 40 | * Set the load options of an image from an environment variable. |
| 41 | * |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 42 | * @handle: the image handle |
| 43 | * @env_var: name of the environment variable |
| 44 | * Return: status code |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 45 | */ |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 46 | static efi_status_t set_load_options(efi_handle_t handle, const char *env_var) |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 47 | { |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 48 | struct efi_loaded_image *loaded_image_info; |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 49 | size_t size; |
| 50 | const char *env = env_get(env_var); |
Heinrich Schuchardt | 7086a71 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 51 | u16 *pos; |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 52 | efi_status_t ret; |
| 53 | |
| 54 | ret = EFI_CALL(systab.boottime->open_protocol( |
| 55 | handle, |
| 56 | &efi_guid_loaded_image, |
| 57 | (void **)&loaded_image_info, |
| 58 | efi_root, NULL, |
| 59 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)); |
| 60 | if (ret != EFI_SUCCESS) |
| 61 | return EFI_INVALID_PARAMETER; |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 62 | |
| 63 | loaded_image_info->load_options = NULL; |
| 64 | loaded_image_info->load_options_size = 0; |
| 65 | if (!env) |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 66 | goto out; |
| 67 | |
Heinrich Schuchardt | 7086a71 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 68 | size = utf8_utf16_strlen(env) + 1; |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 69 | loaded_image_info->load_options = calloc(size, sizeof(u16)); |
| 70 | if (!loaded_image_info->load_options) { |
| 71 | printf("ERROR: Out of memory\n"); |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 72 | EFI_CALL(systab.boottime->close_protocol(handle, |
| 73 | &efi_guid_loaded_image, |
| 74 | efi_root, NULL)); |
| 75 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 76 | } |
Heinrich Schuchardt | 7086a71 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 77 | pos = loaded_image_info->load_options; |
| 78 | utf8_utf16_strcpy(&pos, env); |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 79 | loaded_image_info->load_options_size = size * 2; |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 80 | |
| 81 | out: |
| 82 | return EFI_CALL(systab.boottime->close_protocol(handle, |
| 83 | &efi_guid_loaded_image, |
| 84 | efi_root, NULL)); |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 87 | /** |
| 88 | * copy_fdt() - Copy the device tree to a new location available to EFI |
| 89 | * |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 90 | * The FDT is copied to a suitable location within the EFI memory map. |
Heinrich Schuchardt | c3772ca | 2018-11-18 17:58:49 +0100 | [diff] [blame] | 91 | * Additional 12 KiB are added to the space in case the device tree needs to be |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 92 | * expanded later with fdt_open_into(). |
| 93 | * |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 94 | * @fdtp: On entry a pointer to the flattened device tree. |
| 95 | * On exit a pointer to the copy of the flattened device tree. |
Heinrich Schuchardt | 4574d1b | 2018-11-12 18:55:22 +0100 | [diff] [blame] | 96 | * FDT start |
| 97 | * Return: status code |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 98 | */ |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 99 | static efi_status_t copy_fdt(void **fdtp) |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 100 | { |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 101 | unsigned long fdt_ram_start = -1L, fdt_pages; |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 102 | efi_status_t ret = 0; |
| 103 | void *fdt, *new_fdt; |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 104 | u64 new_fdt_addr; |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 105 | uint fdt_size; |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 106 | int i; |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 107 | |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 108 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 109 | u64 ram_start = gd->bd->bi_dram[i].start; |
| 110 | u64 ram_size = gd->bd->bi_dram[i].size; |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 111 | |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 112 | if (!ram_size) |
| 113 | continue; |
| 114 | |
| 115 | if (ram_start < fdt_ram_start) |
| 116 | fdt_ram_start = ram_start; |
| 117 | } |
| 118 | |
Simon Glass | bc9a638 | 2018-06-18 08:08:25 -0600 | [diff] [blame] | 119 | /* |
Heinrich Schuchardt | c3772ca | 2018-11-18 17:58:49 +0100 | [diff] [blame] | 120 | * Give us at least 12 KiB of breathing room in case the device tree |
| 121 | * needs to be expanded later. |
Simon Glass | bc9a638 | 2018-06-18 08:08:25 -0600 | [diff] [blame] | 122 | */ |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 123 | fdt = *fdtp; |
Heinrich Schuchardt | c3772ca | 2018-11-18 17:58:49 +0100 | [diff] [blame] | 124 | fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000); |
| 125 | fdt_size = fdt_pages << EFI_PAGE_SHIFT; |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 126 | |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 127 | /* |
| 128 | * Safe fdt location is at 127 MiB. |
| 129 | * On the sandbox convert from the sandbox address space. |
| 130 | */ |
| 131 | new_fdt_addr = (uintptr_t)map_sysmem(fdt_ram_start + 0x7f00000 + |
| 132 | fdt_size, 0); |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 133 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Ilias Apalodimas | 29361ec | 2019-04-12 21:26:28 +0300 | [diff] [blame] | 134 | EFI_BOOT_SERVICES_DATA, fdt_pages, |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 135 | &new_fdt_addr); |
| 136 | if (ret != EFI_SUCCESS) { |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 137 | /* If we can't put it there, put it somewhere */ |
xypron.glpk@gmx.de | a44bffc | 2017-08-11 21:19:25 +0200 | [diff] [blame] | 138 | new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size); |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 139 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Ilias Apalodimas | 29361ec | 2019-04-12 21:26:28 +0300 | [diff] [blame] | 140 | EFI_BOOT_SERVICES_DATA, fdt_pages, |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 141 | &new_fdt_addr); |
| 142 | if (ret != EFI_SUCCESS) { |
Alexander Graf | 85a6e9b | 2017-07-03 13:32:35 +0200 | [diff] [blame] | 143 | printf("ERROR: Failed to reserve space for FDT\n"); |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 144 | goto done; |
Alexander Graf | 85a6e9b | 2017-07-03 13:32:35 +0200 | [diff] [blame] | 145 | } |
Alexander Graf | ad0c1a3 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 146 | } |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 147 | new_fdt = (void *)(uintptr_t)new_fdt_addr; |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 148 | memcpy(new_fdt, fdt, fdt_totalsize(fdt)); |
| 149 | fdt_set_totalsize(new_fdt, fdt_size); |
| 150 | |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 151 | *fdtp = (void *)(uintptr_t)new_fdt_addr; |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 152 | done: |
| 153 | return ret; |
Alexander Graf | 0d9d501 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Simon Glass | 416e07e | 2018-06-18 08:08:28 -0600 | [diff] [blame] | 156 | /* |
| 157 | * efi_carve_out_dt_rsv() - Carve out DT reserved memory ranges |
| 158 | * |
| 159 | * The mem_rsv entries of the FDT are added to the memory map. Any failures are |
| 160 | * ignored because this is not critical and we would rather continue to try to |
| 161 | * boot. |
| 162 | * |
| 163 | * @fdt: Pointer to device tree |
| 164 | */ |
| 165 | static void efi_carve_out_dt_rsv(void *fdt) |
Alexander Graf | 806d2fa | 2018-04-06 09:40:51 +0200 | [diff] [blame] | 166 | { |
| 167 | int nr_rsv, i; |
| 168 | uint64_t addr, size, pages; |
| 169 | |
| 170 | nr_rsv = fdt_num_mem_rsv(fdt); |
| 171 | |
| 172 | /* Look for an existing entry and add it to the efi mem map. */ |
| 173 | for (i = 0; i < nr_rsv; i++) { |
| 174 | if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0) |
| 175 | continue; |
| 176 | |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 177 | /* Convert from sandbox address space. */ |
| 178 | addr = (uintptr_t)map_sysmem(addr, 0); |
| 179 | |
Heinrich Schuchardt | c3772ca | 2018-11-18 17:58:49 +0100 | [diff] [blame] | 180 | pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); |
Heinrich Schuchardt | 23fd84b | 2018-11-12 18:55:23 +0100 | [diff] [blame] | 181 | addr &= ~EFI_PAGE_MASK; |
Simon Glass | 416e07e | 2018-06-18 08:08:28 -0600 | [diff] [blame] | 182 | if (!efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE, |
| 183 | false)) |
| 184 | printf("FDT memrsv map %d: Failed to add to map\n", i); |
Alexander Graf | 806d2fa | 2018-04-06 09:40:51 +0200 | [diff] [blame] | 185 | } |
Alexander Graf | 806d2fa | 2018-04-06 09:40:51 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 188 | static efi_status_t efi_install_fdt(ulong fdt_addr) |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 189 | { |
| 190 | bootm_headers_t img = { 0 }; |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 191 | efi_status_t ret; |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 192 | void *fdt; |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 193 | |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 194 | fdt = map_sysmem(fdt_addr, 0); |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 195 | if (fdt_check_header(fdt)) { |
| 196 | printf("ERROR: invalid device tree\n"); |
| 197 | return EFI_INVALID_PARAMETER; |
| 198 | } |
| 199 | |
Heinrich Schuchardt | 0c9ac06 | 2018-11-18 17:58:53 +0100 | [diff] [blame] | 200 | /* Create memory reservation as indicated by the device tree */ |
| 201 | efi_carve_out_dt_rsv(fdt); |
| 202 | |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 203 | /* Prepare fdt for payload */ |
Heinrich Schuchardt | 16b615d | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 204 | ret = copy_fdt(&fdt); |
Simon Glass | 9dff490 | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 205 | if (ret) |
| 206 | return ret; |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 207 | |
| 208 | if (image_setup_libfdt(&img, fdt, 0, NULL)) { |
| 209 | printf("ERROR: failed to process device tree\n"); |
| 210 | return EFI_LOAD_ERROR; |
| 211 | } |
| 212 | |
| 213 | /* Link to it in the efi tables */ |
| 214 | ret = efi_install_configuration_table(&efi_guid_fdt, fdt); |
| 215 | if (ret != EFI_SUCCESS) |
| 216 | return EFI_OUT_OF_RESOURCES; |
| 217 | |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 218 | return ret; |
| 219 | } |
| 220 | |
AKASHI Takahiro | e878e6a | 2019-04-19 12:22:29 +0900 | [diff] [blame^] | 221 | /** |
| 222 | * efi_process_fdt() - process fdt passed by a command argument |
| 223 | * @fdt_opt: pointer to argument |
| 224 | * Return: status code |
| 225 | * |
| 226 | * If specified, fdt will be installed as configuration table, |
| 227 | * otherwise no fdt will be passed. |
| 228 | */ |
| 229 | static efi_status_t efi_process_fdt(const char *fdt_opt) |
| 230 | { |
| 231 | unsigned long fdt_addr; |
| 232 | efi_status_t ret; |
| 233 | |
| 234 | if (fdt_opt) { |
| 235 | fdt_addr = simple_strtoul(fdt_opt, NULL, 16); |
| 236 | if (!fdt_addr && *fdt_opt != '0') |
| 237 | return EFI_INVALID_PARAMETER; |
| 238 | |
| 239 | /* Install device tree */ |
| 240 | ret = efi_install_fdt(fdt_addr); |
| 241 | if (ret != EFI_SUCCESS) { |
| 242 | printf("ERROR: failed to install device tree\n"); |
| 243 | return ret; |
| 244 | } |
| 245 | } else { |
| 246 | /* Remove device tree. EFI_NOT_FOUND can be ignored here */ |
| 247 | efi_install_configuration_table(&efi_guid_fdt, NULL); |
| 248 | } |
| 249 | |
| 250 | return EFI_SUCCESS; |
| 251 | } |
| 252 | |
Simon Glass | f4f0f7c | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 253 | static efi_status_t bootefi_run_prepare(const char *load_options_path, |
| 254 | struct efi_device_path *device_path, |
| 255 | struct efi_device_path *image_path, |
| 256 | struct efi_loaded_image_obj **image_objp, |
| 257 | struct efi_loaded_image **loaded_image_infop) |
| 258 | { |
| 259 | efi_status_t ret; |
| 260 | |
| 261 | ret = efi_setup_loaded_image(device_path, image_path, image_objp, |
| 262 | loaded_image_infop); |
| 263 | if (ret != EFI_SUCCESS) |
| 264 | return ret; |
| 265 | |
| 266 | /* Transfer environment variable as load options */ |
AKASHI Takahiro | defa7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 267 | return set_load_options((efi_handle_t)*image_objp, load_options_path); |
Simon Glass | f4f0f7c | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 270 | /** |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 271 | * bootefi_run_finish() - finish up after running an EFI test |
| 272 | * |
| 273 | * @loaded_image_info: Pointer to a struct which holds the loaded image info |
| 274 | * @image_objj: Pointer to a struct which holds the loaded image object |
| 275 | */ |
| 276 | static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, |
| 277 | struct efi_loaded_image *loaded_image_info) |
| 278 | { |
| 279 | efi_restore_gd(); |
| 280 | free(loaded_image_info->load_options); |
| 281 | efi_delete_handle(&image_obj->header); |
| 282 | } |
| 283 | |
| 284 | /** |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 285 | * do_bootefi_exec() - execute EFI binary |
| 286 | * |
| 287 | * @efi: address of the binary |
| 288 | * @device_path: path of the device from which the binary was loaded |
| 289 | * @image_path: device path of the binary |
| 290 | * Return: status code |
| 291 | * |
| 292 | * Load the EFI binary into a newly assigned memory unwinding the relocation |
| 293 | * information, install the loaded image protocol, and call the binary. |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 294 | */ |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 295 | static efi_status_t do_bootefi_exec(void *efi, |
Heinrich Schuchardt | 3eb0841 | 2017-10-18 18:13:08 +0200 | [diff] [blame] | 296 | struct efi_device_path *device_path, |
| 297 | struct efi_device_path *image_path) |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 298 | { |
Heinrich Schuchardt | 8887acc | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 299 | efi_handle_t mem_handle = NULL; |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 300 | struct efi_device_path *memdp = NULL; |
Heinrich Schuchardt | 45204b1 | 2018-03-03 15:29:01 +0100 | [diff] [blame] | 301 | efi_status_t ret; |
Heinrich Schuchardt | faea104 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 302 | struct efi_loaded_image_obj *image_obj = NULL; |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 303 | struct efi_loaded_image *loaded_image_info = NULL; |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 304 | |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 305 | /* |
| 306 | * Special case for efi payload not loaded from disk, such as |
| 307 | * 'bootefi hello' or for example payload loaded directly into |
Heinrich Schuchardt | e1fec15 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 308 | * memory via JTAG, etc: |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 309 | */ |
| 310 | if (!device_path && !image_path) { |
| 311 | printf("WARNING: using memory device/image path, this may confuse some payloads!\n"); |
| 312 | /* actual addresses filled in after efi_load_pe() */ |
Heinrich Schuchardt | 0a76ba6 | 2018-12-26 22:23:00 +0100 | [diff] [blame] | 313 | memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 314 | device_path = image_path = memdp; |
Heinrich Schuchardt | 8887acc | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 315 | /* |
| 316 | * Grub expects that the device path of the loaded image is |
| 317 | * installed on a handle. |
| 318 | */ |
| 319 | ret = efi_create_handle(&mem_handle); |
| 320 | if (ret != EFI_SUCCESS) |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 321 | return ret; /* TODO: leaks device_path */ |
Heinrich Schuchardt | 8887acc | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 322 | ret = efi_add_protocol(mem_handle, &efi_guid_device_path, |
Alexander Graf | 58bc69d | 2018-06-12 10:21:16 +0200 | [diff] [blame] | 323 | device_path); |
| 324 | if (ret != EFI_SUCCESS) |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 325 | goto err_add_protocol; |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 326 | } else { |
| 327 | assert(device_path && image_path); |
| 328 | } |
| 329 | |
Simon Glass | f4f0f7c | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 330 | ret = bootefi_run_prepare("bootargs", device_path, image_path, |
| 331 | &image_obj, &loaded_image_info); |
| 332 | if (ret) |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 333 | goto err_prepare; |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 334 | |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 335 | /* Load the EFI payload */ |
Heinrich Schuchardt | 8f7e2b2 | 2018-12-26 12:49:09 +0100 | [diff] [blame] | 336 | ret = efi_load_pe(image_obj, efi, loaded_image_info); |
| 337 | if (ret != EFI_SUCCESS) |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 338 | goto err_prepare; |
Alexander Graf | 80a4800 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 339 | |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 340 | if (memdp) { |
| 341 | struct efi_device_path_memory *mdp = (void *)memdp; |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 342 | mdp->memory_type = loaded_image_info->image_code_type; |
| 343 | mdp->start_address = (uintptr_t)loaded_image_info->image_base; |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 344 | mdp->end_address = mdp->start_address + |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 345 | loaded_image_info->image_size; |
Rob Clark | bf19273 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Rob Clark | ad644e7 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 348 | /* we don't support much: */ |
| 349 | env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", |
| 350 | "{ro,boot}(blob)0000000000000000"); |
| 351 | |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 352 | /* Call our payload! */ |
Heinrich Schuchardt | 8f7e2b2 | 2018-12-26 12:49:09 +0100 | [diff] [blame] | 353 | debug("%s: Jumping to 0x%p\n", __func__, image_obj->entry); |
Heinrich Schuchardt | f69d63f | 2018-12-26 13:28:09 +0100 | [diff] [blame] | 354 | ret = EFI_CALL(efi_start_image(&image_obj->header, NULL, NULL)); |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 355 | |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 356 | err_prepare: |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 357 | /* image has returned, loaded-image obj goes *poof*: */ |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 358 | bootefi_run_finish(image_obj, loaded_image_info); |
| 359 | |
| 360 | err_add_protocol: |
Heinrich Schuchardt | 8887acc | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 361 | if (mem_handle) |
| 362 | efi_delete_handle(mem_handle); |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 363 | |
| 364 | return ret; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 367 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
| 368 | /** |
| 369 | * bootefi_test_prepare() - prepare to run an EFI test |
| 370 | * |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 371 | * Prepare to run a test as if it were provided by a loaded image. |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 372 | * |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 373 | * @image_objp: pointer to be set to the loaded image handle |
| 374 | * @loaded_image_infop: pointer to be set to the loaded image protocol |
| 375 | * @path: dummy file path used to construct the device path |
| 376 | * set in the loaded image protocol |
| 377 | * @load_options_path: name of a U-Boot environment variable. Its value is |
| 378 | * set as load options in the loaded image protocol. |
| 379 | * Return: status code |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 380 | */ |
| 381 | static efi_status_t bootefi_test_prepare |
| 382 | (struct efi_loaded_image_obj **image_objp, |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 383 | struct efi_loaded_image **loaded_image_infop, const char *path, |
| 384 | const char *load_options_path) |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 385 | { |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 386 | efi_status_t ret; |
| 387 | |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 388 | /* Construct a dummy device path */ |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 389 | bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 390 | if (!bootefi_device_path) |
| 391 | return EFI_OUT_OF_RESOURCES; |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 392 | |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 393 | bootefi_image_path = efi_dp_from_file(NULL, 0, path); |
| 394 | if (!bootefi_image_path) { |
| 395 | ret = EFI_OUT_OF_RESOURCES; |
| 396 | goto failure; |
| 397 | } |
| 398 | |
| 399 | ret = bootefi_run_prepare(load_options_path, bootefi_device_path, |
| 400 | bootefi_image_path, image_objp, |
| 401 | loaded_image_infop); |
| 402 | if (ret == EFI_SUCCESS) |
| 403 | return ret; |
| 404 | |
| 405 | efi_free_pool(bootefi_image_path); |
| 406 | bootefi_image_path = NULL; |
| 407 | failure: |
| 408 | efi_free_pool(bootefi_device_path); |
| 409 | bootefi_device_path = NULL; |
| 410 | return ret; |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Simon Glass | d9717ea | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 413 | #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ |
| 414 | |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 415 | static int do_bootefi_bootmgr_exec(void) |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 416 | { |
| 417 | struct efi_device_path *device_path, *file_path; |
| 418 | void *addr; |
| 419 | efi_status_t r; |
| 420 | |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 421 | addr = efi_bootmgr_load(&device_path, &file_path); |
| 422 | if (!addr) |
| 423 | return 1; |
| 424 | |
| 425 | printf("## Starting EFI application at %p ...\n", addr); |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 426 | r = do_bootefi_exec(addr, device_path, file_path); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 427 | printf("## Application terminated, r = %lu\n", |
| 428 | r & ~EFI_ERROR_MASK); |
| 429 | |
| 430 | if (r != EFI_SUCCESS) |
| 431 | return 1; |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 436 | /* Interpreter command to boot an arbitrary EFI image from memory */ |
| 437 | static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 438 | { |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 439 | unsigned long addr; |
| 440 | char *saddr; |
Heinrich Schuchardt | 3eb0841 | 2017-10-18 18:13:08 +0200 | [diff] [blame] | 441 | efi_status_t r; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 442 | |
Heinrich Schuchardt | c3b11de | 2018-04-03 21:59:32 +0200 | [diff] [blame] | 443 | /* Allow unaligned memory access */ |
| 444 | allow_unaligned(); |
| 445 | |
Heinrich Schuchardt | f6c6df7 | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 446 | switch_to_non_secure_mode(); |
| 447 | |
Heinrich Schuchardt | fc225e6 | 2018-03-03 15:29:02 +0100 | [diff] [blame] | 448 | /* Initialize EFI drivers */ |
| 449 | r = efi_init_obj_list(); |
| 450 | if (r != EFI_SUCCESS) { |
| 451 | printf("Error: Cannot set up EFI drivers, r = %lu\n", |
| 452 | r & ~EFI_ERROR_MASK); |
| 453 | return CMD_RET_FAILURE; |
| 454 | } |
| 455 | |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 456 | if (argc < 2) |
Bin Meng | 3c1dcef | 2016-08-13 04:02:06 -0700 | [diff] [blame] | 457 | return CMD_RET_USAGE; |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 458 | |
AKASHI Takahiro | e878e6a | 2019-04-19 12:22:29 +0900 | [diff] [blame^] | 459 | r = efi_process_fdt(argc > 2 ? argv[2] : NULL); |
| 460 | if (r == EFI_INVALID_PARAMETER) |
| 461 | return CMD_RET_USAGE; |
| 462 | else if (r != EFI_SUCCESS) |
| 463 | return CMD_RET_FAILURE; |
| 464 | |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 465 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
| 466 | if (!strcmp(argv[1], "hello")) { |
Heinrich Schuchardt | 5e44489 | 2017-09-05 03:19:37 +0200 | [diff] [blame] | 467 | ulong size = __efi_helloworld_end - __efi_helloworld_begin; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 468 | |
Heinrich Schuchardt | 51c533f | 2017-08-28 18:54:30 +0200 | [diff] [blame] | 469 | saddr = env_get("loadaddr"); |
| 470 | if (saddr) |
| 471 | addr = simple_strtoul(saddr, NULL, 16); |
| 472 | else |
| 473 | addr = CONFIG_SYS_LOAD_ADDR; |
Alexander Graf | 354264b | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 474 | memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 475 | } else |
| 476 | #endif |
Heinrich Schuchardt | 623b3a5 | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 477 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
| 478 | if (!strcmp(argv[1], "selftest")) { |
Heinrich Schuchardt | faea104 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 479 | struct efi_loaded_image_obj *image_obj; |
Heinrich Schuchardt | c982874 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 480 | struct efi_loaded_image *loaded_image_info; |
Heinrich Schuchardt | 7aca68c | 2017-09-20 22:54:58 +0200 | [diff] [blame] | 481 | |
Heinrich Schuchardt | 1504bb0 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 482 | r = bootefi_test_prepare(&image_obj, &loaded_image_info, |
| 483 | "\\selftest", "efi_selftest"); |
| 484 | if (r != EFI_SUCCESS) |
Simon Glass | 2ab7ef7 | 2018-11-25 20:14:36 -0700 | [diff] [blame] | 485 | return CMD_RET_FAILURE; |
| 486 | |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 487 | /* Execute the test */ |
Heinrich Schuchardt | 914df75 | 2019-02-09 14:10:39 +0100 | [diff] [blame] | 488 | r = EFI_CALL(efi_selftest(&image_obj->header, &systab)); |
Simon Glass | 5e2f039 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 489 | bootefi_run_finish(image_obj, loaded_image_info); |
Heinrich Schuchardt | c2b5390 | 2017-10-18 18:13:14 +0200 | [diff] [blame] | 490 | return r != EFI_SUCCESS; |
Heinrich Schuchardt | 623b3a5 | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 491 | } else |
| 492 | #endif |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 493 | if (!strcmp(argv[1], "bootmgr")) { |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 494 | return do_bootefi_bootmgr_exec(); |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 495 | } else { |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 496 | saddr = argv[1]; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 497 | |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 498 | addr = simple_strtoul(saddr, NULL, 16); |
Heinrich Schuchardt | 49db1cb | 2018-01-24 20:33:54 +0100 | [diff] [blame] | 499 | /* Check that a numeric value was passed */ |
| 500 | if (!addr && *saddr != '0') |
| 501 | return CMD_RET_USAGE; |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 502 | |
Alexander Graf | 1c39809 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Simon Glass | 5ee31ba | 2016-11-07 08:47:05 -0700 | [diff] [blame] | 505 | printf("## Starting EFI application at %08lx ...\n", addr); |
Alexander Graf | 354264b | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 506 | r = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 507 | bootefi_image_path); |
xypron.glpk@gmx.de | 1da1bac | 2017-07-04 23:15:23 +0200 | [diff] [blame] | 508 | printf("## Application terminated, r = %lu\n", |
| 509 | r & ~EFI_ERROR_MASK); |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 510 | |
xypron.glpk@gmx.de | 1da1bac | 2017-07-04 23:15:23 +0200 | [diff] [blame] | 511 | if (r != EFI_SUCCESS) |
| 512 | return 1; |
| 513 | else |
| 514 | return 0; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | #ifdef CONFIG_SYS_LONGHELP |
| 518 | static char bootefi_help_text[] = |
Alexander Graf | 1c39809 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 519 | "<image address> [fdt address]\n" |
| 520 | " - boot EFI payload stored at address <image address>.\n" |
| 521 | " If specified, the device tree located at <fdt address> gets\n" |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 522 | " exposed as EFI configuration table.\n" |
| 523 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
Heinrich Schuchardt | 623b3a5 | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 524 | "bootefi hello\n" |
| 525 | " - boot a sample Hello World application stored within U-Boot\n" |
| 526 | #endif |
| 527 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
Heinrich Schuchardt | bc4f913 | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 528 | "bootefi selftest [fdt address]\n" |
Heinrich Schuchardt | 623b3a5 | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 529 | " - boot an EFI selftest application stored within U-Boot\n" |
Heinrich Schuchardt | d78e40d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 530 | " Use environment variable efi_selftest to select a single test.\n" |
| 531 | " Use 'setenv efi_selftest list' to enumerate all tests.\n" |
Simon Glass | c7ae3df | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 532 | #endif |
Heinrich Schuchardt | f623e07 | 2018-01-30 19:47:43 +0100 | [diff] [blame] | 533 | "bootefi bootmgr [fdt addr]\n" |
Rob Clark | 9975fe9 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 534 | " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" |
| 535 | "\n" |
| 536 | " If specified, the device tree located at <fdt address> gets\n" |
| 537 | " exposed as EFI configuration table.\n"; |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 538 | #endif |
| 539 | |
| 540 | U_BOOT_CMD( |
Alexander Graf | 1c39809 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 541 | bootefi, 3, 0, do_bootefi, |
Sergey Kubushyn | 92dfd92 | 2016-06-07 11:14:31 -0700 | [diff] [blame] | 542 | "Boots an EFI payload from memory", |
Alexander Graf | b993933 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 543 | bootefi_help_text |
| 544 | ); |
Alexander Graf | 0f4060e | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 545 | |
Alexander Graf | c07ad7c | 2016-04-11 16:16:19 +0200 | [diff] [blame] | 546 | void efi_set_bootdev(const char *dev, const char *devnr, const char *path) |
Alexander Graf | 0f4060e | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 547 | { |
AKASHI Takahiro | f1589ff | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 548 | struct efi_device_path *device, *image; |
| 549 | efi_status_t ret; |
Alexander Graf | 0f4060e | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 550 | |
Heinrich Schuchardt | 79276eb | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 551 | /* efi_set_bootdev is typically called repeatedly, recover memory */ |
| 552 | efi_free_pool(bootefi_device_path); |
| 553 | efi_free_pool(bootefi_image_path); |
Heinrich Schuchardt | 79276eb | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 554 | |
AKASHI Takahiro | f1589ff | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 555 | ret = efi_dp_from_name(dev, devnr, path, &device, &image); |
| 556 | if (ret == EFI_SUCCESS) { |
| 557 | bootefi_device_path = device; |
| 558 | bootefi_image_path = image; |
Rob Clark | 95c5553 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 559 | } else { |
AKASHI Takahiro | f1589ff | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 560 | bootefi_device_path = NULL; |
| 561 | bootefi_image_path = NULL; |
Alexander Graf | f9d334b | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 562 | } |
Alexander Graf | 0f4060e | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 563 | } |