blob: 0915192bbb7368a9ee82db200c15e62df0f64d02 [file] [log] [blame]
Alexander Grafb9939332016-03-10 00:27:20 +01001/*
2 * EFI application loader
3 *
4 * Copyright (c) 2016 Alexander Graf
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +02009#include <charset.h>
Alexander Grafb9939332016-03-10 00:27:20 +010010#include <common.h>
11#include <command.h>
Simon Glass9d922452017-05-17 17:18:03 -060012#include <dm.h>
Alexander Grafb9939332016-03-10 00:27:20 +010013#include <efi_loader.h>
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +020014#include <efi_selftest.h>
Alexander Grafb9939332016-03-10 00:27:20 +010015#include <errno.h>
16#include <libfdt.h>
17#include <libfdt_env.h>
Alexander Grafad0c1a32016-04-11 23:51:01 +020018#include <memalign.h>
Alexander Graf0d9d5012016-04-11 16:55:26 +020019#include <asm/global_data.h>
Simon Glasse2754582016-09-25 15:27:32 -060020#include <asm-generic/sections.h>
21#include <linux/linkage.h>
Alexander Graf0d9d5012016-04-11 16:55:26 +020022
23DECLARE_GLOBAL_DATA_PTR;
Alexander Grafb9939332016-03-10 00:27:20 +010024
Heinrich Schuchardt7cbc1242017-07-19 19:37:22 +020025static uint8_t efi_obj_list_initalized;
26
Rob Clark95c55532017-09-13 18:05:33 -040027static struct efi_device_path *bootefi_image_path;
28static struct efi_device_path *bootefi_device_path;
Alexander Grafb9939332016-03-10 00:27:20 +010029
Heinrich Schuchardt7cbc1242017-07-19 19:37:22 +020030/* Initialize and populate EFI object list */
31static void efi_init_obj_list(void)
32{
33 efi_obj_list_initalized = 1;
34
Heinrich Schuchardt7cbc1242017-07-19 19:37:22 +020035 efi_console_register();
36#ifdef CONFIG_PARTITIONS
37 efi_disk_register();
38#endif
39#if defined(CONFIG_LCD) || defined(CONFIG_DM_VIDEO)
40 efi_gop_register();
41#endif
42#ifdef CONFIG_NET
Rob Clark95c55532017-09-13 18:05:33 -040043 efi_net_register();
Heinrich Schuchardt7cbc1242017-07-19 19:37:22 +020044#endif
45#ifdef CONFIG_GENERATE_SMBIOS_TABLE
46 efi_smbios_register();
47#endif
Heinrich Schuchardtb3d60902017-10-18 18:13:04 +020048 efi_watchdog_register();
Heinrich Schuchardt7cbc1242017-07-19 19:37:22 +020049
50 /* Initialize EFI runtime services */
51 efi_reset_system_init();
52 efi_get_time_init();
53}
54
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +020055/*
56 * Set the load options of an image from an environment variable.
57 *
58 * @loaded_image_info: the image
59 * @env_var: name of the environment variable
60 */
61static void set_load_options(struct efi_loaded_image *loaded_image_info,
62 const char *env_var)
63{
64 size_t size;
65 const char *env = env_get(env_var);
66
67 loaded_image_info->load_options = NULL;
68 loaded_image_info->load_options_size = 0;
69 if (!env)
70 return;
71 size = strlen(env) + 1;
72 loaded_image_info->load_options = calloc(size, sizeof(u16));
73 if (!loaded_image_info->load_options) {
74 printf("ERROR: Out of memory\n");
75 return;
76 }
77 utf8_to_utf16(loaded_image_info->load_options, (u8 *)env, size);
78 loaded_image_info->load_options_size = size * 2;
79}
80
Alexander Graf0d9d5012016-04-11 16:55:26 +020081static void *copy_fdt(void *fdt)
82{
83 u64 fdt_size = fdt_totalsize(fdt);
Alexander Grafad0c1a32016-04-11 23:51:01 +020084 unsigned long fdt_ram_start = -1L, fdt_pages;
85 u64 new_fdt_addr;
Alexander Graf0d9d5012016-04-11 16:55:26 +020086 void *new_fdt;
Alexander Grafad0c1a32016-04-11 23:51:01 +020087 int i;
Alexander Graf0d9d5012016-04-11 16:55:26 +020088
Alexander Grafad0c1a32016-04-11 23:51:01 +020089 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
90 u64 ram_start = gd->bd->bi_dram[i].start;
91 u64 ram_size = gd->bd->bi_dram[i].size;
Alexander Graf0d9d5012016-04-11 16:55:26 +020092
Alexander Grafad0c1a32016-04-11 23:51:01 +020093 if (!ram_size)
94 continue;
95
96 if (ram_start < fdt_ram_start)
97 fdt_ram_start = ram_start;
98 }
99
100 /* Give us at least 4kb breathing room */
xypron.glpk@gmx.dea44bffc2017-08-11 21:19:25 +0200101 fdt_size = ALIGN(fdt_size + 4096, EFI_PAGE_SIZE);
Alexander Grafad0c1a32016-04-11 23:51:01 +0200102 fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
103
104 /* Safe fdt location is at 128MB */
105 new_fdt_addr = fdt_ram_start + (128 * 1024 * 1024) + fdt_size;
106 if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
107 &new_fdt_addr) != EFI_SUCCESS) {
108 /* If we can't put it there, put it somewhere */
xypron.glpk@gmx.dea44bffc2017-08-11 21:19:25 +0200109 new_fdt_addr = (ulong)memalign(EFI_PAGE_SIZE, fdt_size);
Alexander Graf85a6e9b2017-07-03 13:32:35 +0200110 if (efi_allocate_pages(1, EFI_BOOT_SERVICES_DATA, fdt_pages,
111 &new_fdt_addr) != EFI_SUCCESS) {
112 printf("ERROR: Failed to reserve space for FDT\n");
113 return NULL;
114 }
Alexander Grafad0c1a32016-04-11 23:51:01 +0200115 }
Alexander Graf85a6e9b2017-07-03 13:32:35 +0200116
Alexander Grafad0c1a32016-04-11 23:51:01 +0200117 new_fdt = (void*)(ulong)new_fdt_addr;
Alexander Graf0d9d5012016-04-11 16:55:26 +0200118 memcpy(new_fdt, fdt, fdt_totalsize(fdt));
119 fdt_set_totalsize(new_fdt, fdt_size);
120
121 return new_fdt;
122}
123
Heinrich Schuchardt3eb08412017-10-18 18:13:08 +0200124static efi_status_t efi_do_enter(
125 void *image_handle, struct efi_system_table *st,
126 asmlinkage ulong (*entry)(void *image_handle,
127 struct efi_system_table *st))
xypron.glpk@gmx.deb06d8ac2017-07-04 23:15:21 +0200128{
129 efi_status_t ret = EFI_LOAD_ERROR;
130
131 if (entry)
132 ret = entry(image_handle, st);
133 st->boottime->exit(image_handle, ret, 0, NULL);
134 return ret;
135}
136
Alison Wangec6617c2016-11-10 10:49:03 +0800137#ifdef CONFIG_ARM64
Heinrich Schuchardt3eb08412017-10-18 18:13:08 +0200138static efi_status_t efi_run_in_el2(asmlinkage ulong (*entry)(
xypron.glpk@gmx.deb06d8ac2017-07-04 23:15:21 +0200139 void *image_handle, struct efi_system_table *st),
140 void *image_handle, struct efi_system_table *st)
Alison Wangec6617c2016-11-10 10:49:03 +0800141{
142 /* Enable caches again */
143 dcache_enable();
144
xypron.glpk@gmx.deb06d8ac2017-07-04 23:15:21 +0200145 return efi_do_enter(image_handle, st, entry);
Alison Wangec6617c2016-11-10 10:49:03 +0800146}
147#endif
148
Alexander Grafb9939332016-03-10 00:27:20 +0100149/*
150 * Load an EFI payload into a newly allocated piece of memory, register all
151 * EFI objects it would want to access and jump to it.
152 */
Heinrich Schuchardt3eb08412017-10-18 18:13:08 +0200153static efi_status_t do_bootefi_exec(void *efi, void *fdt,
154 struct efi_device_path *device_path,
155 struct efi_device_path *image_path)
Alexander Grafb9939332016-03-10 00:27:20 +0100156{
Rob Clark95c55532017-09-13 18:05:33 -0400157 struct efi_loaded_image loaded_image_info = {};
158 struct efi_object loaded_image_info_obj = {};
Rob Clarkbf192732017-10-10 08:23:06 -0400159 struct efi_device_path *memdp = NULL;
Rob Clark95c55532017-09-13 18:05:33 -0400160 ulong ret;
161
Simon Glasse2754582016-09-25 15:27:32 -0600162 ulong (*entry)(void *image_handle, struct efi_system_table *st)
163 asmlinkage;
Alexander Grafb9939332016-03-10 00:27:20 +0100164 ulong fdt_pages, fdt_size, fdt_start, fdt_end;
Alexander Graff4f99932017-07-26 13:41:05 +0200165 const efi_guid_t fdt_guid = EFI_FDT_GUID;
Alexander Grafdea21742016-03-04 01:10:13 +0100166 bootm_headers_t img = { 0 };
Alexander Grafb9939332016-03-10 00:27:20 +0100167
Rob Clarkbf192732017-10-10 08:23:06 -0400168 /*
169 * Special case for efi payload not loaded from disk, such as
170 * 'bootefi hello' or for example payload loaded directly into
171 * memory via jtag/etc:
172 */
173 if (!device_path && !image_path) {
174 printf("WARNING: using memory device/image path, this may confuse some payloads!\n");
175 /* actual addresses filled in after efi_load_pe() */
176 memdp = efi_dp_from_mem(0, 0, 0);
177 device_path = image_path = memdp;
178 } else {
179 assert(device_path && image_path);
180 }
181
Rob Clark95c55532017-09-13 18:05:33 -0400182 /* Initialize and populate EFI object list */
183 if (!efi_obj_list_initalized)
184 efi_init_obj_list();
185
186 efi_setup_loaded_image(&loaded_image_info, &loaded_image_info_obj,
187 device_path, image_path);
188
Alexander Grafb9939332016-03-10 00:27:20 +0100189 /*
190 * gd lives in a fixed register which may get clobbered while we execute
191 * the payload. So save it here and restore it on every callback entry
192 */
193 efi_save_gd();
194
Alexander Graf1c398092016-04-14 16:07:53 +0200195 if (fdt && !fdt_check_header(fdt)) {
Alexander Grafdea21742016-03-04 01:10:13 +0100196 /* Prepare fdt for payload */
Alexander Graf0d9d5012016-04-11 16:55:26 +0200197 fdt = copy_fdt(fdt);
198
199 if (image_setup_libfdt(&img, fdt, 0, NULL)) {
Alexander Grafdea21742016-03-04 01:10:13 +0100200 printf("ERROR: Failed to process device tree\n");
201 return -EINVAL;
202 }
203
204 /* Link to it in the efi tables */
Alexander Graff4f99932017-07-26 13:41:05 +0200205 efi_install_configuration_table(&fdt_guid, fdt);
Alexander Grafb9939332016-03-10 00:27:20 +0100206
207 /* And reserve the space in the memory map */
Alexander Graf0d9d5012016-04-11 16:55:26 +0200208 fdt_start = ((ulong)fdt) & ~EFI_PAGE_MASK;
209 fdt_end = ((ulong)fdt) + fdt_totalsize(fdt);
Alexander Grafb9939332016-03-10 00:27:20 +0100210 fdt_size = (fdt_end - fdt_start) + EFI_PAGE_MASK;
211 fdt_pages = fdt_size >> EFI_PAGE_SHIFT;
212 /* Give a bootloader the chance to modify the device tree */
213 fdt_pages += 2;
214 efi_add_memory_map(fdt_start, fdt_pages,
215 EFI_BOOT_SERVICES_DATA, true);
Alexander Grafb9939332016-03-10 00:27:20 +0100216 } else {
Alexander Graf1c398092016-04-14 16:07:53 +0200217 printf("WARNING: Invalid device tree, expect boot to fail\n");
Alexander Graff4f99932017-07-26 13:41:05 +0200218 efi_install_configuration_table(&fdt_guid, NULL);
Alexander Grafb9939332016-03-10 00:27:20 +0100219 }
220
221 /* Load the EFI payload */
222 entry = efi_load_pe(efi, &loaded_image_info);
Rob Clark95c55532017-09-13 18:05:33 -0400223 if (!entry) {
224 ret = -ENOENT;
225 goto exit;
226 }
Alexander Graf80a48002016-08-16 21:08:45 +0200227
Rob Clarkbf192732017-10-10 08:23:06 -0400228 if (memdp) {
229 struct efi_device_path_memory *mdp = (void *)memdp;
230 mdp->memory_type = loaded_image_info.image_code_type;
231 mdp->start_address = (uintptr_t)loaded_image_info.image_base;
232 mdp->end_address = mdp->start_address +
233 loaded_image_info.image_size;
234 }
235
Rob Clarkad644e72017-09-13 18:05:37 -0400236 /* we don't support much: */
237 env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported",
238 "{ro,boot}(blob)0000000000000000");
239
Alexander Grafb9939332016-03-10 00:27:20 +0100240 /* Call our payload! */
Alexander Grafedcef3b2016-06-02 11:38:27 +0200241 debug("%s:%d Jumping to 0x%lx\n", __func__, __LINE__, (long)entry);
Alexander Grafa86aeaf2016-05-20 23:28:23 +0200242
243 if (setjmp(&loaded_image_info.exit_jmp)) {
Rob Clark95c55532017-09-13 18:05:33 -0400244 ret = loaded_image_info.exit_status;
Rob Clark95c55532017-09-13 18:05:33 -0400245 goto exit;
Alexander Grafa86aeaf2016-05-20 23:28:23 +0200246 }
247
Alexander Graf69bd4592016-11-17 01:02:58 +0100248#ifdef CONFIG_ARM64
249 /* On AArch64 we need to make sure we call our payload in < EL3 */
250 if (current_el() == 3) {
251 smp_kick_all_cpus();
252 dcache_disable(); /* flush cache before switch to EL2 */
Alison Wangec6617c2016-11-10 10:49:03 +0800253
254 /* Move into EL2 and keep running there */
255 armv8_switch_to_el2((ulong)entry, (ulong)&loaded_image_info,
Alison Wang7c5e1fe2017-01-17 09:39:17 +0800256 (ulong)&systab, 0, (ulong)efi_run_in_el2,
Alison Wangec6617c2016-11-10 10:49:03 +0800257 ES_TO_AARCH64);
258
259 /* Should never reach here, efi exits with longjmp */
260 while (1) { }
Alexander Graf69bd4592016-11-17 01:02:58 +0100261 }
262#endif
263
Rob Clark95c55532017-09-13 18:05:33 -0400264 ret = efi_do_enter(&loaded_image_info, &systab, entry);
265
266exit:
267 /* image has returned, loaded-image obj goes *poof*: */
268 list_del(&loaded_image_info_obj.link);
269
270 return ret;
Alexander Grafb9939332016-03-10 00:27:20 +0100271}
272
Rob Clark9975fe92017-09-13 18:05:38 -0400273static int do_bootefi_bootmgr_exec(unsigned long fdt_addr)
274{
275 struct efi_device_path *device_path, *file_path;
276 void *addr;
277 efi_status_t r;
278
279 /* Initialize and populate EFI object list */
280 if (!efi_obj_list_initalized)
281 efi_init_obj_list();
282
283 /*
284 * gd lives in a fixed register which may get clobbered while we execute
285 * the payload. So save it here and restore it on every callback entry
286 */
287 efi_save_gd();
288
289 addr = efi_bootmgr_load(&device_path, &file_path);
290 if (!addr)
291 return 1;
292
293 printf("## Starting EFI application at %p ...\n", addr);
294 r = do_bootefi_exec(addr, (void *)fdt_addr, device_path, file_path);
295 printf("## Application terminated, r = %lu\n",
296 r & ~EFI_ERROR_MASK);
297
298 if (r != EFI_SUCCESS)
299 return 1;
300
301 return 0;
302}
303
Alexander Grafb9939332016-03-10 00:27:20 +0100304/* Interpreter command to boot an arbitrary EFI image from memory */
305static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
306{
Alexander Graf1c398092016-04-14 16:07:53 +0200307 char *saddr, *sfdt;
308 unsigned long addr, fdt_addr = 0;
Heinrich Schuchardt3eb08412017-10-18 18:13:08 +0200309 efi_status_t r;
Alexander Grafb9939332016-03-10 00:27:20 +0100310
311 if (argc < 2)
Bin Meng3c1dcef2016-08-13 04:02:06 -0700312 return CMD_RET_USAGE;
Simon Glassc7ae3df2016-11-07 08:47:08 -0700313#ifdef CONFIG_CMD_BOOTEFI_HELLO
314 if (!strcmp(argv[1], "hello")) {
Heinrich Schuchardt5e444892017-09-05 03:19:37 +0200315 ulong size = __efi_helloworld_end - __efi_helloworld_begin;
Alexander Grafb9939332016-03-10 00:27:20 +0100316
Heinrich Schuchardt51c533f2017-08-28 18:54:30 +0200317 saddr = env_get("loadaddr");
318 if (saddr)
319 addr = simple_strtoul(saddr, NULL, 16);
320 else
321 addr = CONFIG_SYS_LOAD_ADDR;
Heinrich Schuchardt5e444892017-09-05 03:19:37 +0200322 memcpy((char *)addr, __efi_helloworld_begin, size);
Simon Glassc7ae3df2016-11-07 08:47:08 -0700323 } else
324#endif
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200325#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
326 if (!strcmp(argv[1], "selftest")) {
Heinrich Schuchardt7aca68c2017-09-20 22:54:58 +0200327 struct efi_loaded_image loaded_image_info = {};
328 struct efi_object loaded_image_info_obj = {};
329
Heinrich Schuchardtf972dc12017-10-18 18:13:09 +0200330 /* Construct a dummy device path. */
331 bootefi_device_path = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE,
332 (uintptr_t)&efi_selftest,
333 (uintptr_t)&efi_selftest);
334 bootefi_image_path = efi_dp_from_file(NULL, 0, "\\selftest");
335
Heinrich Schuchardt7aca68c2017-09-20 22:54:58 +0200336 efi_setup_loaded_image(&loaded_image_info,
337 &loaded_image_info_obj,
338 bootefi_device_path, bootefi_image_path);
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200339 /*
340 * gd lives in a fixed register which may get clobbered while we
341 * execute the payload. So save it here and restore it on every
342 * callback entry
343 */
344 efi_save_gd();
345 /* Initialize and populate EFI object list */
346 if (!efi_obj_list_initalized)
347 efi_init_obj_list();
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200348 /* Transfer environment variable efi_selftest as load options */
349 set_load_options(&loaded_image_info, "efi_selftest");
350 /* Execute the test */
351 r = efi_selftest(&loaded_image_info, &systab);
Heinrich Schuchardtc2b53902017-10-18 18:13:14 +0200352 efi_restore_gd();
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200353 free(loaded_image_info.load_options);
Heinrich Schuchardtc2b53902017-10-18 18:13:14 +0200354 list_del(&loaded_image_info_obj.link);
355 return r != EFI_SUCCESS;
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200356 } else
357#endif
Rob Clark9975fe92017-09-13 18:05:38 -0400358 if (!strcmp(argv[1], "bootmgr")) {
359 unsigned long fdt_addr = 0;
360
361 if (argc > 2)
362 fdt_addr = simple_strtoul(argv[2], NULL, 16);
363
364 return do_bootefi_bootmgr_exec(fdt_addr);
365 } else {
Simon Glassc7ae3df2016-11-07 08:47:08 -0700366 saddr = argv[1];
Alexander Grafb9939332016-03-10 00:27:20 +0100367
Simon Glassc7ae3df2016-11-07 08:47:08 -0700368 addr = simple_strtoul(saddr, NULL, 16);
369
370 if (argc > 2) {
371 sfdt = argv[2];
372 fdt_addr = simple_strtoul(sfdt, NULL, 16);
373 }
Alexander Graf1c398092016-04-14 16:07:53 +0200374 }
375
Simon Glass5ee31ba2016-11-07 08:47:05 -0700376 printf("## Starting EFI application at %08lx ...\n", addr);
Rob Clark95c55532017-09-13 18:05:33 -0400377 r = do_bootefi_exec((void *)addr, (void *)fdt_addr,
378 bootefi_device_path, bootefi_image_path);
xypron.glpk@gmx.de1da1bac2017-07-04 23:15:23 +0200379 printf("## Application terminated, r = %lu\n",
380 r & ~EFI_ERROR_MASK);
Alexander Grafb9939332016-03-10 00:27:20 +0100381
xypron.glpk@gmx.de1da1bac2017-07-04 23:15:23 +0200382 if (r != EFI_SUCCESS)
383 return 1;
384 else
385 return 0;
Alexander Grafb9939332016-03-10 00:27:20 +0100386}
387
388#ifdef CONFIG_SYS_LONGHELP
389static char bootefi_help_text[] =
Alexander Graf1c398092016-04-14 16:07:53 +0200390 "<image address> [fdt address]\n"
391 " - boot EFI payload stored at address <image address>.\n"
392 " If specified, the device tree located at <fdt address> gets\n"
Simon Glassc7ae3df2016-11-07 08:47:08 -0700393 " exposed as EFI configuration table.\n"
394#ifdef CONFIG_CMD_BOOTEFI_HELLO
Heinrich Schuchardt623b3a52017-09-15 10:06:11 +0200395 "bootefi hello\n"
396 " - boot a sample Hello World application stored within U-Boot\n"
397#endif
398#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
399 "bootefi selftest\n"
400 " - boot an EFI selftest application stored within U-Boot\n"
Heinrich Schuchardtd78e40d2017-10-18 18:13:13 +0200401 " Use environment variable efi_selftest to select a single test.\n"
402 " Use 'setenv efi_selftest list' to enumerate all tests.\n"
Simon Glassc7ae3df2016-11-07 08:47:08 -0700403#endif
Rob Clark9975fe92017-09-13 18:05:38 -0400404 "bootmgr [fdt addr]\n"
405 " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n"
406 "\n"
407 " If specified, the device tree located at <fdt address> gets\n"
408 " exposed as EFI configuration table.\n";
Alexander Grafb9939332016-03-10 00:27:20 +0100409#endif
410
411U_BOOT_CMD(
Alexander Graf1c398092016-04-14 16:07:53 +0200412 bootefi, 3, 0, do_bootefi,
Sergey Kubushyn92dfd922016-06-07 11:14:31 -0700413 "Boots an EFI payload from memory",
Alexander Grafb9939332016-03-10 00:27:20 +0100414 bootefi_help_text
415);
Alexander Graf0f4060e2016-03-04 01:10:14 +0100416
Rob Clark95c55532017-09-13 18:05:33 -0400417static int parse_partnum(const char *devnr)
418{
419 const char *str = strchr(devnr, ':');
420 if (str) {
421 str++;
422 return simple_strtoul(str, NULL, 16);
423 }
424 return 0;
425}
426
Alexander Grafc07ad7c2016-04-11 16:16:19 +0200427void efi_set_bootdev(const char *dev, const char *devnr, const char *path)
Alexander Graf0f4060e2016-03-04 01:10:14 +0100428{
Rob Clark95c55532017-09-13 18:05:33 -0400429 char filename[32] = { 0 }; /* dp->str is u16[32] long */
430 char *s;
Alexander Graf0f4060e2016-03-04 01:10:14 +0100431
Rob Clark95c55532017-09-13 18:05:33 -0400432 if (strcmp(dev, "Net")) {
433 struct blk_desc *desc;
434 int part;
435
436 desc = blk_get_dev(dev, simple_strtol(devnr, NULL, 10));
437 part = parse_partnum(devnr);
438
439 bootefi_device_path = efi_dp_from_part(desc, part);
440 } else {
441#ifdef CONFIG_NET
442 bootefi_device_path = efi_dp_from_eth();
Alexander Graff9d334b2016-08-05 14:49:53 +0200443#endif
Alexander Graff9d334b2016-08-05 14:49:53 +0200444 }
445
Rob Clark9975fe92017-09-13 18:05:38 -0400446 if (!path)
447 return;
448
Alexander Graf49271662016-07-21 01:44:46 +0200449 if (strcmp(dev, "Net")) {
450 /* Add leading / to fs paths, because they're absolute */
Rob Clark95c55532017-09-13 18:05:33 -0400451 snprintf(filename, sizeof(filename), "/%s", path);
Alexander Graf49271662016-07-21 01:44:46 +0200452 } else {
Rob Clark95c55532017-09-13 18:05:33 -0400453 snprintf(filename, sizeof(filename), "%s", path);
Alexander Graf49271662016-07-21 01:44:46 +0200454 }
Rob Clark3e433e92017-07-24 07:59:09 -0400455 /* DOS style file path: */
Rob Clark95c55532017-09-13 18:05:33 -0400456 s = filename;
Rob Clark3e433e92017-07-24 07:59:09 -0400457 while ((s = strchr(s, '/')))
458 *s++ = '\\';
Rob Clark95c55532017-09-13 18:05:33 -0400459 bootefi_image_path = efi_dp_from_file(NULL, 0, filename);
Alexander Graf0f4060e2016-03-04 01:10:14 +0100460}