xref: /openbmc/u-boot/cmd/bootefi.c (revision ec6617c3)
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>
11f9d334bdSAlexander Graf #include <dm/device.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 
57e275458cSSimon Glass static efi_status_t EFIAPI bootefi_open_dp(void *handle, efi_guid_t *protocol,
58b9939336SAlexander Graf 			void **protocol_interface, void *agent_handle,
59b9939336SAlexander Graf 			void *controller_handle, uint32_t attributes)
60b9939336SAlexander Graf {
61c07ad7c0SAlexander Graf 	*protocol_interface = bootefi_device_path;
62b9939336SAlexander Graf 	return EFI_SUCCESS;
63b9939336SAlexander Graf }
64b9939336SAlexander Graf 
65b9939336SAlexander Graf /* The EFI loaded_image interface for the image executed via "bootefi" */
66b9939336SAlexander Graf static struct efi_loaded_image loaded_image_info = {
67c07ad7c0SAlexander Graf 	.device_handle = bootefi_device_path,
680f4060ebSAlexander Graf 	.file_path = bootefi_image_path,
69b9939336SAlexander Graf };
70b9939336SAlexander Graf 
71b9939336SAlexander Graf /* The EFI object struct for the image executed via "bootefi" */
72b9939336SAlexander Graf static struct efi_object loaded_image_info_obj = {
73b9939336SAlexander Graf 	.handle = &loaded_image_info,
74b9939336SAlexander Graf 	.protocols = {
75b9939336SAlexander Graf 		{
76b9939336SAlexander Graf 			/*
77b9939336SAlexander Graf 			 * When asking for the loaded_image interface, just
78b9939336SAlexander Graf 			 * return handle which points to loaded_image_info
79b9939336SAlexander Graf 			 */
80b9939336SAlexander Graf 			.guid = &efi_guid_loaded_image,
81b9939336SAlexander Graf 			.open = &efi_return_handle,
82b9939336SAlexander Graf 		},
83b9939336SAlexander Graf 		{
84b9939336SAlexander Graf 			/*
85b9939336SAlexander Graf 			 * When asking for the device path interface, return
86c07ad7c0SAlexander Graf 			 * bootefi_device_path
87b9939336SAlexander Graf 			 */
88b9939336SAlexander Graf 			.guid = &efi_guid_device_path,
89b9939336SAlexander Graf 			.open = &bootefi_open_dp,
90b9939336SAlexander Graf 		},
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,
102b9939336SAlexander Graf 			.open = &bootefi_open_dp,
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);
136ad0c1a3dSAlexander Graf 	}
137ad0c1a3dSAlexander Graf 	new_fdt = (void*)(ulong)new_fdt_addr;
1380d9d501fSAlexander Graf 	memcpy(new_fdt, fdt, fdt_totalsize(fdt));
1390d9d501fSAlexander Graf 	fdt_set_totalsize(new_fdt, fdt_size);
1400d9d501fSAlexander Graf 
1410d9d501fSAlexander Graf 	return new_fdt;
1420d9d501fSAlexander Graf }
1430d9d501fSAlexander Graf 
144*ec6617c3SAlison Wang #ifdef CONFIG_ARM64
145*ec6617c3SAlison Wang static unsigned long efi_run_in_el2(ulong (*entry)(void *image_handle,
146*ec6617c3SAlison Wang 		struct efi_system_table *st), void *image_handle,
147*ec6617c3SAlison Wang 		struct efi_system_table *st)
148*ec6617c3SAlison Wang {
149*ec6617c3SAlison Wang 	/* Enable caches again */
150*ec6617c3SAlison Wang 	dcache_enable();
151*ec6617c3SAlison Wang 
152*ec6617c3SAlison Wang 	return entry(image_handle, st);
153*ec6617c3SAlison Wang }
154*ec6617c3SAlison Wang #endif
155*ec6617c3SAlison Wang 
156b9939336SAlexander Graf /*
157b9939336SAlexander Graf  * Load an EFI payload into a newly allocated piece of memory, register all
158b9939336SAlexander Graf  * EFI objects it would want to access and jump to it.
159b9939336SAlexander Graf  */
1601c39809bSAlexander Graf static unsigned long do_bootefi_exec(void *efi, void *fdt)
161b9939336SAlexander Graf {
162e275458cSSimon Glass 	ulong (*entry)(void *image_handle, struct efi_system_table *st)
163e275458cSSimon Glass 		asmlinkage;
164b9939336SAlexander Graf 	ulong fdt_pages, fdt_size, fdt_start, fdt_end;
165dea2174dSAlexander Graf 	bootm_headers_t img = { 0 };
166b9939336SAlexander Graf 
167b9939336SAlexander Graf 	/*
168b9939336SAlexander Graf 	 * gd lives in a fixed register which may get clobbered while we execute
169b9939336SAlexander Graf 	 * the payload. So save it here and restore it on every callback entry
170b9939336SAlexander Graf 	 */
171b9939336SAlexander Graf 	efi_save_gd();
172b9939336SAlexander Graf 
1731c39809bSAlexander Graf 	if (fdt && !fdt_check_header(fdt)) {
174dea2174dSAlexander Graf 		/* Prepare fdt for payload */
1750d9d501fSAlexander Graf 		fdt = copy_fdt(fdt);
1760d9d501fSAlexander Graf 
1770d9d501fSAlexander Graf 		if (image_setup_libfdt(&img, fdt, 0, NULL)) {
178dea2174dSAlexander Graf 			printf("ERROR: Failed to process device tree\n");
179dea2174dSAlexander Graf 			return -EINVAL;
180dea2174dSAlexander Graf 		}
181dea2174dSAlexander Graf 
182dea2174dSAlexander Graf 		/* Link to it in the efi tables */
183b9939336SAlexander Graf 		systab.tables[0].guid = EFI_FDT_GUID;
1840d9d501fSAlexander Graf 		systab.tables[0].table = fdt;
185b9939336SAlexander Graf 		systab.nr_tables = 1;
186b9939336SAlexander Graf 
187b9939336SAlexander Graf 		/* And reserve the space in the memory map */
1880d9d501fSAlexander Graf 		fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK;
1890d9d501fSAlexander Graf 		fdt_end = ((ulong)fdt) + fdt_totalsize(fdt);
190b9939336SAlexander Graf 		fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK;
191b9939336SAlexander Graf 		fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
192b9939336SAlexander Graf 		/* Give a bootloader the chance to modify the device tree */
193b9939336SAlexander Graf 		fdt_pages += 2;
194b9939336SAlexander Graf 		efi_add_memory_map(fdt_start, fdt_pages,
195b9939336SAlexander Graf 				   EFI_BOOT_SERVICES_DATA, true);
196b9939336SAlexander Graf 	} else {
1971c39809bSAlexander Graf 		printf("WARNING: Invalid device tree, expect boot to fail\n");
198b9939336SAlexander Graf 		systab.nr_tables = 0;
199b9939336SAlexander Graf 	}
200b9939336SAlexander Graf 
201b9939336SAlexander Graf 	/* Load the EFI payload */
202b9939336SAlexander Graf 	entry = efi_load_pe(efi, &loaded_image_info);
203b9939336SAlexander Graf 	if (!entry)
204b9939336SAlexander Graf 		return -ENOENT;
205b9939336SAlexander Graf 
206b9939336SAlexander Graf 	/* Initialize and populate EFI object list */
207b9939336SAlexander Graf 	INIT_LIST_HEAD(&efi_obj_list);
208b9939336SAlexander Graf 	list_add_tail(&loaded_image_info_obj.link, &efi_obj_list);
209b9939336SAlexander Graf 	list_add_tail(&bootefi_device_obj.link, &efi_obj_list);
210b9939336SAlexander Graf #ifdef CONFIG_PARTITIONS
211b9939336SAlexander Graf 	efi_disk_register();
212b9939336SAlexander Graf #endif
213be8d3241SAlexander Graf #ifdef CONFIG_LCD
214be8d3241SAlexander Graf 	efi_gop_register();
215be8d3241SAlexander Graf #endif
2160efe1bcfSAlexander Graf #ifdef CONFIG_NET
2170efe1bcfSAlexander Graf 	void *nethandle = loaded_image_info.device_handle;
2180efe1bcfSAlexander Graf 	efi_net_register(&nethandle);
2190efe1bcfSAlexander Graf 
2200efe1bcfSAlexander Graf 	if (!memcmp(bootefi_device_path[0].str, "N\0e\0t", 6))
2210efe1bcfSAlexander Graf 		loaded_image_info.device_handle = nethandle;
2223fb97e26SAlexander Graf 	else
2233fb97e26SAlexander Graf 		loaded_image_info.device_handle = bootefi_device_path;
2240efe1bcfSAlexander Graf #endif
225e663b350SAlexander Graf #ifdef CONFIG_GENERATE_SMBIOS_TABLE
226e663b350SAlexander Graf 	efi_smbios_register();
227e663b350SAlexander Graf #endif
228b9939336SAlexander Graf 
22980a4800eSAlexander Graf 	/* Initialize EFI runtime services */
23080a4800eSAlexander Graf 	efi_reset_system_init();
23180a4800eSAlexander Graf 	efi_get_time_init();
23280a4800eSAlexander Graf 
233b9939336SAlexander Graf 	/* Call our payload! */
234edcef3baSAlexander Graf 	debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
235a86aeaf2SAlexander Graf 
236a86aeaf2SAlexander Graf 	if (setjmp(&loaded_image_info.exit_jmp)) {
237a86aeaf2SAlexander Graf 		efi_status_t status = loaded_image_info.exit_status;
238a86aeaf2SAlexander Graf 		return status == EFI_SUCCESS ? 0 : -EINVAL;
239a86aeaf2SAlexander Graf 	}
240a86aeaf2SAlexander Graf 
24169bd459dSAlexander Graf #ifdef CONFIG_ARM64
24269bd459dSAlexander Graf 	/* On AArch64 we need to make sure we call our payload in < EL3 */
24369bd459dSAlexander Graf 	if (current_el() == 3) {
24469bd459dSAlexander Graf 		smp_kick_all_cpus();
24569bd459dSAlexander Graf 		dcache_disable();	/* flush cache before switch to EL2 */
246*ec6617c3SAlison Wang 
247*ec6617c3SAlison Wang 		/* Move into EL2 and keep running there */
248*ec6617c3SAlison Wang 		armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info,
249*ec6617c3SAlison Wang 				    (ulong)&systab, (ulong)efi_run_in_el2,
250*ec6617c3SAlison Wang 				    ES_TO_AARCH64);
251*ec6617c3SAlison Wang 
252*ec6617c3SAlison Wang 		/* Should never reach here, efi exits with longjmp */
253*ec6617c3SAlison Wang 		while (1) { }
25469bd459dSAlexander Graf 	}
25569bd459dSAlexander Graf #endif
25669bd459dSAlexander Graf 
257b9939336SAlexander Graf 	return entry(&loaded_image_info, &systab);
258b9939336SAlexander Graf }
259b9939336SAlexander Graf 
260b9939336SAlexander Graf 
261b9939336SAlexander Graf /* Interpreter command to boot an arbitrary EFI image from memory */
262b9939336SAlexander Graf static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
263b9939336SAlexander Graf {
2641c39809bSAlexander Graf 	char *saddr, *sfdt;
2651c39809bSAlexander Graf 	unsigned long addr, fdt_addr = 0;
266b9939336SAlexander Graf 	int r = 0;
267b9939336SAlexander Graf 
268b9939336SAlexander Graf 	if (argc < 2)
2693c1dcef6SBin Meng 		return CMD_RET_USAGE;
270c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
271c7ae3dfdSSimon Glass 	if (!strcmp(argv[1], "hello")) {
272c7ae3dfdSSimon Glass 		ulong size = __efi_hello_world_end - __efi_hello_world_begin;
273c7ae3dfdSSimon Glass 
274c7ae3dfdSSimon Glass 		addr = CONFIG_SYS_LOAD_ADDR;
275c7ae3dfdSSimon Glass 		memcpy((char *)addr, __efi_hello_world_begin, size);
276c7ae3dfdSSimon Glass 	} else
277c7ae3dfdSSimon Glass #endif
278c7ae3dfdSSimon Glass 	{
279b9939336SAlexander Graf 		saddr = argv[1];
280b9939336SAlexander Graf 
281b9939336SAlexander Graf 		addr = simple_strtoul(saddr, NULL, 16);
282b9939336SAlexander Graf 
2831c39809bSAlexander Graf 		if (argc > 2) {
2841c39809bSAlexander Graf 			sfdt = argv[2];
2851c39809bSAlexander Graf 			fdt_addr = simple_strtoul(sfdt, NULL, 16);
2861c39809bSAlexander Graf 		}
287c7ae3dfdSSimon Glass 	}
2881c39809bSAlexander Graf 
2895ee31bafSSimon Glass 	printf("## Starting EFI application at %08lx ...\n", addr);
2901c39809bSAlexander Graf 	r = do_bootefi_exec((void *)addr, (void*)fdt_addr);
291b9939336SAlexander Graf 	printf("## Application terminated, r = %d\n", r);
292b9939336SAlexander Graf 
293b9939336SAlexander Graf 	if (r != 0)
294b9939336SAlexander Graf 		r = 1;
295b9939336SAlexander Graf 
296b9939336SAlexander Graf 	return r;
297b9939336SAlexander Graf }
298b9939336SAlexander Graf 
299b9939336SAlexander Graf #ifdef CONFIG_SYS_LONGHELP
300b9939336SAlexander Graf static char bootefi_help_text[] =
3011c39809bSAlexander Graf 	"<image address> [fdt address]\n"
3021c39809bSAlexander Graf 	"  - boot EFI payload stored at address <image address>.\n"
3031c39809bSAlexander Graf 	"    If specified, the device tree located at <fdt address> gets\n"
304c7ae3dfdSSimon Glass 	"    exposed as EFI configuration table.\n"
305c7ae3dfdSSimon Glass #ifdef CONFIG_CMD_BOOTEFI_HELLO
306c7ae3dfdSSimon Glass 	"hello\n"
307c7ae3dfdSSimon Glass 	"  - boot a sample Hello World application stored within U-Boot"
308c7ae3dfdSSimon Glass #endif
309c7ae3dfdSSimon Glass 	;
310b9939336SAlexander Graf #endif
311b9939336SAlexander Graf 
312b9939336SAlexander Graf U_BOOT_CMD(
3131c39809bSAlexander Graf 	bootefi, 3, 0, do_bootefi,
31492dfd922SSergey Kubushyn 	"Boots an EFI payload from memory",
315b9939336SAlexander Graf 	bootefi_help_text
316b9939336SAlexander Graf );
3170f4060ebSAlexander Graf 
318c07ad7c0SAlexander Graf void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
3190f4060ebSAlexander Graf {
3208c3df0bfSAlexander Graf 	__maybe_unused struct blk_desc *desc;
321ecbe1a07SAlexander Graf 	char devname[32] = { 0 }; /* dp->str is u16[32] long */
3220f4060ebSAlexander Graf 	char *colon;
3230f4060ebSAlexander Graf 
324f9d334bdSAlexander Graf #if defined(CONFIG_BLK) || defined(CONFIG_ISO_PARTITION)
325f9d334bdSAlexander Graf 	desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
326f9d334bdSAlexander Graf #endif
327f9d334bdSAlexander Graf 
328f9d334bdSAlexander Graf #ifdef CONFIG_BLK
329f9d334bdSAlexander Graf 	if (desc) {
330f9d334bdSAlexander Graf 		snprintf(devname, sizeof(devname), "%s", desc->bdev->name);
331f9d334bdSAlexander Graf 	} else
332f9d334bdSAlexander Graf #endif
333f9d334bdSAlexander Graf 
334f9d334bdSAlexander Graf 	{
3350f4060ebSAlexander Graf 		/* Assemble the condensed device name we use in efi_disk.c */
3360f4060ebSAlexander Graf 		snprintf(devname, sizeof(devname), "%s%s", dev, devnr);
337f9d334bdSAlexander Graf 	}
338f9d334bdSAlexander Graf 
3390f4060ebSAlexander Graf 	colon = strchr(devname, ':');
3408c3df0bfSAlexander Graf 
3418c3df0bfSAlexander Graf #ifdef CONFIG_ISO_PARTITION
3428c3df0bfSAlexander Graf 	/* For ISOs we create partition block devices */
3438c3df0bfSAlexander Graf 	if (desc && (desc->type != DEV_TYPE_UNKNOWN) &&
3448c3df0bfSAlexander Graf 	    (desc->part_type == PART_TYPE_ISO)) {
3458c3df0bfSAlexander Graf 		if (!colon)
346f9d334bdSAlexander Graf 			snprintf(devname, sizeof(devname), "%s:1", devname);
347f9d334bdSAlexander Graf 
3488c3df0bfSAlexander Graf 		colon = NULL;
3498c3df0bfSAlexander Graf 	}
3508c3df0bfSAlexander Graf #endif
3518c3df0bfSAlexander Graf 
3520f4060ebSAlexander Graf 	if (colon)
3530f4060ebSAlexander Graf 		*colon = '\0';
3540f4060ebSAlexander Graf 
355c07ad7c0SAlexander Graf 	/* Patch bootefi_device_path to the target device */
356c07ad7c0SAlexander Graf 	memset(bootefi_device_path[0].str, 0, sizeof(bootefi_device_path[0].str));
357c07ad7c0SAlexander Graf 	ascii2unicode(bootefi_device_path[0].str, devname);
358c07ad7c0SAlexander Graf 
359c07ad7c0SAlexander Graf 	/* Patch bootefi_image_path to the target file path */
3600f4060ebSAlexander Graf 	memset(bootefi_image_path[0].str, 0, sizeof(bootefi_image_path[0].str));
36149271666SAlexander Graf 	if (strcmp(dev, "Net")) {
36249271666SAlexander Graf 		/* Add leading / to fs paths, because they're absolute */
36349271666SAlexander Graf 		snprintf(devname, sizeof(devname), "/%s", path);
36449271666SAlexander Graf 	} else {
365c07ad7c0SAlexander Graf 		snprintf(devname, sizeof(devname), "%s", path);
36649271666SAlexander Graf 	}
3670f4060ebSAlexander Graf 	ascii2unicode(bootefi_image_path[0].str, devname);
3680f4060ebSAlexander Graf }
369