bootefi.c 17 KB

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