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