xref: /rk3399_rockchip-uboot/cmd/bootefi.c (revision 88adae5ef057845f6bc69c63123df4332fe835b1)
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 		},
83*88adae5eSxypron.glpk@gmx.de 		{
84*88adae5eSxypron.glpk@gmx.de 			.guid = &efi_guid_console_control,
85*88adae5eSxypron.glpk@gmx.de 			.protocol_interface = (void *) &efi_console_control
86*88adae5eSxypron.glpk@gmx.de 		},
87b9939336SAlexander Graf 	},
88b9939336SAlexander Graf };
89b9939336SAlexander Graf 
90b9939336SAlexander Graf /* The EFI object struct for the device the "bootefi" image was loaded from */
91b9939336SAlexander Graf static struct efi_object bootefi_device_obj = {
92c07ad7c0SAlexander Graf 	.handle = bootefi_device_path,
93b9939336SAlexander Graf 	.protocols = {
94b9939336SAlexander Graf 		{
95b9939336SAlexander Graf 			/* When asking for the device path interface, return
96c07ad7c0SAlexander Graf 			 * bootefi_device_path */
97b9939336SAlexander Graf 			.guid = &efi_guid_device_path,
98b5349f74Sxypron.glpk@gmx.de 			.protocol_interface = bootefi_device_path
99b9939336SAlexander Graf 		}
100b9939336SAlexander Graf 	},
101b9939336SAlexander Graf };
102b9939336SAlexander Graf 
1030d9d501fSAlexander Graf static void *copy_fdt(void *fdt)
1040d9d501fSAlexander Graf {
1050d9d501fSAlexander Graf 	u64 fdt_size = fdt_totalsize(fdt);
106ad0c1a3dSAlexander Graf 	unsigned long fdt_ram_start = -1L, fdt_pages;
107ad0c1a3dSAlexander Graf 	u64 new_fdt_addr;
1080d9d501fSAlexander Graf 	void *new_fdt;
109ad0c1a3dSAlexander Graf 	int i;
1100d9d501fSAlexander Graf 
111ad0c1a3dSAlexander Graf         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
112ad0c1a3dSAlexander Graf                 u64 ram_start = gd->bd->bi_dram[i].start;
113ad0c1a3dSAlexander Graf                 u64 ram_size = gd->bd->bi_dram[i].size;
1140d9d501fSAlexander Graf 
115ad0c1a3dSAlexander Graf 		if (!ram_size)
116ad0c1a3dSAlexander Graf 			continue;
117ad0c1a3dSAlexander Graf 
118ad0c1a3dSAlexander Graf 		if (ram_start < fdt_ram_start)
119ad0c1a3dSAlexander Graf 			fdt_ram_start = ram_start;
120ad0c1a3dSAlexander Graf 	}
121ad0c1a3dSAlexander Graf 
122ad0c1a3dSAlexander Graf 	/* Give us at least 4kb breathing room */
123ad0c1a3dSAlexander Graf 	fdt_size = ALIGN(fdt_size + 4096, 4096);
124ad0c1a3dSAlexander Graf 	fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
125ad0c1a3dSAlexander Graf 
126ad0c1a3dSAlexander Graf 	/* Safe fdt location is at 128MB */
127ad0c1a3dSAlexander Graf 	new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size;
128ad0c1a3dSAlexander Graf 	if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
129ad0c1a3dSAlexander Graf 			       &new_fdt_addr) != EFI_SUCCESS) {
130ad0c1a3dSAlexander Graf 		/* If we can't put it there, put it somewhere */
131ad0c1a3dSAlexander Graf 		new_fdt_addr = (ulong)memalign(4096, fdt_size);
13285a6e9b3SAlexander Graf 		if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
13385a6e9b3SAlexander Graf 				       &new_fdt_addr) != EFI_SUCCESS) {
13485a6e9b3SAlexander Graf 			printf("ERROR: Failed to reserve space for FDT\n");
13585a6e9b3SAlexander Graf 			return NULL;
136ad0c1a3dSAlexander Graf 		}
13785a6e9b3SAlexander Graf 	}
13885a6e9b3SAlexander Graf 
139ad0c1a3dSAlexander Graf 	new_fdt = (void*)(ulong)new_fdt_addr;
1400d9d501fSAlexander Graf 	memcpy(new_fdt, fdt, fdt_totalsize(fdt));
1410d9d501fSAlexander Graf 	fdt_set_totalsize(new_fdt, fdt_size);
1420d9d501fSAlexander Graf 
1430d9d501fSAlexander Graf 	return new_fdt;
1440d9d501fSAlexander Graf }
1450d9d501fSAlexander Graf 
146ec6617c3SAlison Wang #ifdef CONFIG_ARM64
147ec6617c3SAlison Wang static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle,
148ec6617c3SAlison Wang 		struct efi_system_table *st), void *image_handle,
149ec6617c3SAlison Wang 		struct efi_system_table *st)
150ec6617c3SAlison Wang {
151ec6617c3SAlison Wang 	/* Enable caches again */
152ec6617c3SAlison Wang 	dcache_enable();
153ec6617c3SAlison Wang 
154ec6617c3SAlison Wang 	return entry(image_handle, st);
155ec6617c3SAlison Wang }
156ec6617c3SAlison Wang #endif
157ec6617c3SAlison Wang 
158b9939336SAlexander Graf /*
159b9939336SAlexander Graf  * Load an EFI payload into a newly allocated piece of memory, register all
160b9939336SAlexander Graf  * EFI objects it would want to access and jump to it.
161b9939336SAlexander Graf  */
1621c39809bSAlexander Graf static unsigned long do_bootefi_exec(void *efi, void *fdt)
163b9939336SAlexander Graf {
164e275458cSSimon Glass 	ulong (*entry)(void *image_handle, struct efi_system_table *st)
165e275458cSSimon Glass 		asmlinkage;
166b9939336SAlexander Graf 	ulong fdt_pages, fdt_size, fdt_start, fdt_end;
167dea2174dSAlexander Graf 	bootm_headers_t img = { 0 };
168b9939336SAlexander Graf 
169b9939336SAlexander Graf 	/*
170b9939336SAlexander Graf 	 * gd lives in a fixed register which may get clobbered while we execute
171b9939336SAlexander Graf 	 * the payload. So save it here and restore it on every callback entry
172b9939336SAlexander Graf 	 */
173b9939336SAlexander Graf 	efi_save_gd();
174b9939336SAlexander Graf 
1751c39809bSAlexander Graf 	if (fdt && !fdt_check_header(fdt)) {
176dea2174dSAlexander Graf 		/* Prepare fdt for payload */
1770d9d501fSAlexander Graf 		fdt = copy_fdt(fdt);
1780d9d501fSAlexander Graf 
1790d9d501fSAlexander Graf 		if (image_setup_libfdt(&img, fdt, 0, NULL)) {
180dea2174dSAlexander Graf 			printf("ERROR: Failed to process device tree\n");
181dea2174dSAlexander Graf 			return -EINVAL;
182dea2174dSAlexander Graf 		}
183dea2174dSAlexander Graf 
184dea2174dSAlexander Graf 		/* Link to it in the efi tables */
185b9939336SAlexander Graf 		systab.tables[0].guid = EFI_FDT_GUID;
1860d9d501fSAlexander Graf 		systab.tables[0].table = fdt;
187b9939336SAlexander Graf 		systab.nr_tables = 1;
188b9939336SAlexander Graf 
189b9939336SAlexander Graf 		/* And reserve the space in the memory map */
1900d9d501fSAlexander Graf 		fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK;
1910d9d501fSAlexander Graf 		fdt_end = ((ulong)fdt) + fdt_totalsize(fdt);
192b9939336SAlexander Graf 		fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK;
193b9939336SAlexander Graf 		fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
194b9939336SAlexander Graf 		/* Give a bootloader the chance to modify the device tree */
195b9939336SAlexander Graf 		fdt_pages += 2;
196b9939336SAlexander Graf 		efi_add_memory_map(fdt_start, fdt_pages,
197b9939336SAlexander Graf 				   EFI_BOOT_SERVICES_DATA, true);
198b9939336SAlexander Graf 	} else {
1991c39809bSAlexander Graf 		printf("WARNING: Invalid device tree, expect boot to fail\n");
200b9939336SAlexander Graf 		systab.nr_tables = 0;
201b9939336SAlexander Graf 	}
202b9939336SAlexander Graf 
203b9939336SAlexander Graf 	/* Load the EFI payload */
204b9939336SAlexander Graf 	entry = efi_load_pe(efi, &loaded_image_info);
205b9939336SAlexander Graf 	if (!entry)
206b9939336SAlexander Graf 		return -ENOENT;
207b9939336SAlexander Graf 
208b9939336SAlexander Graf 	/* Initialize and populate EFI object list */
209b9939336SAlexander Graf 	INIT_LIST_HEAD(&efi_obj_list);
210b9939336SAlexander Graf 	list_add_tail(&loaded_image_info_obj.link, &efi_obj_list);
211b9939336SAlexander Graf 	list_add_tail(&bootefi_device_obj.link, &efi_obj_list);
212b9939336SAlexander Graf #ifdef CONFIG_PARTITIONS
213b9939336SAlexander Graf 	efi_disk_register();
214b9939336SAlexander Graf #endif
215be8d3241SAlexander Graf #ifdef CONFIG_LCD
216be8d3241SAlexander Graf 	efi_gop_register();
217be8d3241SAlexander Graf #endif
2180efe1bcfSAlexander Graf #ifdef CONFIG_NET
2190efe1bcfSAlexander Graf 	void *nethandle = loaded_image_info.device_handle;
2200efe1bcfSAlexander Graf 	efi_net_register(&nethandle);
2210efe1bcfSAlexander Graf 
2220efe1bcfSAlexander Graf 	if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6))
2230efe1bcfSAlexander Graf 		loaded_image_info.device_handle = nethandle;
2243fb97e26SAlexander Graf 	else
2253fb97e26SAlexander Graf 		loaded_image_info.device_handle = bootefi_device_path;
2260efe1bcfSAlexander Graf #endif
227e663b350SAlexander Graf #ifdef CONFIG_GENERATE_SMBIOS_TABLE
228e663b350SAlexander Graf 	efi_smbios_register();
229e663b350SAlexander Graf #endif
230b9939336SAlexander Graf 
23180a4800eSAlexander Graf 	/* Initialize EFI runtime services */
23280a4800eSAlexander Graf 	efi_reset_system_init();
23380a4800eSAlexander Graf 	efi_get_time_init();
23480a4800eSAlexander Graf 
235b9939336SAlexander Graf 	/* Call our payload! */
236edcef3baSAlexander Graf 	debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
237a86aeaf2SAlexander Graf 
238a86aeaf2SAlexander Graf 	if (setjmp(&loaded_image_info.exit_jmp)) {
239a86aeaf2SAlexander Graf 		efi_status_t status = loaded_image_info.exit_status;
240a86aeaf2SAlexander Graf 		return status == EFI_SUCCESS ? 0 : -EINVAL;
241a86aeaf2SAlexander Graf 	}
242a86aeaf2SAlexander Graf 
24369bd459dSAlexander Graf #ifdef CONFIG_ARM64
24469bd459dSAlexander Graf 	/* On AArch64 we need to make sure we call our payload in < EL3 */
24569bd459dSAlexander Graf 	if (current_el() == 3) {
24669bd459dSAlexander Graf 		smp_kick_all_cpus();
24769bd459dSAlexander Graf 		dcache_disable();	/* flush cache before switch to EL2 */
248ec6617c3SAlison Wang 
249ec6617c3SAlison Wang 		/* Move into EL2 and keep running there */
250ec6617c3SAlison Wang 		armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info,
2517c5e1febSAlison Wang 				    (ulong)&systab, 0, (ulong)efi_run_in_el2,
252ec6617c3SAlison Wang 				    ES_TO_AARCH64);
253ec6617c3SAlison Wang 
254ec6617c3SAlison Wang 		/* Should never reach here, efi exits with longjmp */
255ec6617c3SAlison Wang 		while (1) { }
25669bd459dSAlexander Graf 	}
25769bd459dSAlexander Graf #endif
25869bd459dSAlexander Graf 
259b9939336SAlexander Graf 	return entry(&loaded_image_info, &systab);
260b9939336SAlexander Graf }
261b9939336SAlexander Graf 
262b9939336SAlexander Graf 
263b9939336SAlexander Graf /* Interpreter command to boot an arbitrary EFI image from memory */
264b9939336SAlexander Graf static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
265b9939336SAlexander Graf {
2661c39809bSAlexander Graf 	char *saddr, *sfdt;
2671c39809bSAlexander Graf 	unsigned long addr, fdt_addr = 0;
268b9939336SAlexander Graf 	int r = 0;
269b9939336SAlexander Graf 
270b9939336SAlexander Graf 	if (argc < 2)
2713c1dcef6SBin Meng 		return CMD_RET_USAGE;
272c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
273c7ae3dfdSSimon Glass 	if (!strcmp(argv[1], "hello")) {
274c7ae3dfdSSimon Glass 		ulong size = __efi_hello_world_end - __efi_hello_world_begin;
275c7ae3dfdSSimon Glass 
276c7ae3dfdSSimon Glass 		addr = CONFIG_SYS_LOAD_ADDR;
277c7ae3dfdSSimon Glass 		memcpy((char *)addr, __efi_hello_world_begin, size);
278c7ae3dfdSSimon Glass 	} else
279c7ae3dfdSSimon Glass #endif
280c7ae3dfdSSimon Glass 	{
281b9939336SAlexander Graf 		saddr = argv[1];
282b9939336SAlexander Graf 
283b9939336SAlexander Graf 		addr = simple_strtoul(saddr, NULL, 16);
284b9939336SAlexander Graf 
2851c39809bSAlexander Graf 		if (argc > 2) {
2861c39809bSAlexander Graf 			sfdt = argv[2];
2871c39809bSAlexander Graf 			fdt_addr = simple_strtoul(sfdt, NULL, 16);
2881c39809bSAlexander Graf 		}
289c7ae3dfdSSimon Glass 	}
2901c39809bSAlexander Graf 
2915ee31bafSSimon Glass 	printf("## Starting EFI application at %08lx ...\n", addr);
2921c39809bSAlexander Graf 	r = do_bootefi_exec((void *)addr, (void*)fdt_addr);
293b9939336SAlexander Graf 	printf("## Application terminated, r = %d\n", r);
294b9939336SAlexander Graf 
295b9939336SAlexander Graf 	if (r != 0)
296b9939336SAlexander Graf 		r = 1;
297b9939336SAlexander Graf 
298b9939336SAlexander Graf 	return r;
299b9939336SAlexander Graf }
300b9939336SAlexander Graf 
301b9939336SAlexander Graf #ifdef CONFIG_SYS_LONGHELP
302b9939336SAlexander Graf static char bootefi_help_text[] =
3031c39809bSAlexander Graf 	"<image address> [fdt address]\n"
3041c39809bSAlexander Graf 	"  - boot EFI payload stored at address <image address>.\n"
3051c39809bSAlexander Graf 	"    If specified, the device tree located at <fdt address> gets\n"
306c7ae3dfdSSimon Glass 	"    exposed as EFI configuration table.\n"
307c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
308c7ae3dfdSSimon Glass 	"hello\n"
309c7ae3dfdSSimon Glass 	"  - boot a sample Hello World application stored within U-Boot"
310c7ae3dfdSSimon Glass #endif
311c7ae3dfdSSimon Glass 	;
312b9939336SAlexander Graf #endif
313b9939336SAlexander Graf 
314b9939336SAlexander Graf U_BOOT_CMD(
3151c39809bSAlexander Graf 	bootefi, 3, 0, do_bootefi,
31692dfd922SSergey Kubushyn 	"Boots an EFI payload from memory",
317b9939336SAlexander Graf 	bootefi_help_text
318b9939336SAlexander Graf );
3190f4060ebSAlexander Graf 
320c07ad7c0SAlexander Graf void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
3210f4060ebSAlexander Graf {
3228c3df0bfSAlexander Graf 	__maybe_unused struct blk_desc *desc;
323ecbe1a07SAlexander Graf 	char devname[32] = { 0 }; /* dp->str is u16[32] long */
3240f4060ebSAlexander Graf 	char *colon;
3250f4060ebSAlexander Graf 
3261acc0087SPatrick Delaunay #if defined(CONFIG_BLK) || CONFIG_IS_ENABLED(ISO_PARTITION)
327f9d334bdSAlexander Graf 	desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
328f9d334bdSAlexander Graf #endif
329f9d334bdSAlexander Graf 
330f9d334bdSAlexander Graf #ifdef CONFIG_BLK
331f9d334bdSAlexander Graf 	if (desc) {
332f9d334bdSAlexander Graf 		snprintf(devname, sizeof(devname), "%s", desc->bdev->name);
333f9d334bdSAlexander Graf 	} else
334f9d334bdSAlexander Graf #endif
335f9d334bdSAlexander Graf 
336f9d334bdSAlexander Graf 	{
3370f4060ebSAlexander Graf 		/* Assemble the condensed device name we use in efi_disk.c */
3380f4060ebSAlexander Graf 		snprintf(devname, sizeof(devname), "%s%s", dev, devnr);
339f9d334bdSAlexander Graf 	}
340f9d334bdSAlexander Graf 
3410f4060ebSAlexander Graf 	colon = strchr(devname, ':');
3428c3df0bfSAlexander Graf 
3431acc0087SPatrick Delaunay #if CONFIG_IS_ENABLED(ISO_PARTITION)
3448c3df0bfSAlexander Graf 	/* For ISOs we create partition block devices */
3458c3df0bfSAlexander Graf 	if (desc && (desc->type != DEV_TYPE_UNKNOWN) &&
3468c3df0bfSAlexander Graf 	    (desc->part_type == PART_TYPE_ISO)) {
3478c3df0bfSAlexander Graf 		if (!colon)
348f9d334bdSAlexander Graf 			snprintf(devname, sizeof(devname), "%s:1", devname);
349f9d334bdSAlexander Graf 
3508c3df0bfSAlexander Graf 		colon = NULL;
3518c3df0bfSAlexander Graf 	}
3528c3df0bfSAlexander Graf #endif
3538c3df0bfSAlexander Graf 
3540f4060ebSAlexander Graf 	if (colon)
3550f4060ebSAlexander Graf 		*colon = '\0';
3560f4060ebSAlexander Graf 
357c07ad7c0SAlexander Graf 	/* Patch bootefi_device_path to the target device */
358c07ad7c0SAlexander Graf 	memset(bootefi_device_path[0].str, 0, sizeof(bootefi_device_path[0].str));
359c07ad7c0SAlexander Graf 	ascii2unicode(bootefi_device_path[0].str, devname);
360c07ad7c0SAlexander Graf 
361c07ad7c0SAlexander Graf 	/* Patch bootefi_image_path to the target file path */
3620f4060ebSAlexander Graf 	memset(bootefi_image_path[0].str, 0, sizeof(bootefi_image_path[0].str));
36349271666SAlexander Graf 	if (strcmp(dev, "Net")) {
36449271666SAlexander Graf 		/* Add leading / to fs paths, because they're absolute */
36549271666SAlexander Graf 		snprintf(devname, sizeof(devname), "/%s", path);
36649271666SAlexander Graf 	} else {
367c07ad7c0SAlexander Graf 		snprintf(devname, sizeof(devname), "%s", path);
36849271666SAlexander Graf 	}
3690f4060ebSAlexander Graf 	ascii2unicode(bootefi_image_path[0].str, devname);
3700f4060ebSAlexander Graf }
371