bootefi.c 18 KB

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