Tom Rini | 70df9d6 | 2018-05-07 17:02:21 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 2 | /* |
| 3 | * EFI application loader |
| 4 | * |
| 5 | * Copyright (c) 2016 Alexander Graf |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Heinrich Schuchardt | aa0b11b | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 9 | #include <bootm.h> |
| 10 | #include <charset.h> |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 11 | #include <command.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 13 | #include <efi_loader.h> |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 14 | #include <efi_selftest.h> |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 15 | #include <errno.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 16 | #include <linux/libfdt.h> |
| 17 | #include <linux/libfdt_env.h> |
Alexander Graf | a241451 | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 18 | #include <mapmem.h> |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 19 | #include <memalign.h> |
Alexander Graf | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 20 | #include <asm/global_data.h> |
Simon Glass | c2194bf | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 21 | #include <asm-generic/sections.h> |
Heinrich Schuchardt | 954e2b9 | 2018-04-03 21:59:32 +0200 | [diff] [blame] | 22 | #include <asm-generic/unaligned.h> |
Simon Glass | c2194bf | 2016-09-25 15:27:32 -0600 | [diff] [blame] | 23 | #include <linux/linkage.h> |
Alexander Graf | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 26 | |
Rob Clark | f8db922 | 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 | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 29 | |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 30 | /* |
Heinrich Schuchardt | 954e2b9 | 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 | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 40 | * Set the load options of an image from an environment variable. |
| 41 | * |
AKASHI Takahiro | e25a7b8 | 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 | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 45 | */ |
AKASHI Takahiro | e25a7b8 | 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 | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 47 | { |
AKASHI Takahiro | e25a7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 48 | struct efi_loaded_image *loaded_image_info; |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 49 | size_t size; |
| 50 | const char *env = env_get(env_var); |
Heinrich Schuchardt | de52780 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 51 | u16 *pos; |
AKASHI Takahiro | e25a7b8 | 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 | 02efd5d | 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 | e25a7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame] | 66 | goto out; |
| 67 | |
Heinrich Schuchardt | de52780 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 68 | size = utf8_utf16_strlen(env) + 1; |
Heinrich Schuchardt | 02efd5d | 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 | e25a7b8 | 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 | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 76 | } |
Heinrich Schuchardt | de52780 | 2018-08-31 21:31:33 +0200 | [diff] [blame] | 77 | pos = loaded_image_info->load_options; |
| 78 | utf8_utf16_strcpy(&pos, env); |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 79 | loaded_image_info->load_options_size = size * 2; |
AKASHI Takahiro | e25a7b8 | 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 | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Simon Glass | 5d618df | 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 | b23f9b7 | 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 | dcdca29 | 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 | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 92 | * expanded later with fdt_open_into(). |
| 93 | * |
Heinrich Schuchardt | b23f9b7 | 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 | 96af56e | 2018-11-12 18:55:22 +0100 | [diff] [blame] | 96 | * FDT start |
| 97 | * Return: status code |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 98 | */ |
Heinrich Schuchardt | b23f9b7 | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 99 | static efi_status_t copy_fdt(void **fdtp) |
Alexander Graf | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 100 | { |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 101 | unsigned long fdt_ram_start = -1L, fdt_pages; |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 102 | efi_status_t ret = 0; |
| 103 | void *fdt, *new_fdt; |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 104 | u64 new_fdt_addr; |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 105 | uint fdt_size; |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 106 | int i; |
Alexander Graf | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 107 | |
Simon Glass | 5d618df | 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 | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 111 | |
Alexander Graf | fdbae01 | 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 | 56bbcc1 | 2018-06-18 08:08:25 -0600 | [diff] [blame] | 119 | /* |
Heinrich Schuchardt | dcdca29 | 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 | 56bbcc1 | 2018-06-18 08:08:25 -0600 | [diff] [blame] | 122 | */ |
Heinrich Schuchardt | b23f9b7 | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 123 | fdt = *fdtp; |
Heinrich Schuchardt | dcdca29 | 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 | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 126 | |
Heinrich Schuchardt | b23f9b7 | 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 | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 133 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Ilias Apalodimas | 0468b8e | 2019-04-12 21:26:28 +0300 | [diff] [blame] | 134 | EFI_BOOT_SERVICES_DATA, fdt_pages, |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 135 | &new_fdt_addr); |
| 136 | if (ret != EFI_SUCCESS) { |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 137 | /* If we can't put it there, put it somewhere */ |
xypron.glpk@gmx.de | f6b9912 | 2017-08-11 21:19:25 +0200 | [diff] [blame] | 138 | new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size); |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 139 | ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, |
Ilias Apalodimas | 0468b8e | 2019-04-12 21:26:28 +0300 | [diff] [blame] | 140 | EFI_BOOT_SERVICES_DATA, fdt_pages, |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 141 | &new_fdt_addr); |
| 142 | if (ret != EFI_SUCCESS) { |
Alexander Graf | 9b9b716 | 2017-07-03 13:32:35 +0200 | [diff] [blame] | 143 | printf("ERROR: Failed to reserve space for FDT\n"); |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 144 | goto done; |
Alexander Graf | 9b9b716 | 2017-07-03 13:32:35 +0200 | [diff] [blame] | 145 | } |
Alexander Graf | fdbae01 | 2016-04-11 23:51:01 +0200 | [diff] [blame] | 146 | } |
Heinrich Schuchardt | b23f9b7 | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 147 | new_fdt = (void *)(uintptr_t)new_fdt_addr; |
Alexander Graf | 2ff5cc3 | 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 | b23f9b7 | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 151 | *fdtp = (void *)(uintptr_t)new_fdt_addr; |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 152 | done: |
| 153 | return ret; |
Alexander Graf | 2ff5cc3 | 2016-04-11 16:55:26 +0200 | [diff] [blame] | 154 | } |
| 155 | |
Simon Glass | 54b9b6e | 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 | 22c88bf | 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 | b23f9b7 | 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 | dcdca29 | 2018-11-18 17:58:49 +0100 | [diff] [blame] | 180 | pages = efi_size_in_pages(size + (addr & EFI_PAGE_MASK)); |
Heinrich Schuchardt | 3d92fc8 | 2018-11-12 18:55:23 +0100 | [diff] [blame] | 181 | addr &= ~EFI_PAGE_MASK; |
Simon Glass | 54b9b6e | 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 | 22c88bf | 2018-04-06 09:40:51 +0200 | [diff] [blame] | 185 | } |
Alexander Graf | 22c88bf | 2018-04-06 09:40:51 +0200 | [diff] [blame] | 186 | } |
| 187 | |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 188 | /** |
AKASHI Takahiro | 451e991 | 2019-04-19 12:22:30 +0900 | [diff] [blame] | 189 | * efi_install_fdt() - install fdt passed by a command argument |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 190 | * @fdt_opt: pointer to argument |
| 191 | * Return: status code |
| 192 | * |
| 193 | * If specified, fdt will be installed as configuration table, |
| 194 | * otherwise no fdt will be passed. |
| 195 | */ |
AKASHI Takahiro | 451e991 | 2019-04-19 12:22:30 +0900 | [diff] [blame] | 196 | static efi_status_t efi_install_fdt(const char *fdt_opt) |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 197 | { |
| 198 | unsigned long fdt_addr; |
AKASHI Takahiro | 451e991 | 2019-04-19 12:22:30 +0900 | [diff] [blame] | 199 | void *fdt; |
| 200 | bootm_headers_t img = { 0 }; |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 201 | efi_status_t ret; |
| 202 | |
| 203 | if (fdt_opt) { |
AKASHI Takahiro | 451e991 | 2019-04-19 12:22:30 +0900 | [diff] [blame] | 204 | /* Install device tree */ |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 205 | fdt_addr = simple_strtoul(fdt_opt, NULL, 16); |
| 206 | if (!fdt_addr && *fdt_opt != '0') |
| 207 | return EFI_INVALID_PARAMETER; |
| 208 | |
AKASHI Takahiro | 451e991 | 2019-04-19 12:22:30 +0900 | [diff] [blame] | 209 | fdt = map_sysmem(fdt_addr, 0); |
| 210 | if (fdt_check_header(fdt)) { |
| 211 | printf("ERROR: invalid device tree\n"); |
| 212 | return EFI_INVALID_PARAMETER; |
| 213 | } |
| 214 | |
| 215 | /* Create memory reservation as indicated by the device tree */ |
| 216 | efi_carve_out_dt_rsv(fdt); |
| 217 | |
| 218 | /* Prepare fdt for payload */ |
| 219 | ret = copy_fdt(&fdt); |
| 220 | if (ret) |
| 221 | return ret; |
| 222 | |
| 223 | if (image_setup_libfdt(&img, fdt, 0, NULL)) { |
| 224 | printf("ERROR: failed to process device tree\n"); |
| 225 | return EFI_LOAD_ERROR; |
| 226 | } |
| 227 | |
| 228 | /* Link to it in the efi tables */ |
| 229 | ret = efi_install_configuration_table(&efi_guid_fdt, fdt); |
AKASHI Takahiro | cc02f17 | 2019-04-19 12:22:29 +0900 | [diff] [blame] | 230 | if (ret != EFI_SUCCESS) { |
| 231 | printf("ERROR: failed to install device tree\n"); |
| 232 | return ret; |
| 233 | } |
| 234 | } else { |
| 235 | /* Remove device tree. EFI_NOT_FOUND can be ignored here */ |
| 236 | efi_install_configuration_table(&efi_guid_fdt, NULL); |
| 237 | } |
| 238 | |
| 239 | return EFI_SUCCESS; |
| 240 | } |
| 241 | |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 242 | /** |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 243 | * do_bootefi_exec() - execute EFI binary |
| 244 | * |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 245 | * @handle: handle of loaded image |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 246 | * Return: status code |
| 247 | * |
| 248 | * Load the EFI binary into a newly assigned memory unwinding the relocation |
| 249 | * information, install the loaded image protocol, and call the binary. |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 250 | */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 251 | static efi_status_t do_bootefi_exec(efi_handle_t handle) |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 252 | { |
Heinrich Schuchardt | 4b055a2 | 2018-03-03 15:29:01 +0100 | [diff] [blame] | 253 | efi_status_t ret; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 254 | |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 255 | /* Transfer environment variable as load options */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 256 | ret = set_load_options(handle, "bootargs"); |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 257 | if (ret != EFI_SUCCESS) |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 258 | return ret; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 259 | |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 260 | /* we don't support much: */ |
| 261 | env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", |
| 262 | "{ro,boot}(blob)0000000000000000"); |
| 263 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 264 | /* Call our payload! */ |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 265 | ret = EFI_CALL(efi_start_image(handle, NULL, NULL)); |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 266 | |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 267 | efi_restore_gd(); |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 268 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 269 | /* |
| 270 | * FIXME: Who is responsible for |
| 271 | * free(loaded_image_info->load_options); |
| 272 | * Once efi_exit() is implemented correctly, |
| 273 | * handle itself doesn't exist here. |
| 274 | */ |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 275 | |
| 276 | return ret; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 277 | } |
| 278 | |
AKASHI Takahiro | cf81983 | 2019-04-19 12:22:33 +0900 | [diff] [blame] | 279 | /** |
| 280 | * do_efibootmgr() - execute EFI Boot Manager |
| 281 | * |
| 282 | * @fdt_opt: string of fdt start address |
| 283 | * Return: status code |
| 284 | * |
| 285 | * Execute EFI Boot Manager |
| 286 | */ |
| 287 | static int do_efibootmgr(const char *fdt_opt) |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 288 | { |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 289 | efi_handle_t handle; |
AKASHI Takahiro | cf81983 | 2019-04-19 12:22:33 +0900 | [diff] [blame] | 290 | efi_status_t ret; |
| 291 | |
| 292 | /* Allow unaligned memory access */ |
| 293 | allow_unaligned(); |
| 294 | |
| 295 | switch_to_non_secure_mode(); |
| 296 | |
| 297 | /* Initialize EFI drivers */ |
| 298 | ret = efi_init_obj_list(); |
| 299 | if (ret != EFI_SUCCESS) { |
| 300 | printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", |
| 301 | ret & ~EFI_ERROR_MASK); |
| 302 | return CMD_RET_FAILURE; |
| 303 | } |
| 304 | |
| 305 | ret = efi_install_fdt(fdt_opt); |
| 306 | if (ret == EFI_INVALID_PARAMETER) |
| 307 | return CMD_RET_USAGE; |
| 308 | else if (ret != EFI_SUCCESS) |
| 309 | return CMD_RET_FAILURE; |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 310 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 311 | ret = efi_bootmgr_load(&handle); |
| 312 | if (ret != EFI_SUCCESS) { |
| 313 | printf("EFI boot manager: Cannot load any image\n"); |
| 314 | return CMD_RET_FAILURE; |
| 315 | } |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 316 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 317 | ret = do_bootefi_exec(handle); |
| 318 | printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 319 | |
AKASHI Takahiro | cf81983 | 2019-04-19 12:22:33 +0900 | [diff] [blame] | 320 | if (ret != EFI_SUCCESS) |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 321 | return CMD_RET_FAILURE; |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 322 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 323 | return CMD_RET_SUCCESS; |
AKASHI Takahiro | 758733d | 2019-04-19 12:22:32 +0900 | [diff] [blame] | 324 | } |
| 325 | |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 326 | /* |
| 327 | * do_bootefi_image() - execute EFI binary from command line |
| 328 | * |
| 329 | * @image_opt: string of image start address |
| 330 | * @fdt_opt: string of fdt start address |
| 331 | * Return: status code |
| 332 | * |
| 333 | * Set up memory image for the binary to be loaded, prepare |
| 334 | * device path and then call do_bootefi_exec() to execute it. |
| 335 | */ |
| 336 | static int do_bootefi_image(const char *image_opt, const char *fdt_opt) |
| 337 | { |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 338 | void *image_buf; |
| 339 | struct efi_device_path *device_path, *image_path; |
| 340 | struct efi_device_path *file_path = NULL; |
| 341 | unsigned long addr, size; |
| 342 | const char *size_str; |
| 343 | efi_handle_t mem_handle = NULL, handle; |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 344 | efi_status_t ret; |
| 345 | |
| 346 | /* Allow unaligned memory access */ |
| 347 | allow_unaligned(); |
| 348 | |
| 349 | switch_to_non_secure_mode(); |
| 350 | |
| 351 | /* Initialize EFI drivers */ |
| 352 | ret = efi_init_obj_list(); |
| 353 | if (ret != EFI_SUCCESS) { |
| 354 | printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", |
| 355 | ret & ~EFI_ERROR_MASK); |
| 356 | return CMD_RET_FAILURE; |
| 357 | } |
| 358 | |
| 359 | ret = efi_install_fdt(fdt_opt); |
| 360 | if (ret == EFI_INVALID_PARAMETER) |
| 361 | return CMD_RET_USAGE; |
| 362 | else if (ret != EFI_SUCCESS) |
| 363 | return CMD_RET_FAILURE; |
| 364 | |
| 365 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
| 366 | if (!strcmp(image_opt, "hello")) { |
| 367 | char *saddr; |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 368 | |
| 369 | saddr = env_get("loadaddr"); |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 370 | size = __efi_helloworld_end - __efi_helloworld_begin; |
| 371 | |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 372 | if (saddr) |
| 373 | addr = simple_strtoul(saddr, NULL, 16); |
| 374 | else |
| 375 | addr = CONFIG_SYS_LOAD_ADDR; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 376 | |
| 377 | image_buf = map_sysmem(addr, size); |
| 378 | memcpy(image_buf, __efi_helloworld_begin, size); |
| 379 | |
| 380 | device_path = NULL; |
| 381 | image_path = NULL; |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 382 | } else |
| 383 | #endif |
| 384 | { |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 385 | size_str = env_get("filesize"); |
| 386 | if (size_str) |
| 387 | size = simple_strtoul(size_str, NULL, 16); |
| 388 | else |
| 389 | size = 0; |
| 390 | |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 391 | addr = simple_strtoul(image_opt, NULL, 16); |
| 392 | /* Check that a numeric value was passed */ |
| 393 | if (!addr && *image_opt != '0') |
| 394 | return CMD_RET_USAGE; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 395 | |
| 396 | image_buf = map_sysmem(addr, size); |
| 397 | |
| 398 | device_path = bootefi_device_path; |
| 399 | image_path = bootefi_image_path; |
| 400 | } |
| 401 | |
| 402 | if (!device_path && !image_path) { |
| 403 | /* |
| 404 | * Special case for efi payload not loaded from disk, |
| 405 | * such as 'bootefi hello' or for example payload |
| 406 | * loaded directly into memory via JTAG, etc: |
| 407 | */ |
| 408 | file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, |
| 409 | (uintptr_t)image_buf, size); |
| 410 | /* |
| 411 | * Make sure that device for device_path exist |
| 412 | * in load_image(). Otherwise, shell and grub will fail. |
| 413 | */ |
| 414 | ret = efi_create_handle(&mem_handle); |
| 415 | if (ret != EFI_SUCCESS) |
| 416 | goto out; |
| 417 | |
| 418 | ret = efi_add_protocol(mem_handle, &efi_guid_device_path, |
| 419 | file_path); |
| 420 | if (ret != EFI_SUCCESS) |
| 421 | goto out; |
| 422 | } else { |
| 423 | assert(device_path && image_path); |
| 424 | file_path = efi_dp_append(device_path, image_path); |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 425 | } |
| 426 | |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 427 | ret = EFI_CALL(efi_load_image(false, efi_root, |
| 428 | file_path, image_buf, size, &handle)); |
| 429 | if (ret != EFI_SUCCESS) |
| 430 | goto out; |
| 431 | |
| 432 | ret = do_bootefi_exec(handle); |
| 433 | printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); |
| 434 | |
| 435 | out: |
| 436 | if (mem_handle) |
| 437 | efi_delete_handle(mem_handle); |
| 438 | if (file_path) |
| 439 | efi_free_pool(file_path); |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 440 | |
| 441 | if (ret != EFI_SUCCESS) |
| 442 | return CMD_RET_FAILURE; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 443 | |
| 444 | return CMD_RET_SUCCESS; |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 445 | } |
| 446 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 447 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 448 | static efi_status_t bootefi_run_prepare(const char *load_options_path, |
| 449 | struct efi_device_path *device_path, |
| 450 | struct efi_device_path *image_path, |
| 451 | struct efi_loaded_image_obj **image_objp, |
| 452 | struct efi_loaded_image **loaded_image_infop) |
| 453 | { |
| 454 | efi_status_t ret; |
| 455 | |
| 456 | ret = efi_setup_loaded_image(device_path, image_path, image_objp, |
| 457 | loaded_image_infop); |
| 458 | if (ret != EFI_SUCCESS) |
| 459 | return ret; |
| 460 | |
| 461 | /* Transfer environment variable as load options */ |
| 462 | return set_load_options((efi_handle_t)*image_objp, load_options_path); |
| 463 | } |
| 464 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 465 | /** |
| 466 | * bootefi_test_prepare() - prepare to run an EFI test |
| 467 | * |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 468 | * Prepare to run a test as if it were provided by a loaded image. |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 469 | * |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 470 | * @image_objp: pointer to be set to the loaded image handle |
| 471 | * @loaded_image_infop: pointer to be set to the loaded image protocol |
| 472 | * @path: dummy file path used to construct the device path |
| 473 | * set in the loaded image protocol |
| 474 | * @load_options_path: name of a U-Boot environment variable. Its value is |
| 475 | * set as load options in the loaded image protocol. |
| 476 | * Return: status code |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 477 | */ |
| 478 | static efi_status_t bootefi_test_prepare |
| 479 | (struct efi_loaded_image_obj **image_objp, |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 480 | struct efi_loaded_image **loaded_image_infop, const char *path, |
| 481 | const char *load_options_path) |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 482 | { |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 483 | efi_status_t ret; |
| 484 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 485 | /* Construct a dummy device path */ |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 486 | bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 487 | if (!bootefi_device_path) |
| 488 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 489 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 490 | bootefi_image_path = efi_dp_from_file(NULL, 0, path); |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 491 | if (!bootefi_image_path) { |
| 492 | ret = EFI_OUT_OF_RESOURCES; |
| 493 | goto failure; |
| 494 | } |
| 495 | |
| 496 | ret = bootefi_run_prepare(load_options_path, bootefi_device_path, |
| 497 | bootefi_image_path, image_objp, |
| 498 | loaded_image_infop); |
| 499 | if (ret == EFI_SUCCESS) |
| 500 | return ret; |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 501 | |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 502 | efi_free_pool(bootefi_image_path); |
| 503 | bootefi_image_path = NULL; |
| 504 | failure: |
| 505 | efi_free_pool(bootefi_device_path); |
| 506 | bootefi_device_path = NULL; |
| 507 | return ret; |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 508 | } |
| 509 | |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 510 | /** |
| 511 | * bootefi_run_finish() - finish up after running an EFI test |
| 512 | * |
| 513 | * @loaded_image_info: Pointer to a struct which holds the loaded image info |
| 514 | * @image_obj: Pointer to a struct which holds the loaded image object |
| 515 | */ |
| 516 | static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, |
| 517 | struct efi_loaded_image *loaded_image_info) |
| 518 | { |
| 519 | efi_restore_gd(); |
| 520 | free(loaded_image_info->load_options); |
| 521 | efi_delete_handle(&image_obj->header); |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * do_efi_selftest() - execute EFI Selftest |
| 526 | * |
| 527 | * @fdt_opt: string of fdt start address |
| 528 | * Return: status code |
| 529 | * |
| 530 | * Execute EFI Selftest |
| 531 | */ |
| 532 | static int do_efi_selftest(const char *fdt_opt) |
| 533 | { |
| 534 | struct efi_loaded_image_obj *image_obj; |
| 535 | struct efi_loaded_image *loaded_image_info; |
| 536 | efi_status_t ret; |
| 537 | |
| 538 | /* Allow unaligned memory access */ |
| 539 | allow_unaligned(); |
| 540 | |
| 541 | switch_to_non_secure_mode(); |
| 542 | |
| 543 | /* Initialize EFI drivers */ |
| 544 | ret = efi_init_obj_list(); |
| 545 | if (ret != EFI_SUCCESS) { |
| 546 | printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", |
| 547 | ret & ~EFI_ERROR_MASK); |
| 548 | return CMD_RET_FAILURE; |
| 549 | } |
| 550 | |
| 551 | ret = efi_install_fdt(fdt_opt); |
| 552 | if (ret == EFI_INVALID_PARAMETER) |
| 553 | return CMD_RET_USAGE; |
| 554 | else if (ret != EFI_SUCCESS) |
| 555 | return CMD_RET_FAILURE; |
| 556 | |
| 557 | ret = bootefi_test_prepare(&image_obj, &loaded_image_info, |
| 558 | "\\selftest", "efi_selftest"); |
| 559 | if (ret != EFI_SUCCESS) |
| 560 | return CMD_RET_FAILURE; |
| 561 | |
| 562 | /* Execute the test */ |
| 563 | ret = EFI_CALL(efi_selftest(&image_obj->header, &systab)); |
| 564 | bootefi_run_finish(image_obj, loaded_image_info); |
| 565 | |
| 566 | return ret != EFI_SUCCESS; |
| 567 | } |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 568 | #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ |
| 569 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 570 | /* Interpreter command to boot an arbitrary EFI image from memory */ |
| 571 | static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 572 | { |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 573 | if (argc < 2) |
| 574 | return CMD_RET_USAGE; |
AKASHI Takahiro | cf81983 | 2019-04-19 12:22:33 +0900 | [diff] [blame] | 575 | |
| 576 | if (!strcmp(argv[1], "bootmgr")) |
| 577 | return do_efibootmgr(argc > 2 ? argv[2] : NULL); |
AKASHI Takahiro | 09a81c7 | 2019-04-19 12:22:31 +0900 | [diff] [blame] | 578 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
| 579 | else if (!strcmp(argv[1], "selftest")) |
| 580 | return do_efi_selftest(argc > 2 ? argv[2] : NULL); |
| 581 | #endif |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 582 | |
AKASHI Takahiro | fbd3ba5 | 2019-04-19 12:22:34 +0900 | [diff] [blame] | 583 | return do_bootefi_image(argv[1], argc > 2 ? argv[2] : NULL); |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | #ifdef CONFIG_SYS_LONGHELP |
| 587 | static char bootefi_help_text[] = |
Alexander Graf | 54c1e83 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 588 | "<image address> [fdt address]\n" |
| 589 | " - boot EFI payload stored at address <image address>.\n" |
| 590 | " If specified, the device tree located at <fdt address> gets\n" |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 591 | " exposed as EFI configuration table.\n" |
| 592 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 593 | "bootefi hello\n" |
| 594 | " - boot a sample Hello World application stored within U-Boot\n" |
| 595 | #endif |
| 596 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 597 | "bootefi selftest [fdt address]\n" |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 598 | " - boot an EFI selftest application stored within U-Boot\n" |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 599 | " Use environment variable efi_selftest to select a single test.\n" |
| 600 | " Use 'setenv efi_selftest list' to enumerate all tests.\n" |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 601 | #endif |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 602 | "bootefi bootmgr [fdt address]\n" |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 603 | " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" |
| 604 | "\n" |
| 605 | " If specified, the device tree located at <fdt address> gets\n" |
| 606 | " exposed as EFI configuration table.\n"; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 607 | #endif |
| 608 | |
| 609 | U_BOOT_CMD( |
Alexander Graf | 54c1e83 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 610 | bootefi, 3, 0, do_bootefi, |
Sergey Kubushyn | 268f19e | 2016-06-07 11:14:31 -0700 | [diff] [blame] | 611 | "Boots an EFI payload from memory", |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 612 | bootefi_help_text |
| 613 | ); |
Alexander Graf | 8f19f26 | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 614 | |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 615 | void efi_set_bootdev(const char *dev, const char *devnr, const char *path) |
| 616 | { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 617 | struct efi_device_path *device, *image; |
| 618 | efi_status_t ret; |
Alexander Graf | 34118e7 | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 619 | |
Heinrich Schuchardt | 761ecc8 | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 620 | /* efi_set_bootdev is typically called repeatedly, recover memory */ |
| 621 | efi_free_pool(bootefi_device_path); |
| 622 | efi_free_pool(bootefi_image_path); |
Heinrich Schuchardt | 761ecc8 | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 623 | |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 624 | ret = efi_dp_from_name(dev, devnr, path, &device, &image); |
| 625 | if (ret == EFI_SUCCESS) { |
| 626 | bootefi_device_path = device; |
AKASHI Takahiro | 14ff23b | 2019-04-19 12:22:35 +0900 | [diff] [blame] | 627 | if (image) { |
| 628 | /* FIXME: image should not contain device */ |
| 629 | struct efi_device_path *image_tmp = image; |
| 630 | |
| 631 | efi_dp_split_file_path(image, &device, &image); |
| 632 | efi_free_pool(image_tmp); |
| 633 | } |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 634 | bootefi_image_path = image; |
Alexander Graf | 45e437d | 2016-07-21 01:44:46 +0200 | [diff] [blame] | 635 | } else { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 636 | bootefi_device_path = NULL; |
| 637 | bootefi_image_path = NULL; |
Alexander Graf | 45e437d | 2016-07-21 01:44:46 +0200 | [diff] [blame] | 638 | } |
Alexander Graf | 8f19f26 | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 639 | } |