efi_loader: setting boot device
[platform/kernel/u-boot.git] / cmd / bootefi.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  *  EFI application loader
4  *
5  *  Copyright (c) 2016 Alexander Graf
6  */
7
8 #define LOG_CATEGORY LOGC_EFI
9
10 #include <common.h>
11 #include <charset.h>
12 #include <command.h>
13 #include <dm.h>
14 #include <efi_loader.h>
15 #include <efi_selftest.h>
16 #include <env.h>
17 #include <errno.h>
18 #include <image.h>
19 #include <log.h>
20 #include <malloc.h>
21 #include <linux/libfdt.h>
22 #include <linux/libfdt_env.h>
23 #include <mapmem.h>
24 #include <memalign.h>
25 #include <asm-generic/sections.h>
26 #include <linux/linkage.h>
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 static struct efi_device_path *bootefi_image_path;
31 static struct efi_device_path *bootefi_device_path;
32 static void *image_addr;
33 static size_t image_size;
34
35 /**
36  * efi_clear_bootdev() - clear boot device
37  */
38 static void efi_clear_bootdev(void)
39 {
40         efi_free_pool(bootefi_device_path);
41         efi_free_pool(bootefi_image_path);
42         bootefi_device_path = NULL;
43         bootefi_image_path = NULL;
44         image_addr = NULL;
45         image_size = 0;
46 }
47
48 /**
49  * efi_set_bootdev() - set boot device
50  *
51  * This function is called when a file is loaded, e.g. via the 'load' command.
52  * We use the path to this file to inform the UEFI binary about the boot device.
53  *
54  * @dev:                device, e.g. "MMC"
55  * @devnr:              number of the device, e.g. "1:2"
56  * @path:               path to file loaded
57  * @buffer:             buffer with file loaded
58  * @buffer_size:        size of file loaded
59  */
60 void efi_set_bootdev(const char *dev, const char *devnr, const char *path,
61                      void *buffer, size_t buffer_size)
62 {
63         struct efi_device_path *device, *image;
64         efi_status_t ret;
65
66         /* Forget overwritten image */
67         if (buffer + buffer_size >= image_addr &&
68             image_addr + image_size >= buffer)
69                 efi_clear_bootdev();
70
71         /* Remember only PE-COFF and FIT images */
72         if (efi_check_pe(buffer, buffer_size, NULL) != EFI_SUCCESS) {
73 #ifdef CONFIG_FIT
74                 if (!fit_check_format(buffer))
75                         return;
76                 /*
77                  * FIT images of type EFI_OS are started via command bootm.
78                  * We should not use their boot device with the bootefi command.
79                  */
80                 buffer = 0;
81                 buffer_size = 0;
82 #else
83                 return;
84 #endif
85         }
86
87         /* efi_set_bootdev() is typically called repeatedly, recover memory */
88         efi_clear_bootdev();
89
90         image_addr = buffer;
91         image_size = buffer_size;
92
93         ret = efi_dp_from_name(dev, devnr, path, &device, &image);
94         if (ret == EFI_SUCCESS) {
95                 bootefi_device_path = device;
96                 if (image) {
97                         /* FIXME: image should not contain device */
98                         struct efi_device_path *image_tmp = image;
99
100                         efi_dp_split_file_path(image, &device, &image);
101                         efi_free_pool(image_tmp);
102                 }
103                 bootefi_image_path = image;
104         } else {
105                 efi_clear_bootdev();
106         }
107 }
108
109 /**
110  * efi_env_set_load_options() - set load options from environment variable
111  *
112  * @handle:             the image handle
113  * @env_var:            name of the environment variable
114  * @load_options:       pointer to load options (output)
115  * Return:              status code
116  */
117 static efi_status_t efi_env_set_load_options(efi_handle_t handle,
118                                              const char *env_var,
119                                              u16 **load_options)
120 {
121         const char *env = env_get(env_var);
122         size_t size;
123         u16 *pos;
124         efi_status_t ret;
125
126         *load_options = NULL;
127         if (!env)
128                 return EFI_SUCCESS;
129         size = sizeof(u16) * (utf8_utf16_strlen(env) + 1);
130         pos = calloc(size, 1);
131         if (!pos)
132                 return EFI_OUT_OF_RESOURCES;
133         *load_options = pos;
134         utf8_utf16_strcpy(&pos, env);
135         ret = efi_set_load_options(handle, size, *load_options);
136         if (ret != EFI_SUCCESS) {
137                 free(*load_options);
138                 *load_options = NULL;
139         }
140         return ret;
141 }
142
143 #if !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
144
145 /**
146  * copy_fdt() - Copy the device tree to a new location available to EFI
147  *
148  * The FDT is copied to a suitable location within the EFI memory map.
149  * Additional 12 KiB are added to the space in case the device tree needs to be
150  * expanded later with fdt_open_into().
151  *
152  * @fdtp:       On entry a pointer to the flattened device tree.
153  *              On exit a pointer to the copy of the flattened device tree.
154  *              FDT start
155  * Return:      status code
156  */
157 static efi_status_t copy_fdt(void **fdtp)
158 {
159         unsigned long fdt_ram_start = -1L, fdt_pages;
160         efi_status_t ret = 0;
161         void *fdt, *new_fdt;
162         u64 new_fdt_addr;
163         uint fdt_size;
164         int i;
165
166         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
167                 u64 ram_start = gd->bd->bi_dram[i].start;
168                 u64 ram_size = gd->bd->bi_dram[i].size;
169
170                 if (!ram_size)
171                         continue;
172
173                 if (ram_start < fdt_ram_start)
174                         fdt_ram_start = ram_start;
175         }
176
177         /*
178          * Give us at least 12 KiB of breathing room in case the device tree
179          * needs to be expanded later.
180          */
181         fdt = *fdtp;
182         fdt_pages = efi_size_in_pages(fdt_totalsize(fdt) + 0x3000);
183         fdt_size = fdt_pages << EFI_PAGE_SHIFT;
184
185         /*
186          * Safe fdt location is at 127 MiB.
187          * On the sandbox convert from the sandbox address space.
188          */
189         new_fdt_addr = (uintptr_t)map_sysmem(fdt_ram_start + 0x7f00000 +
190                                              fdt_size, 0);
191         ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
192                                  EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
193                                  &new_fdt_addr);
194         if (ret != EFI_SUCCESS) {
195                 /* If we can't put it there, put it somewhere */
196                 new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
197                 ret = efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,
198                                          EFI_ACPI_RECLAIM_MEMORY, fdt_pages,
199                                          &new_fdt_addr);
200                 if (ret != EFI_SUCCESS) {
201                         log_err("ERROR: Failed to reserve space for FDT\n");
202                         goto done;
203                 }
204         }
205         new_fdt = (void *)(uintptr_t)new_fdt_addr;
206         memcpy(new_fdt, fdt, fdt_totalsize(fdt));
207         fdt_set_totalsize(new_fdt, fdt_size);
208
209         *fdtp = (void *)(uintptr_t)new_fdt_addr;
210 done:
211         return ret;
212 }
213
214 /**
215  * efi_reserve_memory() - add reserved memory to memory map
216  *
217  * @addr:       start address of the reserved memory range
218  * @size:       size of the reserved memory range
219  * @nomap:      indicates that the memory range shall not be accessed by the
220  *              UEFI payload
221  */
222 static void efi_reserve_memory(u64 addr, u64 size, bool nomap)
223 {
224         int type;
225         efi_uintn_t ret;
226
227         /* Convert from sandbox address space. */
228         addr = (uintptr_t)map_sysmem(addr, 0);
229
230         if (nomap)
231                 type = EFI_RESERVED_MEMORY_TYPE;
232         else
233                 type = EFI_BOOT_SERVICES_DATA;
234
235         ret = efi_add_memory_map(addr, size, type);
236         if (ret != EFI_SUCCESS)
237                 log_err("Reserved memory mapping failed addr %llx size %llx\n",
238                         addr, size);
239 }
240
241 /**
242  * efi_carve_out_dt_rsv() - Carve out DT reserved memory ranges
243  *
244  * The mem_rsv entries of the FDT are added to the memory map. Any failures are
245  * ignored because this is not critical and we would rather continue to try to
246  * boot.
247  *
248  * @fdt: Pointer to device tree
249  */
250 static void efi_carve_out_dt_rsv(void *fdt)
251 {
252         int nr_rsv, i;
253         u64 addr, size;
254         int nodeoffset, subnode;
255
256         nr_rsv = fdt_num_mem_rsv(fdt);
257
258         /* Look for an existing entry and add it to the efi mem map. */
259         for (i = 0; i < nr_rsv; i++) {
260                 if (fdt_get_mem_rsv(fdt, i, &addr, &size) != 0)
261                         continue;
262                 efi_reserve_memory(addr, size, false);
263         }
264
265         /* process reserved-memory */
266         nodeoffset = fdt_subnode_offset(fdt, 0, "reserved-memory");
267         if (nodeoffset >= 0) {
268                 subnode = fdt_first_subnode(fdt, nodeoffset);
269                 while (subnode >= 0) {
270                         fdt_addr_t fdt_addr;
271                         fdt_size_t fdt_size;
272
273                         /* check if this subnode has a reg property */
274                         fdt_addr = fdtdec_get_addr_size_auto_parent(
275                                                 fdt, nodeoffset, subnode,
276                                                 "reg", 0, &fdt_size, false);
277                         /*
278                          * The /reserved-memory node may have children with
279                          * a size instead of a reg property.
280                          */
281                         if (fdt_addr != FDT_ADDR_T_NONE &&
282                             fdtdec_get_is_enabled(fdt, subnode)) {
283                                 bool nomap;
284
285                                 nomap = !!fdt_getprop(fdt, subnode, "no-map",
286                                                       NULL);
287                                 efi_reserve_memory(fdt_addr, fdt_size, nomap);
288                         }
289                         subnode = fdt_next_subnode(fdt, subnode);
290                 }
291         }
292 }
293
294 /**
295  * get_config_table() - get configuration table
296  *
297  * @guid:       GUID of the configuration table
298  * Return:      pointer to configuration table or NULL
299  */
300 static void *get_config_table(const efi_guid_t *guid)
301 {
302         size_t i;
303
304         for (i = 0; i < systab.nr_tables; i++) {
305                 if (!guidcmp(guid, &systab.tables[i].guid))
306                         return systab.tables[i].table;
307         }
308         return NULL;
309 }
310
311 #endif /* !CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE) */
312
313 /**
314  * efi_install_fdt() - install device tree
315  *
316  * If fdt is not EFI_FDT_USE_INTERNAL, the device tree located at that memory
317  * address will will be installed as configuration table, otherwise the device
318  * tree located at the address indicated by environment variable fdt_addr or as
319  * fallback fdtcontroladdr will be used.
320  *
321  * On architectures using ACPI tables device trees shall not be installed as
322  * configuration table.
323  *
324  * @fdt:        address of device tree or EFI_FDT_USE_INTERNAL to use the
325  *              the hardware device tree as indicated by environment variable
326  *              fdt_addr or as fallback the internal device tree as indicated by
327  *              the environment variable fdtcontroladdr
328  * Return:      status code
329  */
330 efi_status_t efi_install_fdt(void *fdt)
331 {
332         /*
333          * The EBBR spec requires that we have either an FDT or an ACPI table
334          * but not both.
335          */
336 #if CONFIG_IS_ENABLED(GENERATE_ACPI_TABLE)
337         if (fdt) {
338                 log_err("ERROR: can't have ACPI table and device tree.\n");
339                 return EFI_LOAD_ERROR;
340         }
341 #else
342         bootm_headers_t img = { 0 };
343         efi_status_t ret;
344
345         if (fdt == EFI_FDT_USE_INTERNAL) {
346                 const char *fdt_opt;
347                 uintptr_t fdt_addr;
348
349                 /* Look for device tree that is already installed */
350                 if (get_config_table(&efi_guid_fdt))
351                         return EFI_SUCCESS;
352                 /* Check if there is a hardware device tree */
353                 fdt_opt = env_get("fdt_addr");
354                 /* Use our own device tree as fallback */
355                 if (!fdt_opt) {
356                         fdt_opt = env_get("fdtcontroladdr");
357                         if (!fdt_opt) {
358                                 log_err("ERROR: need device tree\n");
359                                 return EFI_NOT_FOUND;
360                         }
361                 }
362                 fdt_addr = simple_strtoul(fdt_opt, NULL, 16);
363                 if (!fdt_addr) {
364                         log_err("ERROR: invalid $fdt_addr or $fdtcontroladdr\n");
365                         return EFI_LOAD_ERROR;
366                 }
367                 fdt = map_sysmem(fdt_addr, 0);
368         }
369
370         /* Install device tree */
371         if (fdt_check_header(fdt)) {
372                 log_err("ERROR: invalid device tree\n");
373                 return EFI_LOAD_ERROR;
374         }
375
376         /* Prepare device tree for payload */
377         ret = copy_fdt(&fdt);
378         if (ret) {
379                 log_err("ERROR: out of memory\n");
380                 return EFI_OUT_OF_RESOURCES;
381         }
382
383         if (image_setup_libfdt(&img, fdt, 0, NULL)) {
384                 log_err("ERROR: failed to process device tree\n");
385                 return EFI_LOAD_ERROR;
386         }
387
388         /* Create memory reservations as indicated by the device tree */
389         efi_carve_out_dt_rsv(fdt);
390
391         /* Install device tree as UEFI table */
392         ret = efi_install_configuration_table(&efi_guid_fdt, fdt);
393         if (ret != EFI_SUCCESS) {
394                 log_err("ERROR: failed to install device tree\n");
395                 return ret;
396         }
397 #endif /* GENERATE_ACPI_TABLE */
398
399         return EFI_SUCCESS;
400 }
401
402 /**
403  * do_bootefi_exec() - execute EFI binary
404  *
405  * The image indicated by @handle is started. When it returns the allocated
406  * memory for the @load_options is freed.
407  *
408  * @handle:             handle of loaded image
409  * @load_options:       load options
410  * Return:              status code
411  *
412  * Load the EFI binary into a newly assigned memory unwinding the relocation
413  * information, install the loaded image protocol, and call the binary.
414  */
415 static efi_status_t do_bootefi_exec(efi_handle_t handle, void *load_options)
416 {
417         efi_status_t ret;
418         efi_uintn_t exit_data_size = 0;
419         u16 *exit_data = NULL;
420
421         /* Call our payload! */
422         ret = EFI_CALL(efi_start_image(handle, &exit_data_size, &exit_data));
423         if (ret != EFI_SUCCESS) {
424                 log_err("## Application failed, r = %lu\n",
425                         ret & ~EFI_ERROR_MASK);
426                 if (exit_data) {
427                         log_err("## %ls\n", exit_data);
428                         efi_free_pool(exit_data);
429                 }
430         }
431
432         efi_restore_gd();
433
434         free(load_options);
435
436         return ret;
437 }
438
439 /**
440  * do_efibootmgr() - execute EFI boot manager
441  *
442  * Return:      status code
443  */
444 static int do_efibootmgr(void)
445 {
446         efi_handle_t handle;
447         efi_status_t ret;
448         void *load_options;
449
450         ret = efi_bootmgr_load(&handle, &load_options);
451         if (ret != EFI_SUCCESS) {
452                 log_notice("EFI boot manager: Cannot load any image\n");
453                 return CMD_RET_FAILURE;
454         }
455
456         ret = do_bootefi_exec(handle, load_options);
457
458         if (ret != EFI_SUCCESS)
459                 return CMD_RET_FAILURE;
460
461         return CMD_RET_SUCCESS;
462 }
463
464 /**
465  * do_bootefi_image() - execute EFI binary
466  *
467  * Set up memory image for the binary to be loaded, prepare device path, and
468  * then call do_bootefi_exec() to execute it.
469  *
470  * @image_opt:  string of image start address
471  * Return:      status code
472  */
473 static int do_bootefi_image(const char *image_opt)
474 {
475         void *image_buf;
476         unsigned long addr, size;
477         efi_status_t ret;
478
479 #ifdef CONFIG_CMD_BOOTEFI_HELLO
480         if (!strcmp(image_opt, "hello")) {
481                 image_buf = __efi_helloworld_begin;
482                 size = __efi_helloworld_end - __efi_helloworld_begin;
483                 efi_clear_bootdev();
484         } else
485 #endif
486         {
487                 addr = strtoul(image_opt, NULL, 16);
488                 /* Check that a numeric value was passed */
489                 if (!addr)
490                         return CMD_RET_USAGE;
491
492                 image_buf = map_sysmem(addr, 0);
493
494                 if (image_buf != image_addr) {
495                         log_err("No UEFI binary known at %s\n", image_opt);
496                         return CMD_RET_FAILURE;
497                 }
498                 size = image_size;
499         }
500         ret = efi_run_image(image_buf, size);
501
502         if (ret != EFI_SUCCESS)
503                 return CMD_RET_FAILURE;
504
505         return CMD_RET_SUCCESS;
506 }
507
508 /**
509  * efi_run_image() - run loaded UEFI image
510  *
511  * @source_buffer:      memory address of the UEFI image
512  * @source_size:        size of the UEFI image
513  * Return:              status code
514  */
515 efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size)
516 {
517         efi_handle_t mem_handle = NULL, handle;
518         struct efi_device_path *file_path = NULL;
519         struct efi_device_path *msg_path;
520         efi_status_t ret;
521         u16 *load_options;
522
523         if (!bootefi_device_path || !bootefi_image_path) {
524                 /*
525                  * Special case for efi payload not loaded from disk,
526                  * such as 'bootefi hello' or for example payload
527                  * loaded directly into memory via JTAG, etc:
528                  */
529                 file_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
530                                             (uintptr_t)source_buffer,
531                                             source_size);
532                 /*
533                  * Make sure that device for device_path exist
534                  * in load_image(). Otherwise, shell and grub will fail.
535                  */
536                 ret = efi_create_handle(&mem_handle);
537                 if (ret != EFI_SUCCESS)
538                         goto out;
539
540                 ret = efi_add_protocol(mem_handle, &efi_guid_device_path,
541                                        file_path);
542                 if (ret != EFI_SUCCESS)
543                         goto out;
544                 msg_path = file_path;
545         } else {
546                 file_path = efi_dp_append(bootefi_device_path,
547                                           bootefi_image_path);
548                 msg_path = bootefi_image_path;
549         }
550
551         log_info("Booting %pD\n", msg_path);
552
553         ret = EFI_CALL(efi_load_image(false, efi_root, file_path, source_buffer,
554                                       source_size, &handle));
555         if (ret != EFI_SUCCESS) {
556                 log_err("Loading image failed\n");
557                 goto out;
558         }
559
560         /* Transfer environment variable as load options */
561         ret = efi_env_set_load_options(handle, "bootargs", &load_options);
562         if (ret != EFI_SUCCESS)
563                 goto out;
564
565         ret = do_bootefi_exec(handle, load_options);
566
567 out:
568         efi_delete_handle(mem_handle);
569         efi_free_pool(file_path);
570         return ret;
571 }
572
573 #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
574 static efi_status_t bootefi_run_prepare(const char *load_options_path,
575                 struct efi_device_path *device_path,
576                 struct efi_device_path *image_path,
577                 struct efi_loaded_image_obj **image_objp,
578                 struct efi_loaded_image **loaded_image_infop)
579 {
580         efi_status_t ret;
581         u16 *load_options;
582
583         ret = efi_setup_loaded_image(device_path, image_path, image_objp,
584                                      loaded_image_infop);
585         if (ret != EFI_SUCCESS)
586                 return ret;
587
588         /* Transfer environment variable as load options */
589         return efi_env_set_load_options((efi_handle_t)*image_objp,
590                                         load_options_path,
591                                         &load_options);
592 }
593
594 /**
595  * bootefi_test_prepare() - prepare to run an EFI test
596  *
597  * Prepare to run a test as if it were provided by a loaded image.
598  *
599  * @image_objp:         pointer to be set to the loaded image handle
600  * @loaded_image_infop: pointer to be set to the loaded image protocol
601  * @path:               dummy file path used to construct the device path
602  *                      set in the loaded image protocol
603  * @load_options_path:  name of a U-Boot environment variable. Its value is
604  *                      set as load options in the loaded image protocol.
605  * Return:              status code
606  */
607 static efi_status_t bootefi_test_prepare
608                 (struct efi_loaded_image_obj **image_objp,
609                  struct efi_loaded_image **loaded_image_infop, const char *path,
610                  const char *load_options_path)
611 {
612         efi_status_t ret;
613
614         /* Construct a dummy device path */
615         bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0);
616         if (!bootefi_device_path)
617                 return EFI_OUT_OF_RESOURCES;
618
619         bootefi_image_path = efi_dp_from_file(NULL, 0, path);
620         if (!bootefi_image_path) {
621                 ret = EFI_OUT_OF_RESOURCES;
622                 goto failure;
623         }
624
625         ret = bootefi_run_prepare(load_options_path, bootefi_device_path,
626                                   bootefi_image_path, image_objp,
627                                   loaded_image_infop);
628         if (ret == EFI_SUCCESS)
629                 return ret;
630
631 failure:
632         efi_clear_bootdev();
633         return ret;
634 }
635
636 /**
637  * bootefi_run_finish() - finish up after running an EFI test
638  *
639  * @loaded_image_info: Pointer to a struct which holds the loaded image info
640  * @image_obj: Pointer to a struct which holds the loaded image object
641  */
642 static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj,
643                                struct efi_loaded_image *loaded_image_info)
644 {
645         efi_restore_gd();
646         free(loaded_image_info->load_options);
647         efi_delete_handle(&image_obj->header);
648 }
649
650 /**
651  * do_efi_selftest() - execute EFI selftest
652  *
653  * Return:      status code
654  */
655 static int do_efi_selftest(void)
656 {
657         struct efi_loaded_image_obj *image_obj;
658         struct efi_loaded_image *loaded_image_info;
659         efi_status_t ret;
660
661         ret = bootefi_test_prepare(&image_obj, &loaded_image_info,
662                                    "\\selftest", "efi_selftest");
663         if (ret != EFI_SUCCESS)
664                 return CMD_RET_FAILURE;
665
666         /* Execute the test */
667         ret = EFI_CALL(efi_selftest(&image_obj->header, &systab));
668         bootefi_run_finish(image_obj, loaded_image_info);
669
670         return ret != EFI_SUCCESS;
671 }
672 #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */
673
674 /**
675  * do_bootefi() - execute `bootefi` command
676  *
677  * @cmdtp:      table entry describing command
678  * @flag:       bitmap indicating how the command was invoked
679  * @argc:       number of arguments
680  * @argv:       command line arguments
681  * Return:      status code
682  */
683 static int do_bootefi(struct cmd_tbl *cmdtp, int flag, int argc,
684                       char *const argv[])
685 {
686         efi_status_t ret;
687         void *fdt;
688
689         if (argc < 2)
690                 return CMD_RET_USAGE;
691
692         /* Initialize EFI drivers */
693         ret = efi_init_obj_list();
694         if (ret != EFI_SUCCESS) {
695                 log_err("Error: Cannot initialize UEFI sub-system, r = %lu\n",
696                         ret & ~EFI_ERROR_MASK);
697                 return CMD_RET_FAILURE;
698         }
699
700         if (argc > 2) {
701                 uintptr_t fdt_addr;
702
703                 fdt_addr = simple_strtoul(argv[2], NULL, 16);
704                 fdt = map_sysmem(fdt_addr, 0);
705         } else {
706                 fdt = EFI_FDT_USE_INTERNAL;
707         }
708         ret = efi_install_fdt(fdt);
709         if (ret == EFI_INVALID_PARAMETER)
710                 return CMD_RET_USAGE;
711         else if (ret != EFI_SUCCESS)
712                 return CMD_RET_FAILURE;
713
714         if (!strcmp(argv[1], "bootmgr"))
715                 return do_efibootmgr();
716 #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
717         else if (!strcmp(argv[1], "selftest"))
718                 return do_efi_selftest();
719 #endif
720
721         return do_bootefi_image(argv[1]);
722 }
723
724 #ifdef CONFIG_SYS_LONGHELP
725 static char bootefi_help_text[] =
726         "<image address> [fdt address]\n"
727         "  - boot EFI payload stored at address <image address>.\n"
728         "    If specified, the device tree located at <fdt address> gets\n"
729         "    exposed as EFI configuration table.\n"
730 #ifdef CONFIG_CMD_BOOTEFI_HELLO
731         "bootefi hello\n"
732         "  - boot a sample Hello World application stored within U-Boot\n"
733 #endif
734 #ifdef CONFIG_CMD_BOOTEFI_SELFTEST
735         "bootefi selftest [fdt address]\n"
736         "  - boot an EFI selftest application stored within U-Boot\n"
737         "    Use environment variable efi_selftest to select a single test.\n"
738         "    Use 'setenv efi_selftest list' to enumerate all tests.\n"
739 #endif
740         "bootefi bootmgr [fdt address]\n"
741         "  - load and boot EFI payload based on BootOrder/BootXXXX variables.\n"
742         "\n"
743         "    If specified, the device tree located at <fdt address> gets\n"
744         "    exposed as EFI configuration table.\n";
745 #endif
746
747 U_BOOT_CMD(
748         bootefi, 3, 0, do_bootefi,
749         "Boots an EFI payload from memory",
750         bootefi_help_text
751 );