]> git.ipfire.org Git - thirdparty/u-boot.git/blame - cmd/bootefi.c
efi_loader: memory reservation for fdt
[thirdparty/u-boot.git] / cmd / bootefi.c
CommitLineData
f739fcd8 1// SPDX-License-Identifier: GPL-2.0+
b9939336
AG
2/*
3 * EFI application loader
4 *
5 * Copyright (c) 2016 Alexander Graf
b9939336
AG
6 */
7
d78e40d6 8#include <charset.h>
b9939336
AG
9#include <common.h>
10#include <command.h>
9d922450 11#include <dm.h>
b9939336 12#include <efi_loader.h>
d78e40d6 13#include <efi_selftest.h>
b9939336 14#include <errno.h>
b08c8c48
MY
15#include <linux/libfdt.h>
16#include <linux/libfdt_env.h>
354264b3 17#include <mapmem.h>
ad0c1a3d 18#include <memalign.h>
0d9d501f 19#include <asm/global_data.h>
e275458c 20#include <asm-generic/sections.h>
c3b11dea 21#include <asm-generic/unaligned.h>
e275458c 22#include <linux/linkage.h>
0d9d501f 23
dc500c36
MK
24#ifdef CONFIG_ARMV7_NONSEC
25#include <asm/armv7.h>
26#include <asm/secure.h>
27#endif
28
0d9d501f 29DECLARE_GLOBAL_DATA_PTR;
b9939336 30
fc225e60
HS
31#define OBJ_LIST_NOT_INITIALIZED 1
32
33static efi_status_t efi_obj_list_initialized = OBJ_LIST_NOT_INITIALIZED;
7cbc1241 34
95c5553e
RC
35static struct efi_device_path *bootefi_image_path;
36static struct efi_device_path *bootefi_device_path;
b9939336 37
7cbc1241 38/* Initialize and populate EFI object list */
fc225e60 39efi_status_t efi_init_obj_list(void)
7cbc1241 40{
fc225e60
HS
41 efi_status_t ret = EFI_SUCCESS;
42
1e1e1c27
HS
43 /*
44 * On the ARM architecture gd is mapped to a fixed register (r9 or x18).
45 * As this register may be overwritten by an EFI payload we save it here
46 * and restore it on every callback entered.
47 */
48 efi_save_gd();
49
098a6cdd 50 /* Initialize once only */
fc225e60
HS
51 if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED)
52 return efi_obj_list_initialized;
7cbc1241 53
640adadf
HS
54 /* Initialize system table */
55 ret = efi_initialize_system_table();
56 if (ret != EFI_SUCCESS)
57 goto out;
58
4e6b5d65
HS
59 /* Initialize root node */
60 ret = efi_root_node_register();
61 if (ret != EFI_SUCCESS)
62 goto out;
63
05ef48a2 64 /* Initialize EFI driver uclass */
fc225e60
HS
65 ret = efi_driver_init();
66 if (ret != EFI_SUCCESS)
67 goto out;
05ef48a2 68
fc225e60
HS
69 ret = efi_console_register();
70 if (ret != EFI_SUCCESS)
71 goto out;
7cbc1241 72#ifdef CONFIG_PARTITIONS
fc225e60
HS
73 ret = efi_disk_register();
74 if (ret != EFI_SUCCESS)
75 goto out;
7cbc1241
HS
76#endif
77#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
fc225e60
HS
78 ret = efi_gop_register();
79 if (ret != EFI_SUCCESS)
80 goto out;
7cbc1241 81#endif
092f2f35 82#ifdef CONFIG_NET
fc225e60
HS
83 ret = efi_net_register();
84 if (ret != EFI_SUCCESS)
85 goto out;
7cbc1241 86#endif
86df34d4
BM
87#ifdef CONFIG_GENERATE_ACPI_TABLE
88 ret = efi_acpi_register();
89 if (ret != EFI_SUCCESS)
90 goto out;
91#endif
7cbc1241 92#ifdef CONFIG_GENERATE_SMBIOS_TABLE
fc225e60
HS
93 ret = efi_smbios_register();
94 if (ret != EFI_SUCCESS)
95 goto out;
7cbc1241 96#endif
fc225e60
HS
97 ret = efi_watchdog_register();
98 if (ret != EFI_SUCCESS)
99 goto out;
7cbc1241
HS
100
101 /* Initialize EFI runtime services */
fc225e60
HS
102 ret = efi_reset_system_init();
103 if (ret != EFI_SUCCESS)
104 goto out;
fc225e60
HS
105
106out:
107 efi_obj_list_initialized = ret;
108 return ret;
7cbc1241
HS
109}
110
c3b11dea
HS
111/*
112 * Allow unaligned memory access.
113 *
114 * This routine is overridden by architectures providing this feature.
115 */
116void __weak allow_unaligned(void)
117{
118}
119
d78e40d6
HS
120/*
121 * Set the load options of an image from an environment variable.
122 *
123 * @loaded_image_info: the image
124 * @env_var: name of the environment variable
125 */
126static void set_load_options(struct efi_loaded_image *loaded_image_info,
127 const char *env_var)
128{
129 size_t size;
130 const char *env = env_get(env_var);
7086a71a 131 u16 *pos;
d78e40d6
HS
132
133 loaded_image_info->load_options = NULL;
134 loaded_image_info->load_options_size = 0;
135 if (!env)
136 return;
7086a71a 137 size = utf8_utf16_strlen(env) + 1;
d78e40d6
HS
138 loaded_image_info->load_options = calloc(size, sizeof(u16));
139 if (!loaded_image_info->load_options) {
140 printf("ERROR: Out of memory\n");
141 return;
142 }
7086a71a
HS
143 pos = loaded_image_info->load_options;
144 utf8_utf16_strcpy(&pos, env);
d78e40d6
HS
145 loaded_image_info->load_options_size = size * 2;
146}
147
9dff4900
SG
148/**
149 * copy_fdt() - Copy the device tree to a new location available to EFI
150 *
151 * The FDT is relocated into a suitable location within the EFI memory map.
152 * An additional 12KB is added to the space in case the device tree needs to be
153 * expanded later with fdt_open_into().
154 *
4574d1b3
HS
155 * @fdt_addr: On entry, address of start of FDT. On exit, address of relocated
156 * FDT start
157 * Return: status code
9dff4900 158 */
4574d1b3 159static efi_status_t copy_fdt(ulong *fdt_addrp)
0d9d501f 160{
ad0c1a3d 161 unsigned long fdt_ram_start = -1L, fdt_pages;
9dff4900
SG
162 efi_status_t ret = 0;
163 void *fdt, *new_fdt;
ad0c1a3d 164 u64 new_fdt_addr;
9dff4900 165 uint fdt_size;
ad0c1a3d 166 int i;
0d9d501f 167
9dff4900
SG
168 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
169 u64 ram_start = gd->bd->bi_dram[i].start;
170 u64 ram_size = gd->bd->bi_dram[i].size;
0d9d501f 171
ad0c1a3d
AG
172 if (!ram_size)
173 continue;
174
175 if (ram_start < fdt_ram_start)
176 fdt_ram_start = ram_start;
177 }
178
bc9a638a
SG
179 /*
180 * Give us at least 4KB of breathing room in case the device tree needs
181 * to be expanded later. Round up to the nearest EFI page boundary.
182 */
9dff4900
SG
183 fdt = map_sysmem(*fdt_addrp, 0);
184 fdt_size = fdt_totalsize(fdt);
185 fdt_size += 4096 * 3;
bc9a638a 186 fdt_size = ALIGN(fdt_size + EFI_PAGE_SIZE - 1, EFI_PAGE_SIZE);
ad0c1a3d
AG
187 fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
188
baf70c02
SG
189 /* Safe fdt location is at 127MB */
190 new_fdt_addr = fdt_ram_start + (127 * 1024 * 1024) + fdt_size;
9dff4900
SG
191 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
192 EFI_RUNTIME_SERVICES_DATA, fdt_pages,
193 &new_fdt_addr);
194 if (ret != EFI_SUCCESS) {
ad0c1a3d 195 /* If we can't put it there, put it somewhere */
a44bffcc 196 new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
9dff4900
SG
197 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
198 EFI_RUNTIME_SERVICES_DATA, fdt_pages,
199 &new_fdt_addr);
200 if (ret != EFI_SUCCESS) {
85a6e9b3 201 printf("ERROR: Failed to reserve space for FDT\n");
9dff4900 202 goto done;
85a6e9b3 203 }
ad0c1a3d 204 }
85a6e9b3 205
9dff4900 206 new_fdt = map_sysmem(new_fdt_addr, fdt_size);
0d9d501f
AG
207 memcpy(new_fdt, fdt, fdt_totalsize(fdt));
208 fdt_set_totalsize(new_fdt, fdt_size);
209
9dff4900 210 *fdt_addrp = new_fdt_addr;
9dff4900
SG
211done:
212 return ret;
0d9d501f
AG
213}
214
3eb0841b 215static efi_status_t efi_do_enter(
2074f700 216 efi_handle_t image_handle, struct efi_system_table *st,
c6fa5df6
AG
217 EFIAPI efi_status_t (*entry)(
218 efi_handle_t image_handle,
219 struct efi_system_table *st))
b06d8ac3
HS
220{
221 efi_status_t ret = EFI_LOAD_ERROR;
222
223 if (entry)
224 ret = entry(image_handle, st);
225 st->boottime->exit(image_handle, ret, 0, NULL);
226 return ret;
227}
228
ec6617c3 229#ifdef CONFIG_ARM64
c6fa5df6 230static efi_status_t efi_run_in_el2(EFIAPI efi_status_t (*entry)(
2074f700
HS
231 efi_handle_t image_handle, struct efi_system_table *st),
232 efi_handle_t image_handle, struct efi_system_table *st)
ec6617c3
AW
233{
234 /* Enable caches again */
235 dcache_enable();
236
b06d8ac3 237 return efi_do_enter(image_handle, st, entry);
ec6617c3
AW
238}
239#endif
240
dc500c36 241#ifdef CONFIG_ARMV7_NONSEC
f17f2001
MK
242static bool is_nonsec;
243
dc500c36
MK
244static efi_status_t efi_run_in_hyp(EFIAPI efi_status_t (*entry)(
245 efi_handle_t image_handle, struct efi_system_table *st),
246 efi_handle_t image_handle, struct efi_system_table *st)
247{
248 /* Enable caches again */
249 dcache_enable();
250
f17f2001
MK
251 is_nonsec = true;
252
dc500c36
MK
253 return efi_do_enter(image_handle, st, entry);
254}
255#endif
256
416e07e2
SG
257/*
258 * efi_carve_out_dt_rsv() - Carve out DT reserved memory ranges
259 *
260 * The mem_rsv entries of the FDT are added to the memory map. Any failures are
261 * ignored because this is not critical and we would rather continue to try to
262 * boot.
263 *
264 * @fdt: Pointer to device tree
265 */
266static void efi_carve_out_dt_rsv(void *fdt)
806d2fa8
AG
267{
268 int nr_rsv, i;
269 uint64_t addr, size, pages;
270
271 nr_rsv = fdt_num_mem_rsv(fdt);
272
273 /* Look for an existing entry and add it to the efi mem map. */
274 for (i = 0; i < nr_rsv; i++) {
275 if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0)
276 continue;
277
278 pages = ALIGN(size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT;
416e07e2
SG
279 if (!efi_add_memory_map(addr, pages, EFI_RESERVED_MEMORY_TYPE,
280 false))
281 printf("FDT memrsv map %d: Failed to add to map\n", i);
806d2fa8 282 }
806d2fa8
AG
283}
284
9dff4900 285static efi_status_t efi_install_fdt(ulong fdt_addr)
bc4f9133
HS
286{
287 bootm_headers_t img = { 0 };
bc4f9133 288 efi_status_t ret;
9dff4900 289 void *fdt;
bc4f9133 290
9dff4900 291 fdt = map_sysmem(fdt_addr, 0);
bc4f9133
HS
292 if (fdt_check_header(fdt)) {
293 printf("ERROR: invalid device tree\n");
294 return EFI_INVALID_PARAMETER;
295 }
296
297 /* Prepare fdt for payload */
4574d1b3 298 ret = copy_fdt(&fdt_addr);
9dff4900
SG
299 if (ret)
300 return ret;
bc4f9133 301
9dff4900
SG
302 unmap_sysmem(fdt);
303 fdt = map_sysmem(fdt_addr, 0);
bc4f9133
HS
304 if (image_setup_libfdt(&img, fdt, 0, NULL)) {
305 printf("ERROR: failed to process device tree\n");
306 return EFI_LOAD_ERROR;
307 }
308
416e07e2 309 efi_carve_out_dt_rsv(fdt);
806d2fa8 310
bc4f9133
HS
311 /* Link to it in the efi tables */
312 ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
313 if (ret != EFI_SUCCESS)
314 return EFI_OUT_OF_RESOURCES;
315
bc4f9133
HS
316 return ret;
317}
318
c982874e
HS
319/**
320 * do_bootefi_exec() - execute EFI binary
321 *
322 * @efi: address of the binary
323 * @device_path: path of the device from which the binary was loaded
324 * @image_path: device path of the binary
325 * Return: status code
326 *
327 * Load the EFI binary into a newly assigned memory unwinding the relocation
328 * information, install the loaded image protocol, and call the binary.
b9939336 329 */
bc4f9133 330static efi_status_t do_bootefi_exec(void *efi,
3eb0841b
HS
331 struct efi_device_path *device_path,
332 struct efi_device_path *image_path)
b9939336 333{
8887acc6 334 efi_handle_t mem_handle = NULL;
bf19273e 335 struct efi_device_path *memdp = NULL;
45204b10 336 efi_status_t ret;
faea1041 337 struct efi_loaded_image_obj *image_obj = NULL;
c982874e 338 struct efi_loaded_image *loaded_image_info = NULL;
95c5553e 339
c6fa5df6
AG
340 EFIAPI efi_status_t (*entry)(efi_handle_t image_handle,
341 struct efi_system_table *st);
b9939336 342
bf19273e
RC
343 /*
344 * Special case for efi payload not loaded from disk, such as
345 * 'bootefi hello' or for example payload loaded directly into
e1fec152 346 * memory via JTAG, etc:
bf19273e
RC
347 */
348 if (!device_path && !image_path) {
349 printf("WARNING: using memory device/image path, this may confuse some payloads!\n");
350 /* actual addresses filled in after efi_load_pe() */
351 memdp = efi_dp_from_mem(0, 0, 0);
352 device_path = image_path = memdp;
8887acc6
HS
353 /*
354 * Grub expects that the device path of the loaded image is
355 * installed on a handle.
356 */
357 ret = efi_create_handle(&mem_handle);
358 if (ret != EFI_SUCCESS)
359 goto exit;
360 ret = efi_add_protocol(mem_handle, &efi_guid_device_path,
58bc69d2
AG
361 device_path);
362 if (ret != EFI_SUCCESS)
363 goto exit;
bf19273e
RC
364 } else {
365 assert(device_path && image_path);
366 }
367
faea1041 368 ret = efi_setup_loaded_image(device_path, image_path, &image_obj,
c982874e
HS
369 &loaded_image_info);
370 if (ret != EFI_SUCCESS)
371 goto exit;
95c5553e 372
b57f48a8 373 /* Transfer environment variable bootargs as load options */
c982874e 374 set_load_options(loaded_image_info, "bootargs");
b9939336 375 /* Load the EFI payload */
faea1041 376 entry = efi_load_pe(image_obj, efi, loaded_image_info);
95c5553e 377 if (!entry) {
45204b10 378 ret = EFI_LOAD_ERROR;
95c5553e
RC
379 goto exit;
380 }
80a4800e 381
bf19273e
RC
382 if (memdp) {
383 struct efi_device_path_memory *mdp = (void *)memdp;
c982874e
HS
384 mdp->memory_type = loaded_image_info->image_code_type;
385 mdp->start_address = (uintptr_t)loaded_image_info->image_base;
bf19273e 386 mdp->end_address = mdp->start_address +
c982874e 387 loaded_image_info->image_size;
bf19273e
RC
388 }
389
ad644e7c
RC
390 /* we don't support much: */
391 env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported",
392 "{ro,boot}(blob)0000000000000000");
393
b9939336 394 /* Call our payload! */
edcef3ba 395 debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
a86aeaf2 396
faea1041
HS
397 if (setjmp(&image_obj->exit_jmp)) {
398 ret = image_obj->exit_status;
95c5553e 399 goto exit;
a86aeaf2
AG
400 }
401
69bd459d
AG
402#ifdef CONFIG_ARM64
403 /* On AArch64 we need to make sure we call our payload in < EL3 */
404 if (current_el() == 3) {
405 smp_kick_all_cpus();
406 dcache_disable(); /* flush cache before switch to EL2 */
ec6617c3
AW
407
408 /* Move into EL2 and keep running there */
ea54ad59 409 armv8_switch_to_el2((ulong)entry,
d39646a3 410 (ulong)&image_obj->header,
7c5e1feb 411 (ulong)&systab, 0, (ulong)efi_run_in_el2,
ec6617c3
AW
412 ES_TO_AARCH64);
413
414 /* Should never reach here, efi exits with longjmp */
415 while (1) { }
69bd459d
AG
416 }
417#endif
418
dc500c36 419#ifdef CONFIG_ARMV7_NONSEC
f17f2001 420 if (armv7_boot_nonsec() && !is_nonsec) {
dc500c36
MK
421 dcache_disable(); /* flush cache before switch to HYP */
422
423 armv7_init_nonsec();
424 secure_ram_addr(_do_nonsec_entry)(
425 efi_run_in_hyp,
426 (uintptr_t)entry,
d39646a3 427 (uintptr_t)&image_obj->header,
dc500c36
MK
428 (uintptr_t)&systab);
429
430 /* Should never reach here, efi exits with longjmp */
431 while (1) { }
432 }
433#endif
434
d39646a3 435 ret = efi_do_enter(&image_obj->header, &systab, entry);
95c5553e
RC
436
437exit:
438 /* image has returned, loaded-image obj goes *poof*: */
faea1041 439 if (image_obj)
d39646a3 440 efi_delete_handle(&image_obj->header);
8887acc6
HS
441 if (mem_handle)
442 efi_delete_handle(mem_handle);
95c5553e
RC
443
444 return ret;
b9939336
AG
445}
446
bc4f9133 447static int do_bootefi_bootmgr_exec(void)
9975fe96
RC
448{
449 struct efi_device_path *device_path, *file_path;
450 void *addr;
451 efi_status_t r;
452
9975fe96
RC
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);
bc4f9133 458 r = do_bootefi_exec(addr, device_path, file_path);
9975fe96
RC
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
b9939336
AG
468/* Interpreter command to boot an arbitrary EFI image from memory */
469static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
470{
bc4f9133
HS
471 unsigned long addr;
472 char *saddr;
3eb0841b 473 efi_status_t r;
354264b3 474 unsigned long fdt_addr;
b9939336 475
c3b11dea
HS
476 /* Allow unaligned memory access */
477 allow_unaligned();
478
fc225e60
HS
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
b9939336 487 if (argc < 2)
3c1dcef6 488 return CMD_RET_USAGE;
bc4f9133
HS
489
490 if (argc > 2) {
354264b3 491 fdt_addr = simple_strtoul(argv[2], NULL, 16);
bc4f9133
HS
492 if (!fdt_addr && *argv[2] != '0')
493 return CMD_RET_USAGE;
494 /* Install device tree */
9dff4900 495 r = efi_install_fdt(fdt_addr);
bc4f9133
HS
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 }
c7ae3dfd
SG
505#ifdef CONFIG_CMD_BOOTEFI_HELLO
506 if (!strcmp(argv[1], "hello")) {
5e44489b 507 ulong size = __efi_helloworld_end - __efi_helloworld_begin;
b9939336 508
51c533fd
HS
509 saddr = env_get("loadaddr");
510 if (saddr)
511 addr = simple_strtoul(saddr, NULL, 16);
512 else
513 addr = CONFIG_SYS_LOAD_ADDR;
354264b3 514 memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size);
c7ae3dfd 515 } else
623b3a57
HS
516#endif
517#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
518 if (!strcmp(argv[1], "selftest")) {
faea1041 519 struct efi_loaded_image_obj *image_obj;
c982874e 520 struct efi_loaded_image *loaded_image_info;
7aca68ca 521
f972dc14
HS
522 /* Construct a dummy device path. */
523 bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
524 (uintptr_t)&efi_selftest,
525 (uintptr_t)&efi_selftest);
526 bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
527
c982874e 528 r = efi_setup_loaded_image(bootefi_device_path,
faea1041 529 bootefi_image_path, &image_obj,
c982874e
HS
530 &loaded_image_info);
531 if (r != EFI_SUCCESS)
532 return CMD_RET_FAILURE;
533
623b3a57 534 efi_save_gd();
d78e40d6 535 /* Transfer environment variable efi_selftest as load options */
c982874e 536 set_load_options(loaded_image_info, "efi_selftest");
d78e40d6 537 /* Execute the test */
d39646a3 538 r = efi_selftest(&image_obj->header, &systab);
c2b53902 539 efi_restore_gd();
c982874e 540 free(loaded_image_info->load_options);
d39646a3 541 efi_delete_handle(&image_obj->header);
c2b53902 542 return r != EFI_SUCCESS;
623b3a57 543 } else
c7ae3dfd 544#endif
9975fe96 545 if (!strcmp(argv[1], "bootmgr")) {
bc4f9133 546 return do_bootefi_bootmgr_exec();
9975fe96 547 } else {
c7ae3dfd 548 saddr = argv[1];
b9939336 549
c7ae3dfd 550 addr = simple_strtoul(saddr, NULL, 16);
49db1cb8
HS
551 /* Check that a numeric value was passed */
552 if (!addr && *saddr != '0')
553 return CMD_RET_USAGE;
c7ae3dfd 554
1c39809b
AG
555 }
556
5ee31baf 557 printf("## Starting EFI application at %08lx ...\n", addr);
354264b3 558 r = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path,
bc4f9133 559 bootefi_image_path);
1da1bac4
HS
560 printf("## Application terminated, r = %lu\n",
561 r & ~EFI_ERROR_MASK);
b9939336 562
1da1bac4
HS
563 if (r != EFI_SUCCESS)
564 return 1;
565 else
566 return 0;
b9939336
AG
567}
568
569#ifdef CONFIG_SYS_LONGHELP
570static char bootefi_help_text[] =
1c39809b
AG
571 "<image address> [fdt address]\n"
572 " - boot EFI payload stored at address <image address>.\n"
573 " If specified, the device tree located at <fdt address> gets\n"
c7ae3dfd
SG
574 " exposed as EFI configuration table.\n"
575#ifdef CONFIG_CMD_BOOTEFI_HELLO
623b3a57
HS
576 "bootefi hello\n"
577 " - boot a sample Hello World application stored within U-Boot\n"
578#endif
579#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
bc4f9133 580 "bootefi selftest [fdt address]\n"
623b3a57 581 " - boot an EFI selftest application stored within U-Boot\n"
d78e40d6
HS
582 " Use environment variable efi_selftest to select a single test.\n"
583 " Use 'setenv efi_selftest list' to enumerate all tests.\n"
c7ae3dfd 584#endif
f623e07f 585 "bootefi bootmgr [fdt addr]\n"
9975fe96
RC
586 " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n"
587 "\n"
588 " If specified, the device tree located at <fdt address> gets\n"
589 " exposed as EFI configuration table.\n";
b9939336
AG
590#endif
591
592U_BOOT_CMD(
1c39809b 593 bootefi, 3, 0, do_bootefi,
92dfd922 594 "Boots an EFI payload from memory",
b9939336
AG
595 bootefi_help_text
596);
0f4060eb 597
95c5553e
RC
598void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
599{
f1589ffb
AT
600 struct efi_device_path *device, *image;
601 efi_status_t ret;
f9d334bd 602
79276eb2
HS
603 /* efi_set_bootdev is typically called repeatedly, recover memory */
604 efi_free_pool(bootefi_device_path);
605 efi_free_pool(bootefi_image_path);
9975fe96 606
f1589ffb
AT
607 ret = efi_dp_from_name(dev, devnr, path, &device, &image);
608 if (ret == EFI_SUCCESS) {
609 bootefi_device_path = device;
610 bootefi_image_path = image;
49271666 611 } else {
f1589ffb
AT
612 bootefi_device_path = NULL;
613 bootefi_image_path = NULL;
49271666 614 }
0f4060eb 615}