bootefi.c 17 KB

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