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 | |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 188 | static efi_status_t efi_install_fdt(ulong fdt_addr) |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 189 | { |
| 190 | bootm_headers_t img = { 0 }; |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 191 | efi_status_t ret; |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 192 | void *fdt; |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 193 | |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 194 | fdt = map_sysmem(fdt_addr, 0); |
Heinrich Schuchardt | 44ab21b | 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 | 68a0d5b | 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 | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 203 | /* Prepare fdt for payload */ |
Heinrich Schuchardt | b23f9b7 | 2018-11-18 17:58:52 +0100 | [diff] [blame] | 204 | ret = copy_fdt(&fdt); |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 205 | if (ret) |
| 206 | return ret; |
Heinrich Schuchardt | 44ab21b | 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 | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 218 | return ret; |
| 219 | } |
| 220 | |
Simon Glass | 7816c7a | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 221 | static efi_status_t bootefi_run_prepare(const char *load_options_path, |
| 222 | struct efi_device_path *device_path, |
| 223 | struct efi_device_path *image_path, |
| 224 | struct efi_loaded_image_obj **image_objp, |
| 225 | struct efi_loaded_image **loaded_image_infop) |
| 226 | { |
| 227 | efi_status_t ret; |
| 228 | |
| 229 | ret = efi_setup_loaded_image(device_path, image_path, image_objp, |
| 230 | loaded_image_infop); |
| 231 | if (ret != EFI_SUCCESS) |
| 232 | return ret; |
| 233 | |
| 234 | /* Transfer environment variable as load options */ |
AKASHI Takahiro | e25a7b8 | 2019-04-19 12:22:28 +0900 | [diff] [blame^] | 235 | return set_load_options((efi_handle_t)*image_objp, load_options_path); |
Simon Glass | 7816c7a | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 238 | /** |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 239 | * bootefi_run_finish() - finish up after running an EFI test |
| 240 | * |
| 241 | * @loaded_image_info: Pointer to a struct which holds the loaded image info |
| 242 | * @image_objj: Pointer to a struct which holds the loaded image object |
| 243 | */ |
| 244 | static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, |
| 245 | struct efi_loaded_image *loaded_image_info) |
| 246 | { |
| 247 | efi_restore_gd(); |
| 248 | free(loaded_image_info->load_options); |
| 249 | efi_delete_handle(&image_obj->header); |
| 250 | } |
| 251 | |
| 252 | /** |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 253 | * do_bootefi_exec() - execute EFI binary |
| 254 | * |
| 255 | * @efi: address of the binary |
| 256 | * @device_path: path of the device from which the binary was loaded |
| 257 | * @image_path: device path of the binary |
| 258 | * Return: status code |
| 259 | * |
| 260 | * Load the EFI binary into a newly assigned memory unwinding the relocation |
| 261 | * information, install the loaded image protocol, and call the binary. |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 262 | */ |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 263 | static efi_status_t do_bootefi_exec(void *efi, |
Heinrich Schuchardt | 4e363a9 | 2017-10-18 18:13:08 +0200 | [diff] [blame] | 264 | struct efi_device_path *device_path, |
| 265 | struct efi_device_path *image_path) |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 266 | { |
Heinrich Schuchardt | 078d6e2 | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 267 | efi_handle_t mem_handle = NULL; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 268 | struct efi_device_path *memdp = NULL; |
Heinrich Schuchardt | 4b055a2 | 2018-03-03 15:29:01 +0100 | [diff] [blame] | 269 | efi_status_t ret; |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 270 | struct efi_loaded_image_obj *image_obj = NULL; |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 271 | struct efi_loaded_image *loaded_image_info = NULL; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 272 | |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 273 | /* |
| 274 | * Special case for efi payload not loaded from disk, such as |
| 275 | * 'bootefi hello' or for example payload loaded directly into |
Heinrich Schuchardt | 5e96f42 | 2018-10-18 21:51:38 +0200 | [diff] [blame] | 276 | * memory via JTAG, etc: |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 277 | */ |
| 278 | if (!device_path && !image_path) { |
| 279 | printf("WARNING: using memory device/image path, this may confuse some payloads!\n"); |
| 280 | /* actual addresses filled in after efi_load_pe() */ |
Heinrich Schuchardt | 4c419bb | 2018-12-26 22:23:00 +0100 | [diff] [blame] | 281 | memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 282 | device_path = image_path = memdp; |
Heinrich Schuchardt | 078d6e2 | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 283 | /* |
| 284 | * Grub expects that the device path of the loaded image is |
| 285 | * installed on a handle. |
| 286 | */ |
| 287 | ret = efi_create_handle(&mem_handle); |
| 288 | if (ret != EFI_SUCCESS) |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 289 | return ret; /* TODO: leaks device_path */ |
Heinrich Schuchardt | 078d6e2 | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 290 | ret = efi_add_protocol(mem_handle, &efi_guid_device_path, |
Alexander Graf | 2d00dbe | 2018-06-12 10:21:16 +0200 | [diff] [blame] | 291 | device_path); |
| 292 | if (ret != EFI_SUCCESS) |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 293 | goto err_add_protocol; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 294 | } else { |
| 295 | assert(device_path && image_path); |
| 296 | } |
| 297 | |
Simon Glass | 7816c7a | 2018-11-25 20:14:38 -0700 | [diff] [blame] | 298 | ret = bootefi_run_prepare("bootargs", device_path, image_path, |
| 299 | &image_obj, &loaded_image_info); |
| 300 | if (ret) |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 301 | goto err_prepare; |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 302 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 303 | /* Load the EFI payload */ |
Heinrich Schuchardt | 408fbcc | 2018-12-26 12:49:09 +0100 | [diff] [blame] | 304 | ret = efi_load_pe(image_obj, efi, loaded_image_info); |
| 305 | if (ret != EFI_SUCCESS) |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 306 | goto err_prepare; |
Alexander Graf | 7725609 | 2016-08-16 21:08:45 +0200 | [diff] [blame] | 307 | |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 308 | if (memdp) { |
| 309 | struct efi_device_path_memory *mdp = (void *)memdp; |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 310 | mdp->memory_type = loaded_image_info->image_code_type; |
| 311 | mdp->start_address = (uintptr_t)loaded_image_info->image_base; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 312 | mdp->end_address = mdp->start_address + |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 313 | loaded_image_info->image_size; |
Rob Clark | 18ceba7 | 2017-10-10 08:23:06 -0400 | [diff] [blame] | 314 | } |
| 315 | |
Rob Clark | 15f3d74 | 2017-09-13 18:05:37 -0400 | [diff] [blame] | 316 | /* we don't support much: */ |
| 317 | env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", |
| 318 | "{ro,boot}(blob)0000000000000000"); |
| 319 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 320 | /* Call our payload! */ |
Heinrich Schuchardt | 408fbcc | 2018-12-26 12:49:09 +0100 | [diff] [blame] | 321 | debug("%s: Jumping to 0x%p\n", __func__, image_obj->entry); |
Heinrich Schuchardt | 2f8eb08 | 2018-12-26 13:28:09 +0100 | [diff] [blame] | 322 | ret = EFI_CALL(efi_start_image(&image_obj->header, NULL, NULL)); |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 323 | |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 324 | err_prepare: |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 325 | /* image has returned, loaded-image obj goes *poof*: */ |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 326 | bootefi_run_finish(image_obj, loaded_image_info); |
| 327 | |
| 328 | err_add_protocol: |
Heinrich Schuchardt | 078d6e2 | 2018-09-16 07:19:48 +0200 | [diff] [blame] | 329 | if (mem_handle) |
| 330 | efi_delete_handle(mem_handle); |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 331 | |
| 332 | return ret; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 335 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
| 336 | /** |
| 337 | * bootefi_test_prepare() - prepare to run an EFI test |
| 338 | * |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 339 | * 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] | 340 | * |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 341 | * @image_objp: pointer to be set to the loaded image handle |
| 342 | * @loaded_image_infop: pointer to be set to the loaded image protocol |
| 343 | * @path: dummy file path used to construct the device path |
| 344 | * set in the loaded image protocol |
| 345 | * @load_options_path: name of a U-Boot environment variable. Its value is |
| 346 | * set as load options in the loaded image protocol. |
| 347 | * Return: status code |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 348 | */ |
| 349 | static efi_status_t bootefi_test_prepare |
| 350 | (struct efi_loaded_image_obj **image_objp, |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 351 | struct efi_loaded_image **loaded_image_infop, const char *path, |
| 352 | const char *load_options_path) |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 353 | { |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 354 | efi_status_t ret; |
| 355 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 356 | /* Construct a dummy device path */ |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 357 | 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] | 358 | if (!bootefi_device_path) |
| 359 | return EFI_OUT_OF_RESOURCES; |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 360 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 361 | bootefi_image_path = efi_dp_from_file(NULL, 0, path); |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 362 | if (!bootefi_image_path) { |
| 363 | ret = EFI_OUT_OF_RESOURCES; |
| 364 | goto failure; |
| 365 | } |
| 366 | |
| 367 | ret = bootefi_run_prepare(load_options_path, bootefi_device_path, |
| 368 | bootefi_image_path, image_objp, |
| 369 | loaded_image_infop); |
| 370 | if (ret == EFI_SUCCESS) |
| 371 | return ret; |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 372 | |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 373 | efi_free_pool(bootefi_image_path); |
| 374 | bootefi_image_path = NULL; |
| 375 | failure: |
| 376 | efi_free_pool(bootefi_device_path); |
| 377 | bootefi_device_path = NULL; |
| 378 | return ret; |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Simon Glass | 93f2559 | 2018-11-25 20:14:37 -0700 | [diff] [blame] | 381 | #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ |
| 382 | |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 383 | static int do_bootefi_bootmgr_exec(void) |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 384 | { |
| 385 | struct efi_device_path *device_path, *file_path; |
| 386 | void *addr; |
| 387 | efi_status_t r; |
| 388 | |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 389 | addr = efi_bootmgr_load(&device_path, &file_path); |
| 390 | if (!addr) |
| 391 | return 1; |
| 392 | |
| 393 | printf("## Starting EFI application at %p ...\n", addr); |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 394 | r = do_bootefi_exec(addr, device_path, file_path); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 395 | printf("## Application terminated, r = %lu\n", |
| 396 | r & ~EFI_ERROR_MASK); |
| 397 | |
| 398 | if (r != EFI_SUCCESS) |
| 399 | return 1; |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 404 | /* Interpreter command to boot an arbitrary EFI image from memory */ |
| 405 | static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 406 | { |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 407 | unsigned long addr; |
| 408 | char *saddr; |
Heinrich Schuchardt | 4e363a9 | 2017-10-18 18:13:08 +0200 | [diff] [blame] | 409 | efi_status_t r; |
Alexander Graf | a241451 | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 410 | unsigned long fdt_addr; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 411 | |
Heinrich Schuchardt | 954e2b9 | 2018-04-03 21:59:32 +0200 | [diff] [blame] | 412 | /* Allow unaligned memory access */ |
| 413 | allow_unaligned(); |
| 414 | |
Heinrich Schuchardt | aa0b11b | 2019-01-08 18:13:06 +0100 | [diff] [blame] | 415 | switch_to_non_secure_mode(); |
| 416 | |
Heinrich Schuchardt | 8c0dfc2 | 2018-03-03 15:29:02 +0100 | [diff] [blame] | 417 | /* Initialize EFI drivers */ |
| 418 | r = efi_init_obj_list(); |
| 419 | if (r != EFI_SUCCESS) { |
| 420 | printf("Error: Cannot set up EFI drivers, r = %lu\n", |
| 421 | r & ~EFI_ERROR_MASK); |
| 422 | return CMD_RET_FAILURE; |
| 423 | } |
| 424 | |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 425 | if (argc < 2) |
Bin Meng | da800ff | 2016-08-13 04:02:06 -0700 | [diff] [blame] | 426 | return CMD_RET_USAGE; |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 427 | |
| 428 | if (argc > 2) { |
Alexander Graf | a241451 | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 429 | fdt_addr = simple_strtoul(argv[2], NULL, 16); |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 430 | if (!fdt_addr && *argv[2] != '0') |
| 431 | return CMD_RET_USAGE; |
| 432 | /* Install device tree */ |
Simon Glass | 5d618df | 2018-08-08 03:54:30 -0600 | [diff] [blame] | 433 | r = efi_install_fdt(fdt_addr); |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 434 | if (r != EFI_SUCCESS) { |
| 435 | printf("ERROR: failed to install device tree\n"); |
| 436 | return CMD_RET_FAILURE; |
| 437 | } |
| 438 | } else { |
| 439 | /* Remove device tree. EFI_NOT_FOUND can be ignored here */ |
| 440 | efi_install_configuration_table(&efi_guid_fdt, NULL); |
| 441 | printf("WARNING: booting without device tree\n"); |
| 442 | } |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 443 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
| 444 | if (!strcmp(argv[1], "hello")) { |
Heinrich Schuchardt | 7804ae9 | 2017-09-05 03:19:37 +0200 | [diff] [blame] | 445 | ulong size = __efi_helloworld_end - __efi_helloworld_begin; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 446 | |
Heinrich Schuchardt | e6a9ab5 | 2017-08-28 18:54:30 +0200 | [diff] [blame] | 447 | saddr = env_get("loadaddr"); |
| 448 | if (saddr) |
| 449 | addr = simple_strtoul(saddr, NULL, 16); |
| 450 | else |
| 451 | addr = CONFIG_SYS_LOAD_ADDR; |
Alexander Graf | a241451 | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 452 | memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 453 | } else |
| 454 | #endif |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 455 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
| 456 | if (!strcmp(argv[1], "selftest")) { |
Heinrich Schuchardt | 4f94ec5 | 2018-09-26 05:27:54 +0200 | [diff] [blame] | 457 | struct efi_loaded_image_obj *image_obj; |
Heinrich Schuchardt | 3c3a735 | 2018-09-23 17:21:51 +0200 | [diff] [blame] | 458 | struct efi_loaded_image *loaded_image_info; |
Heinrich Schuchardt | 389f251 | 2017-09-20 22:54:58 +0200 | [diff] [blame] | 459 | |
Heinrich Schuchardt | fd9cbe3 | 2019-01-12 14:42:40 +0100 | [diff] [blame] | 460 | r = bootefi_test_prepare(&image_obj, &loaded_image_info, |
| 461 | "\\selftest", "efi_selftest"); |
| 462 | if (r != EFI_SUCCESS) |
Simon Glass | 758cfa1 | 2018-11-25 20:14:36 -0700 | [diff] [blame] | 463 | return CMD_RET_FAILURE; |
| 464 | |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 465 | /* Execute the test */ |
Heinrich Schuchardt | 7250623 | 2019-02-09 14:10:39 +0100 | [diff] [blame] | 466 | r = EFI_CALL(efi_selftest(&image_obj->header, &systab)); |
Simon Glass | 4d77ee6 | 2018-11-25 20:14:39 -0700 | [diff] [blame] | 467 | bootefi_run_finish(image_obj, loaded_image_info); |
Heinrich Schuchardt | d2d90b4 | 2017-10-18 18:13:14 +0200 | [diff] [blame] | 468 | return r != EFI_SUCCESS; |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 469 | } else |
| 470 | #endif |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 471 | if (!strcmp(argv[1], "bootmgr")) { |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 472 | return do_bootefi_bootmgr_exec(); |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 473 | } else { |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 474 | saddr = argv[1]; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 475 | |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 476 | addr = simple_strtoul(saddr, NULL, 16); |
Heinrich Schuchardt | aa6fd9a | 2018-01-24 20:33:54 +0100 | [diff] [blame] | 477 | /* Check that a numeric value was passed */ |
| 478 | if (!addr && *saddr != '0') |
| 479 | return CMD_RET_USAGE; |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 480 | |
Alexander Graf | 54c1e83 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Simon Glass | 1a5490e | 2016-11-07 08:47:05 -0700 | [diff] [blame] | 483 | printf("## Starting EFI application at %08lx ...\n", addr); |
Alexander Graf | a241451 | 2018-06-18 17:22:58 +0200 | [diff] [blame] | 484 | r = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 485 | bootefi_image_path); |
xypron.glpk@gmx.de | 5eadbfa | 2017-07-04 23:15:23 +0200 | [diff] [blame] | 486 | printf("## Application terminated, r = %lu\n", |
| 487 | r & ~EFI_ERROR_MASK); |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 488 | |
xypron.glpk@gmx.de | 5eadbfa | 2017-07-04 23:15:23 +0200 | [diff] [blame] | 489 | if (r != EFI_SUCCESS) |
| 490 | return 1; |
| 491 | else |
| 492 | return 0; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | #ifdef CONFIG_SYS_LONGHELP |
| 496 | static char bootefi_help_text[] = |
Alexander Graf | 54c1e83 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 497 | "<image address> [fdt address]\n" |
| 498 | " - boot EFI payload stored at address <image address>.\n" |
| 499 | " If specified, the device tree located at <fdt address> gets\n" |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 500 | " exposed as EFI configuration table.\n" |
| 501 | #ifdef CONFIG_CMD_BOOTEFI_HELLO |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 502 | "bootefi hello\n" |
| 503 | " - boot a sample Hello World application stored within U-Boot\n" |
| 504 | #endif |
| 505 | #ifdef CONFIG_CMD_BOOTEFI_SELFTEST |
Heinrich Schuchardt | 44ab21b | 2018-03-03 15:29:03 +0100 | [diff] [blame] | 506 | "bootefi selftest [fdt address]\n" |
Heinrich Schuchardt | d33ae3e | 2017-09-15 10:06:11 +0200 | [diff] [blame] | 507 | " - boot an EFI selftest application stored within U-Boot\n" |
Heinrich Schuchardt | 02efd5d | 2017-10-18 18:13:13 +0200 | [diff] [blame] | 508 | " Use environment variable efi_selftest to select a single test.\n" |
| 509 | " Use 'setenv efi_selftest list' to enumerate all tests.\n" |
Simon Glass | fac4ced | 2016-11-07 08:47:08 -0700 | [diff] [blame] | 510 | #endif |
Heinrich Schuchardt | 1b2320f | 2018-01-30 19:47:43 +0100 | [diff] [blame] | 511 | "bootefi bootmgr [fdt addr]\n" |
Rob Clark | c84c110 | 2017-09-13 18:05:38 -0400 | [diff] [blame] | 512 | " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" |
| 513 | "\n" |
| 514 | " If specified, the device tree located at <fdt address> gets\n" |
| 515 | " exposed as EFI configuration table.\n"; |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 516 | #endif |
| 517 | |
| 518 | U_BOOT_CMD( |
Alexander Graf | 54c1e83 | 2016-04-14 16:07:53 +0200 | [diff] [blame] | 519 | bootefi, 3, 0, do_bootefi, |
Sergey Kubushyn | 268f19e | 2016-06-07 11:14:31 -0700 | [diff] [blame] | 520 | "Boots an EFI payload from memory", |
Alexander Graf | e2b04f2 | 2016-03-10 00:27:20 +0100 | [diff] [blame] | 521 | bootefi_help_text |
| 522 | ); |
Alexander Graf | 8f19f26 | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 523 | |
Rob Clark | f8db922 | 2017-09-13 18:05:33 -0400 | [diff] [blame] | 524 | void efi_set_bootdev(const char *dev, const char *devnr, const char *path) |
| 525 | { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 526 | struct efi_device_path *device, *image; |
| 527 | efi_status_t ret; |
Alexander Graf | 34118e7 | 2016-08-05 14:49:53 +0200 | [diff] [blame] | 528 | |
Heinrich Schuchardt | 761ecc8 | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 529 | /* efi_set_bootdev is typically called repeatedly, recover memory */ |
| 530 | efi_free_pool(bootefi_device_path); |
| 531 | efi_free_pool(bootefi_image_path); |
Heinrich Schuchardt | 761ecc8 | 2018-09-16 07:20:21 +0200 | [diff] [blame] | 532 | |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 533 | ret = efi_dp_from_name(dev, devnr, path, &device, &image); |
| 534 | if (ret == EFI_SUCCESS) { |
| 535 | bootefi_device_path = device; |
| 536 | bootefi_image_path = image; |
Alexander Graf | 45e437d | 2016-07-21 01:44:46 +0200 | [diff] [blame] | 537 | } else { |
AKASHI Takahiro | 035fb01 | 2018-10-17 16:32:03 +0900 | [diff] [blame] | 538 | bootefi_device_path = NULL; |
| 539 | bootefi_image_path = NULL; |
Alexander Graf | 45e437d | 2016-07-21 01:44:46 +0200 | [diff] [blame] | 540 | } |
Alexander Graf | 8f19f26 | 2016-03-04 01:10:14 +0100 | [diff] [blame] | 541 | } |