bootefi.c 18 KB

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