xref: /openbmc/u-boot/cmd/bootefi.c (revision cc5b7081)
1b9939336SAlexander Graf /*
2b9939336SAlexander Graf  *  EFI application loader
3b9939336SAlexander Graf  *
4b9939336SAlexander Graf  *  Copyright (c) 2016 Alexander Graf
5b9939336SAlexander Graf  *
6b9939336SAlexander Graf  *  SPDX-License-Identifier:     GPL-2.0+
7b9939336SAlexander Graf  */
8b9939336SAlexander Graf 
9b9939336SAlexander Graf #include <common.h>
10b9939336SAlexander Graf #include <command.h>
119d922450SSimon Glass #include <dm.h>
12b9939336SAlexander Graf #include <efi_loader.h>
13b9939336SAlexander Graf #include <errno.h>
14b9939336SAlexander Graf #include <libfdt.h>
15b9939336SAlexander Graf #include <libfdt_env.h>
16ad0c1a3dSAlexander Graf #include <memalign.h>
170d9d501fSAlexander Graf #include <asm/global_data.h>
18e275458cSSimon Glass #include <asm-generic/sections.h>
19e275458cSSimon Glass #include <linux/linkage.h>
200d9d501fSAlexander Graf 
210d9d501fSAlexander Graf DECLARE_GLOBAL_DATA_PTR;
22b9939336SAlexander Graf 
23b9939336SAlexander Graf /*
24b9939336SAlexander Graf  * When booting using the "bootefi" command, we don't know which
25b9939336SAlexander Graf  * physical device the file came from. So we create a pseudo-device
26b9939336SAlexander Graf  * called "bootefi" with the device path /bootefi.
27b9939336SAlexander Graf  *
28b9939336SAlexander Graf  * In addition to the originating device we also declare the file path
29b9939336SAlexander Graf  * of "bootefi" based loads to be /bootefi.
30b9939336SAlexander Graf  */
310f4060ebSAlexander Graf static struct efi_device_path_file_path bootefi_image_path[] = {
32b9939336SAlexander Graf 	{
33b9939336SAlexander Graf 		.dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE,
34b9939336SAlexander Graf 		.dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH,
350f4060ebSAlexander Graf 		.dp.length = sizeof(bootefi_image_path[0]),
36b9939336SAlexander Graf 		.str = { 'b','o','o','t','e','f','i' },
37b9939336SAlexander Graf 	}, {
38b9939336SAlexander Graf 		.dp.type = DEVICE_PATH_TYPE_END,
39b9939336SAlexander Graf 		.dp.sub_type = DEVICE_PATH_SUB_TYPE_END,
400f4060ebSAlexander Graf 		.dp.length = sizeof(bootefi_image_path[0]),
41b9939336SAlexander Graf 	}
42b9939336SAlexander Graf };
43b9939336SAlexander Graf 
44c07ad7c0SAlexander Graf static struct efi_device_path_file_path bootefi_device_path[] = {
45c07ad7c0SAlexander Graf 	{
46c07ad7c0SAlexander Graf 		.dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE,
47c07ad7c0SAlexander Graf 		.dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH,
48c07ad7c0SAlexander Graf 		.dp.length = sizeof(bootefi_image_path[0]),
49c07ad7c0SAlexander Graf 		.str = { 'b','o','o','t','e','f','i' },
50c07ad7c0SAlexander Graf 	}, {
51c07ad7c0SAlexander Graf 		.dp.type = DEVICE_PATH_TYPE_END,
52c07ad7c0SAlexander Graf 		.dp.sub_type = DEVICE_PATH_SUB_TYPE_END,
53c07ad7c0SAlexander Graf 		.dp.length = sizeof(bootefi_image_path[0]),
54c07ad7c0SAlexander Graf 	}
55c07ad7c0SAlexander Graf };
56c07ad7c0SAlexander Graf 
57b9939336SAlexander Graf /* The EFI loaded_image interface for the image executed via "bootefi" */
58b9939336SAlexander Graf static struct efi_loaded_image loaded_image_info = {
59c07ad7c0SAlexander Graf 	.device_handle = bootefi_device_path,
600f4060ebSAlexander Graf 	.file_path = bootefi_image_path,
61b9939336SAlexander Graf };
62b9939336SAlexander Graf 
63b9939336SAlexander Graf /* The EFI object struct for the image executed via "bootefi" */
64b9939336SAlexander Graf static struct efi_object loaded_image_info_obj = {
65b9939336SAlexander Graf 	.handle = &loaded_image_info,
66b9939336SAlexander Graf 	.protocols = {
67b9939336SAlexander Graf 		{
68b9939336SAlexander Graf 			/*
69b9939336SAlexander Graf 			 * When asking for the loaded_image interface, just
70b9939336SAlexander Graf 			 * return handle which points to loaded_image_info
71b9939336SAlexander Graf 			 */
72b9939336SAlexander Graf 			.guid = &efi_guid_loaded_image,
73b5349f74Sxypron.glpk@gmx.de 			.protocol_interface = &loaded_image_info,
74b9939336SAlexander Graf 		},
75b9939336SAlexander Graf 		{
76b9939336SAlexander Graf 			/*
77b9939336SAlexander Graf 			 * When asking for the device path interface, return
78c07ad7c0SAlexander Graf 			 * bootefi_device_path
79b9939336SAlexander Graf 			 */
80b9939336SAlexander Graf 			.guid = &efi_guid_device_path,
81b5349f74Sxypron.glpk@gmx.de 			.protocol_interface = bootefi_device_path,
82b9939336SAlexander Graf 		},
8388adae5eSxypron.glpk@gmx.de 		{
8488adae5eSxypron.glpk@gmx.de 			.guid = &efi_guid_console_control,
8588adae5eSxypron.glpk@gmx.de 			.protocol_interface = (void *) &efi_console_control
8688adae5eSxypron.glpk@gmx.de 		},
87*cc5b7081Sxypron.glpk@gmx.de 		{
88*cc5b7081Sxypron.glpk@gmx.de 			.guid = &efi_guid_device_path_to_text_protocol,
89*cc5b7081Sxypron.glpk@gmx.de 			.protocol_interface = (void *) &efi_device_path_to_text
90*cc5b7081Sxypron.glpk@gmx.de 		},
91b9939336SAlexander Graf 	},
92b9939336SAlexander Graf };
93b9939336SAlexander Graf 
94b9939336SAlexander Graf /* The EFI object struct for the device the "bootefi" image was loaded from */
95b9939336SAlexander Graf static struct efi_object bootefi_device_obj = {
96c07ad7c0SAlexander Graf 	.handle = bootefi_device_path,
97b9939336SAlexander Graf 	.protocols = {
98b9939336SAlexander Graf 		{
99b9939336SAlexander Graf 			/* When asking for the device path interface, return
100c07ad7c0SAlexander Graf 			 * bootefi_device_path */
101b9939336SAlexander Graf 			.guid = &efi_guid_device_path,
102b5349f74Sxypron.glpk@gmx.de 			.protocol_interface = bootefi_device_path
103b9939336SAlexander Graf 		}
104b9939336SAlexander Graf 	},
105b9939336SAlexander Graf };
106b9939336SAlexander Graf 
1070d9d501fSAlexander Graf static void *copy_fdt(void *fdt)
1080d9d501fSAlexander Graf {
1090d9d501fSAlexander Graf 	u64 fdt_size = fdt_totalsize(fdt);
110ad0c1a3dSAlexander Graf 	unsigned long fdt_ram_start = -1L, fdt_pages;
111ad0c1a3dSAlexander Graf 	u64 new_fdt_addr;
1120d9d501fSAlexander Graf 	void *new_fdt;
113ad0c1a3dSAlexander Graf 	int i;
1140d9d501fSAlexander Graf 
115ad0c1a3dSAlexander Graf         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
116ad0c1a3dSAlexander Graf                 u64 ram_start = gd->bd->bi_dram[i].start;
117ad0c1a3dSAlexander Graf                 u64 ram_size = gd->bd->bi_dram[i].size;
1180d9d501fSAlexander Graf 
119ad0c1a3dSAlexander Graf 		if (!ram_size)
120ad0c1a3dSAlexander Graf 			continue;
121ad0c1a3dSAlexander Graf 
122ad0c1a3dSAlexander Graf 		if (ram_start < fdt_ram_start)
123ad0c1a3dSAlexander Graf 			fdt_ram_start = ram_start;
124ad0c1a3dSAlexander Graf 	}
125ad0c1a3dSAlexander Graf 
126ad0c1a3dSAlexander Graf 	/* Give us at least 4kb breathing room */
127ad0c1a3dSAlexander Graf 	fdt_size = ALIGN(fdt_size + 4096, 4096);
128ad0c1a3dSAlexander Graf 	fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
129ad0c1a3dSAlexander Graf 
130ad0c1a3dSAlexander Graf 	/* Safe fdt location is at 128MB */
131ad0c1a3dSAlexander Graf 	new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size;
132ad0c1a3dSAlexander Graf 	if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
133ad0c1a3dSAlexander Graf 			       &new_fdt_addr) != EFI_SUCCESS) {
134ad0c1a3dSAlexander Graf 		/* If we can't put it there, put it somewhere */
135ad0c1a3dSAlexander Graf 		new_fdt_addr = (ulong)memalign(4096, fdt_size);
13685a6e9b3SAlexander Graf 		if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
13785a6e9b3SAlexander Graf 				       &new_fdt_addr) != EFI_SUCCESS) {
13885a6e9b3SAlexander Graf 			printf("ERROR: Failed to reserve space for FDT\n");
13985a6e9b3SAlexander Graf 			return NULL;
140ad0c1a3dSAlexander Graf 		}
14185a6e9b3SAlexander Graf 	}
14285a6e9b3SAlexander Graf 
143ad0c1a3dSAlexander Graf 	new_fdt = (void*)(ulong)new_fdt_addr;
1440d9d501fSAlexander Graf 	memcpy(new_fdt, fdt, fdt_totalsize(fdt));
1450d9d501fSAlexander Graf 	fdt_set_totalsize(new_fdt, fdt_size);
1460d9d501fSAlexander Graf 
1470d9d501fSAlexander Graf 	return new_fdt;
1480d9d501fSAlexander Graf }
1490d9d501fSAlexander Graf 
150ec6617c3SAlison Wang #ifdef CONFIG_ARM64
151ec6617c3SAlison Wang static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle,
152ec6617c3SAlison Wang 		struct efi_system_table *st), void *image_handle,
153ec6617c3SAlison Wang 		struct efi_system_table *st)
154ec6617c3SAlison Wang {
155ec6617c3SAlison Wang 	/* Enable caches again */
156ec6617c3SAlison Wang 	dcache_enable();
157ec6617c3SAlison Wang 
158ec6617c3SAlison Wang 	return entry(image_handle, st);
159ec6617c3SAlison Wang }
160ec6617c3SAlison Wang #endif
161ec6617c3SAlison Wang 
162b9939336SAlexander Graf /*
163b9939336SAlexander Graf  * Load an EFI payload into a newly allocated piece of memory, register all
164b9939336SAlexander Graf  * EFI objects it would want to access and jump to it.
165b9939336SAlexander Graf  */
1661c39809bSAlexander Graf static unsigned long do_bootefi_exec(void *efi, void *fdt)
167b9939336SAlexander Graf {
168e275458cSSimon Glass 	ulong (*entry)(void *image_handle, struct efi_system_table *st)
169e275458cSSimon Glass 		asmlinkage;
170b9939336SAlexander Graf 	ulong fdt_pages, fdt_size, fdt_start, fdt_end;
171dea2174dSAlexander Graf 	bootm_headers_t img = { 0 };
172b9939336SAlexander Graf 
173b9939336SAlexander Graf 	/*
174b9939336SAlexander Graf 	 * gd lives in a fixed register which may get clobbered while we execute
175b9939336SAlexander Graf 	 * the payload. So save it here and restore it on every callback entry
176b9939336SAlexander Graf 	 */
177b9939336SAlexander Graf 	efi_save_gd();
178b9939336SAlexander Graf 
1791c39809bSAlexander Graf 	if (fdt && !fdt_check_header(fdt)) {
180dea2174dSAlexander Graf 		/* Prepare fdt for payload */
1810d9d501fSAlexander Graf 		fdt = copy_fdt(fdt);
1820d9d501fSAlexander Graf 
1830d9d501fSAlexander Graf 		if (image_setup_libfdt(&img, fdt, 0, NULL)) {
184dea2174dSAlexander Graf 			printf("ERROR: Failed to process device tree\n");
185dea2174dSAlexander Graf 			return -EINVAL;
186dea2174dSAlexander Graf 		}
187dea2174dSAlexander Graf 
188dea2174dSAlexander Graf 		/* Link to it in the efi tables */
189b9939336SAlexander Graf 		systab.tables[0].guid = EFI_FDT_GUID;
1900d9d501fSAlexander Graf 		systab.tables[0].table = fdt;
191b9939336SAlexander Graf 		systab.nr_tables = 1;
192b9939336SAlexander Graf 
193b9939336SAlexander Graf 		/* And reserve the space in the memory map */
1940d9d501fSAlexander Graf 		fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK;
1950d9d501fSAlexander Graf 		fdt_end = ((ulong)fdt) + fdt_totalsize(fdt);
196b9939336SAlexander Graf 		fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK;
197b9939336SAlexander Graf 		fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
198b9939336SAlexander Graf 		/* Give a bootloader the chance to modify the device tree */
199b9939336SAlexander Graf 		fdt_pages += 2;
200b9939336SAlexander Graf 		efi_add_memory_map(fdt_start, fdt_pages,
201b9939336SAlexander Graf 				   EFI_BOOT_SERVICES_DATA, true);
202b9939336SAlexander Graf 	} else {
2031c39809bSAlexander Graf 		printf("WARNING: Invalid device tree, expect boot to fail\n");
204b9939336SAlexander Graf 		systab.nr_tables = 0;
205b9939336SAlexander Graf 	}
206b9939336SAlexander Graf 
207b9939336SAlexander Graf 	/* Load the EFI payload */
208b9939336SAlexander Graf 	entry = efi_load_pe(efi, &loaded_image_info);
209b9939336SAlexander Graf 	if (!entry)
210b9939336SAlexander Graf 		return -ENOENT;
211b9939336SAlexander Graf 
212b9939336SAlexander Graf 	/* Initialize and populate EFI object list */
213b9939336SAlexander Graf 	INIT_LIST_HEAD(&efi_obj_list);
214b9939336SAlexander Graf 	list_add_tail(&loaded_image_info_obj.link, &efi_obj_list);
215b9939336SAlexander Graf 	list_add_tail(&bootefi_device_obj.link, &efi_obj_list);
216b9939336SAlexander Graf #ifdef CONFIG_PARTITIONS
217b9939336SAlexander Graf 	efi_disk_register();
218b9939336SAlexander Graf #endif
219be8d3241SAlexander Graf #ifdef CONFIG_LCD
220be8d3241SAlexander Graf 	efi_gop_register();
221be8d3241SAlexander Graf #endif
2220efe1bcfSAlexander Graf #ifdef CONFIG_NET
2230efe1bcfSAlexander Graf 	void *nethandle = loaded_image_info.device_handle;
2240efe1bcfSAlexander Graf 	efi_net_register(&nethandle);
2250efe1bcfSAlexander Graf 
2260efe1bcfSAlexander Graf 	if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6))
2270efe1bcfSAlexander Graf 		loaded_image_info.device_handle = nethandle;
2283fb97e26SAlexander Graf 	else
2293fb97e26SAlexander Graf 		loaded_image_info.device_handle = bootefi_device_path;
2300efe1bcfSAlexander Graf #endif
231e663b350SAlexander Graf #ifdef CONFIG_GENERATE_SMBIOS_TABLE
232e663b350SAlexander Graf 	efi_smbios_register();
233e663b350SAlexander Graf #endif
234b9939336SAlexander Graf 
23580a4800eSAlexander Graf 	/* Initialize EFI runtime services */
23680a4800eSAlexander Graf 	efi_reset_system_init();
23780a4800eSAlexander Graf 	efi_get_time_init();
23880a4800eSAlexander Graf 
239b9939336SAlexander Graf 	/* Call our payload! */
240edcef3baSAlexander Graf 	debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
241a86aeaf2SAlexander Graf 
242a86aeaf2SAlexander Graf 	if (setjmp(&loaded_image_info.exit_jmp)) {
243a86aeaf2SAlexander Graf 		efi_status_t status = loaded_image_info.exit_status;
244a86aeaf2SAlexander Graf 		return status == EFI_SUCCESS ? 0 : -EINVAL;
245a86aeaf2SAlexander Graf 	}
246a86aeaf2SAlexander Graf 
24769bd459dSAlexander Graf #ifdef CONFIG_ARM64
24869bd459dSAlexander Graf 	/* On AArch64 we need to make sure we call our payload in < EL3 */
24969bd459dSAlexander Graf 	if (current_el() == 3) {
25069bd459dSAlexander Graf 		smp_kick_all_cpus();
25169bd459dSAlexander Graf 		dcache_disable();	/* flush cache before switch to EL2 */
252ec6617c3SAlison Wang 
253ec6617c3SAlison Wang 		/* Move into EL2 and keep running there */
254ec6617c3SAlison Wang 		armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info,
2557c5e1febSAlison Wang 				    (ulong)&systab, 0, (ulong)efi_run_in_el2,
256ec6617c3SAlison Wang 				    ES_TO_AARCH64);
257ec6617c3SAlison Wang 
258ec6617c3SAlison Wang 		/* Should never reach here, efi exits with longjmp */
259ec6617c3SAlison Wang 		while (1) { }
26069bd459dSAlexander Graf 	}
26169bd459dSAlexander Graf #endif
26269bd459dSAlexander Graf 
263b9939336SAlexander Graf 	return entry(&loaded_image_info, &systab);
264b9939336SAlexander Graf }
265b9939336SAlexander Graf 
266b9939336SAlexander Graf 
267b9939336SAlexander Graf /* Interpreter command to boot an arbitrary EFI image from memory */
268b9939336SAlexander Graf static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
269b9939336SAlexander Graf {
2701c39809bSAlexander Graf 	char *saddr, *sfdt;
2711c39809bSAlexander Graf 	unsigned long addr, fdt_addr = 0;
272b9939336SAlexander Graf 	int r = 0;
273b9939336SAlexander Graf 
274b9939336SAlexander Graf 	if (argc < 2)
2753c1dcef6SBin Meng 		return CMD_RET_USAGE;
276c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
277c7ae3dfdSSimon Glass 	if (!strcmp(argv[1], "hello")) {
278c7ae3dfdSSimon Glass 		ulong size = __efi_hello_world_end - __efi_hello_world_begin;
279c7ae3dfdSSimon Glass 
280c7ae3dfdSSimon Glass 		addr = CONFIG_SYS_LOAD_ADDR;
281c7ae3dfdSSimon Glass 		memcpy((char *)addr, __efi_hello_world_begin, size);
282c7ae3dfdSSimon Glass 	} else
283c7ae3dfdSSimon Glass #endif
284c7ae3dfdSSimon Glass 	{
285b9939336SAlexander Graf 		saddr = argv[1];
286b9939336SAlexander Graf 
287b9939336SAlexander Graf 		addr = simple_strtoul(saddr, NULL, 16);
288b9939336SAlexander Graf 
2891c39809bSAlexander Graf 		if (argc > 2) {
2901c39809bSAlexander Graf 			sfdt = argv[2];
2911c39809bSAlexander Graf 			fdt_addr = simple_strtoul(sfdt, NULL, 16);
2921c39809bSAlexander Graf 		}
293c7ae3dfdSSimon Glass 	}
2941c39809bSAlexander Graf 
2955ee31bafSSimon Glass 	printf("## Starting EFI application at %08lx ...\n", addr);
2961c39809bSAlexander Graf 	r = do_bootefi_exec((void *)addr, (void*)fdt_addr);
297b9939336SAlexander Graf 	printf("## Application terminated, r = %d\n", r);
298b9939336SAlexander Graf 
299b9939336SAlexander Graf 	if (r != 0)
300b9939336SAlexander Graf 		r = 1;
301b9939336SAlexander Graf 
302b9939336SAlexander Graf 	return r;
303b9939336SAlexander Graf }
304b9939336SAlexander Graf 
305b9939336SAlexander Graf #ifdef CONFIG_SYS_LONGHELP
306b9939336SAlexander Graf static char bootefi_help_text[] =
3071c39809bSAlexander Graf 	"<image address> [fdt address]\n"
3081c39809bSAlexander Graf 	"  - boot EFI payload stored at address <image address>.\n"
3091c39809bSAlexander Graf 	"    If specified, the device tree located at <fdt address> gets\n"
310c7ae3dfdSSimon Glass 	"    exposed as EFI configuration table.\n"
311c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
312c7ae3dfdSSimon Glass 	"hello\n"
313c7ae3dfdSSimon Glass 	"  - boot a sample Hello World application stored within U-Boot"
314c7ae3dfdSSimon Glass #endif
315c7ae3dfdSSimon Glass 	;
316b9939336SAlexander Graf #endif
317b9939336SAlexander Graf 
318b9939336SAlexander Graf U_BOOT_CMD(
3191c39809bSAlexander Graf 	bootefi, 3, 0, do_bootefi,
32092dfd922SSergey Kubushyn 	"Boots an EFI payload from memory",
321b9939336SAlexander Graf 	bootefi_help_text
322b9939336SAlexander Graf );
3230f4060ebSAlexander Graf 
324c07ad7c0SAlexander Graf void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
3250f4060ebSAlexander Graf {
3268c3df0bfSAlexander Graf 	__maybe_unused struct blk_desc *desc;
327ecbe1a07SAlexander Graf 	char devname[32] = { 0 }; /* dp->str is u16[32] long */
3280f4060ebSAlexander Graf 	char *colon;
3290f4060ebSAlexander Graf 
3301acc0087SPatrick Delaunay #if defined(CONFIG_BLK) || CONFIG_IS_ENABLED(ISO_PARTITION)
331f9d334bdSAlexander Graf 	desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
332f9d334bdSAlexander Graf #endif
333f9d334bdSAlexander Graf 
334f9d334bdSAlexander Graf #ifdef CONFIG_BLK
335f9d334bdSAlexander Graf 	if (desc) {
336f9d334bdSAlexander Graf 		snprintf(devname, sizeof(devname), "%s", desc->bdev->name);
337f9d334bdSAlexander Graf 	} else
338f9d334bdSAlexander Graf #endif
339f9d334bdSAlexander Graf 
340f9d334bdSAlexander Graf 	{
3410f4060ebSAlexander Graf 		/* Assemble the condensed device name we use in efi_disk.c */
3420f4060ebSAlexander Graf 		snprintf(devname, sizeof(devname), "%s%s", dev, devnr);
343f9d334bdSAlexander Graf 	}
344f9d334bdSAlexander Graf 
3450f4060ebSAlexander Graf 	colon = strchr(devname, ':');
3468c3df0bfSAlexander Graf 
3471acc0087SPatrick Delaunay #if CONFIG_IS_ENABLED(ISO_PARTITION)
3488c3df0bfSAlexander Graf 	/* For ISOs we create partition block devices */
3498c3df0bfSAlexander Graf 	if (desc && (desc->type != DEV_TYPE_UNKNOWN) &&
3508c3df0bfSAlexander Graf 	    (desc->part_type == PART_TYPE_ISO)) {
3518c3df0bfSAlexander Graf 		if (!colon)
352f9d334bdSAlexander Graf 			snprintf(devname, sizeof(devname), "%s:1", devname);
353f9d334bdSAlexander Graf 
3548c3df0bfSAlexander Graf 		colon = NULL;
3558c3df0bfSAlexander Graf 	}
3568c3df0bfSAlexander Graf #endif
3578c3df0bfSAlexander Graf 
3580f4060ebSAlexander Graf 	if (colon)
3590f4060ebSAlexander Graf 		*colon = '\0';
3600f4060ebSAlexander Graf 
361c07ad7c0SAlexander Graf 	/* Patch bootefi_device_path to the target device */
362c07ad7c0SAlexander Graf 	memset(bootefi_device_path[0].str, 0, sizeof(bootefi_device_path[0].str));
363c07ad7c0SAlexander Graf 	ascii2unicode(bootefi_device_path[0].str, devname);
364c07ad7c0SAlexander Graf 
365c07ad7c0SAlexander Graf 	/* Patch bootefi_image_path to the target file path */
3660f4060ebSAlexander Graf 	memset(bootefi_image_path[0].str, 0, sizeof(bootefi_image_path[0].str));
36749271666SAlexander Graf 	if (strcmp(dev, "Net")) {
36849271666SAlexander Graf 		/* Add leading / to fs paths, because they're absolute */
36949271666SAlexander Graf 		snprintf(devname, sizeof(devname), "/%s", path);
37049271666SAlexander Graf 	} else {
371c07ad7c0SAlexander Graf 		snprintf(devname, sizeof(devname), "%s", path);
37249271666SAlexander Graf 	}
3730f4060ebSAlexander Graf 	ascii2unicode(bootefi_image_path[0].str, devname);
3740f4060ebSAlexander Graf }
375