blob: 86297bb7c1166537a9625adbbfd32355013fc575 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rob Clarkf90cb9f2017-09-13 18:05:28 -04002/*
3 * EFI device path from u-boot device-model mapping
4 *
5 * (C) Copyright 2017 Rob Clark
Rob Clarkf90cb9f2017-09-13 18:05:28 -04006 */
7
8#include <common.h>
9#include <blk.h>
10#include <dm.h>
11#include <usb.h>
12#include <mmc.h>
13#include <efi_loader.h>
Rob Clarkf90cb9f2017-09-13 18:05:28 -040014#include <part.h>
AKASHI Takahiro659a6262019-09-12 13:52:35 +090015#include <sandboxblockdev.h>
Heinrich Schuchardt8d80af82019-07-14 19:26:47 +020016#include <asm-generic/unaligned.h>
Rob Clarkf90cb9f2017-09-13 18:05:28 -040017
AKASHI Takahiro659a6262019-09-12 13:52:35 +090018#ifdef CONFIG_SANDBOX
19const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
20#endif
21
Rob Clarkf90cb9f2017-09-13 18:05:28 -040022/* template END node: */
23static const struct efi_device_path END = {
24 .type = DEVICE_PATH_TYPE_END,
25 .sub_type = DEVICE_PATH_SUB_TYPE_END,
26 .length = sizeof(END),
27};
28
Rob Clarkf90cb9f2017-09-13 18:05:28 -040029/* template ROOT node: */
30static const struct efi_device_path_vendor ROOT = {
31 .dp = {
32 .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE,
33 .sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,
34 .length = sizeof(ROOT),
35 },
36 .guid = U_BOOT_GUID,
37};
38
Heinrich Schuchardt7d569db2017-12-11 12:56:39 +010039#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
40/*
41 * Determine if an MMC device is an SD card.
42 *
43 * @desc block device descriptor
44 * @return true if the device is an SD card
45 */
46static bool is_sd(struct blk_desc *desc)
47{
48 struct mmc *mmc = find_mmc_device(desc->devnum);
49
50 if (!mmc)
51 return false;
52
53 return IS_SD(mmc) != 0U;
54}
55#endif
56
Rob Clarkf90cb9f2017-09-13 18:05:28 -040057static void *dp_alloc(size_t sz)
58{
59 void *buf;
60
Heinrich Schuchardt468bf972018-01-19 20:24:37 +010061 if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) !=
62 EFI_SUCCESS) {
63 debug("EFI: ERROR: out of memory in %s\n", __func__);
Rob Clarkf90cb9f2017-09-13 18:05:28 -040064 return NULL;
Heinrich Schuchardt468bf972018-01-19 20:24:37 +010065 }
Rob Clarkf90cb9f2017-09-13 18:05:28 -040066
Patrick Wildtacf7bee2018-03-25 19:54:03 +020067 memset(buf, 0, sz);
Rob Clarkf90cb9f2017-09-13 18:05:28 -040068 return buf;
69}
70
71/*
72 * Iterate to next block in device-path, terminating (returning NULL)
73 * at /End* node.
74 */
75struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
76{
77 if (dp == NULL)
78 return NULL;
79 if (dp->type == DEVICE_PATH_TYPE_END)
80 return NULL;
81 dp = ((void *)dp) + dp->length;
82 if (dp->type == DEVICE_PATH_TYPE_END)
83 return NULL;
84 return (struct efi_device_path *)dp;
85}
86
87/*
88 * Compare two device-paths, stopping when the shorter of the two hits
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +020089 * an End* node. This is useful to, for example, compare a device-path
Rob Clarkf90cb9f2017-09-13 18:05:28 -040090 * representing a device with one representing a file on the device, or
91 * a device with a parent device.
92 */
Heinrich Schuchardt753e2482017-10-26 19:25:48 +020093int efi_dp_match(const struct efi_device_path *a,
94 const struct efi_device_path *b)
Rob Clarkf90cb9f2017-09-13 18:05:28 -040095{
96 while (1) {
97 int ret;
98
99 ret = memcmp(&a->length, &b->length, sizeof(a->length));
100 if (ret)
101 return ret;
102
103 ret = memcmp(a, b, a->length);
104 if (ret)
105 return ret;
106
107 a = efi_dp_next(a);
108 b = efi_dp_next(b);
109
110 if (!a || !b)
111 return 0;
112 }
113}
114
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400115/*
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200116 * We can have device paths that start with a USB WWID or a USB Class node,
117 * and a few other cases which don't encode the full device path with bus
118 * hierarchy:
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400119 *
120 * - MESSAGING:USB_WWID
121 * - MESSAGING:USB_CLASS
122 * - MEDIA:FILE_PATH
123 * - MEDIA:HARD_DRIVE
124 * - MESSAGING:URI
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200125 *
126 * See UEFI spec (section 3.1.2, about short-form device-paths)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400127 */
128static struct efi_device_path *shorten_path(struct efi_device_path *dp)
129{
130 while (dp) {
131 /*
132 * TODO: Add MESSAGING:USB_WWID and MESSAGING:URI..
133 * in practice fallback.efi just uses MEDIA:HARD_DRIVE
134 * so not sure when we would see these other cases.
135 */
136 if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
137 EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
138 EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
139 return dp;
140
141 dp = efi_dp_next(dp);
142 }
143
144 return dp;
145}
146
147static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
148 struct efi_device_path **rem)
149{
150 struct efi_object *efiobj;
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200151 efi_uintn_t dp_size = efi_dp_instance_size(dp);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400152
153 list_for_each_entry(efiobj, &efi_obj_list, link) {
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100154 struct efi_handler *handler;
155 struct efi_device_path *obj_dp;
156 efi_status_t ret;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400157
Heinrich Schuchardtadb50d02018-09-26 05:27:55 +0200158 ret = efi_search_protocol(efiobj,
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100159 &efi_guid_device_path, &handler);
160 if (ret != EFI_SUCCESS)
161 continue;
162 obj_dp = handler->protocol_interface;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400163
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100164 do {
165 if (efi_dp_match(dp, obj_dp) == 0) {
166 if (rem) {
Alexander Graff9360fb2017-12-11 14:29:46 +0100167 /*
168 * Allow partial matches, but inform
169 * the caller.
170 */
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100171 *rem = ((void *)dp) +
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200172 efi_dp_instance_size(obj_dp);
Alexander Graff9360fb2017-12-11 14:29:46 +0100173 return efiobj;
174 } else {
175 /* Only return on exact matches */
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200176 if (efi_dp_instance_size(obj_dp) ==
177 dp_size)
Alexander Graff9360fb2017-12-11 14:29:46 +0100178 return efiobj;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400179 }
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100180 }
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400181
Heinrich Schuchardt6953c102017-11-26 14:05:16 +0100182 obj_dp = shorten_path(efi_dp_next(obj_dp));
183 } while (short_path && obj_dp);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400184 }
185
186 return NULL;
187}
188
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400189/*
190 * Find an efiobj from device-path, if 'rem' is not NULL, returns the
191 * remaining part of the device path after the matched object.
192 */
193struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
194 struct efi_device_path **rem)
195{
196 struct efi_object *efiobj;
197
Alexander Graff9360fb2017-12-11 14:29:46 +0100198 /* Search for an exact match first */
199 efiobj = find_obj(dp, false, NULL);
200
201 /* Then for a fuzzy match */
202 if (!efiobj)
203 efiobj = find_obj(dp, false, rem);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400204
Alexander Graff9360fb2017-12-11 14:29:46 +0100205 /* And now for a fuzzy short match */
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400206 if (!efiobj)
207 efiobj = find_obj(dp, true, rem);
208
209 return efiobj;
210}
211
Heinrich Schuchardt0976f8b2018-01-19 20:24:49 +0100212/*
213 * Determine the last device path node that is not the end node.
214 *
215 * @dp device path
216 * @return last node before the end node if it exists
217 * otherwise NULL
218 */
219const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp)
220{
221 struct efi_device_path *ret;
222
223 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
224 return NULL;
225 while (dp) {
226 ret = (struct efi_device_path *)dp;
227 dp = efi_dp_next(dp);
228 }
229 return ret;
230}
231
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200232/* get size of the first device path instance excluding end node */
233efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400234{
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200235 efi_uintn_t sz = 0;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400236
Heinrich Schuchardt01d48ed2018-04-16 07:59:07 +0200237 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
238 return 0;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400239 while (dp) {
240 sz += dp->length;
241 dp = efi_dp_next(dp);
242 }
243
244 return sz;
245}
246
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200247/* get size of multi-instance device path excluding end node */
248efi_uintn_t efi_dp_size(const struct efi_device_path *dp)
249{
250 const struct efi_device_path *p = dp;
251
252 if (!p)
253 return 0;
254 while (p->type != DEVICE_PATH_TYPE_END ||
255 p->sub_type != DEVICE_PATH_SUB_TYPE_END)
256 p = (void *)p + p->length;
257
258 return (void *)p - (void *)dp;
259}
260
261/* copy multi-instance device path */
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400262struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
263{
264 struct efi_device_path *ndp;
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200265 size_t sz = efi_dp_size(dp) + sizeof(END);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400266
267 if (!dp)
268 return NULL;
269
270 ndp = dp_alloc(sz);
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100271 if (!ndp)
272 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400273 memcpy(ndp, dp, sz);
274
275 return ndp;
276}
277
278struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
279 const struct efi_device_path *dp2)
280{
281 struct efi_device_path *ret;
282
Heinrich Schuchardt60b5ab22018-04-16 07:59:06 +0200283 if (!dp1 && !dp2) {
284 /* return an end node */
285 ret = efi_dp_dup(&END);
286 } else if (!dp1) {
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400287 ret = efi_dp_dup(dp2);
288 } else if (!dp2) {
289 ret = efi_dp_dup(dp1);
290 } else {
291 /* both dp1 and dp2 are non-null */
292 unsigned sz1 = efi_dp_size(dp1);
293 unsigned sz2 = efi_dp_size(dp2);
294 void *p = dp_alloc(sz1 + sz2 + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100295 if (!p)
296 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400297 memcpy(p, dp1, sz1);
Heinrich Schuchardt60b5ab22018-04-16 07:59:06 +0200298 /* the end node of the second device path has to be retained */
299 memcpy(p + sz1, dp2, sz2 + sizeof(END));
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400300 ret = p;
301 }
302
303 return ret;
304}
305
306struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
307 const struct efi_device_path *node)
308{
309 struct efi_device_path *ret;
310
311 if (!node && !dp) {
312 ret = efi_dp_dup(&END);
313 } else if (!node) {
314 ret = efi_dp_dup(dp);
315 } else if (!dp) {
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200316 size_t sz = node->length;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400317 void *p = dp_alloc(sz + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100318 if (!p)
319 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400320 memcpy(p, node, sz);
321 memcpy(p + sz, &END, sizeof(END));
322 ret = p;
323 } else {
324 /* both dp and node are non-null */
Heinrich Schuchardt51ca4f52018-04-16 07:59:08 +0200325 size_t sz = efi_dp_size(dp);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400326 void *p = dp_alloc(sz + node->length + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100327 if (!p)
328 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400329 memcpy(p, dp, sz);
330 memcpy(p + sz, node, node->length);
331 memcpy(p + sz + node->length, &END, sizeof(END));
332 ret = p;
333 }
334
335 return ret;
336}
337
Heinrich Schuchardtb41c8e22018-04-16 07:59:05 +0200338struct efi_device_path *efi_dp_create_device_node(const u8 type,
339 const u8 sub_type,
340 const u16 length)
341{
342 struct efi_device_path *ret;
343
Heinrich Schuchardtc96c5942019-04-23 00:51:01 +0200344 if (length < sizeof(struct efi_device_path))
345 return NULL;
346
Heinrich Schuchardtb41c8e22018-04-16 07:59:05 +0200347 ret = dp_alloc(length);
348 if (!ret)
349 return ret;
350 ret->type = type;
351 ret->sub_type = sub_type;
352 ret->length = length;
353 return ret;
354}
355
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200356struct efi_device_path *efi_dp_append_instance(
357 const struct efi_device_path *dp,
358 const struct efi_device_path *dpi)
359{
360 size_t sz, szi;
361 struct efi_device_path *p, *ret;
362
363 if (!dpi)
364 return NULL;
365 if (!dp)
366 return efi_dp_dup(dpi);
367 sz = efi_dp_size(dp);
368 szi = efi_dp_instance_size(dpi);
369 p = dp_alloc(sz + szi + 2 * sizeof(END));
370 if (!p)
371 return NULL;
372 ret = p;
373 memcpy(p, dp, sz + sizeof(END));
374 p = (void *)p + sz;
375 p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END;
376 p = (void *)p + sizeof(END);
377 memcpy(p, dpi, szi);
378 p = (void *)p + szi;
379 memcpy(p, &END, sizeof(END));
380 return ret;
381}
382
383struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
384 efi_uintn_t *size)
385{
386 size_t sz;
387 struct efi_device_path *p;
388
389 if (size)
390 *size = 0;
391 if (!dp || !*dp)
392 return NULL;
Heinrich Schuchardtcb0f7ce2018-04-16 07:59:09 +0200393 sz = efi_dp_instance_size(*dp);
394 p = dp_alloc(sz + sizeof(END));
395 if (!p)
396 return NULL;
397 memcpy(p, *dp, sz + sizeof(END));
398 *dp = (void *)*dp + sz;
399 if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END)
400 *dp = (void *)*dp + sizeof(END);
401 else
402 *dp = NULL;
403 if (size)
404 *size = sz + sizeof(END);
405 return p;
406}
407
408bool efi_dp_is_multi_instance(const struct efi_device_path *dp)
409{
410 const struct efi_device_path *p = dp;
411
412 if (!p)
413 return false;
414 while (p->type != DEVICE_PATH_TYPE_END)
415 p = (void *)p + p->length;
416 return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END;
417}
418
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400419#ifdef CONFIG_DM
420/* size of device-path not including END node for device and all parents
421 * up to the root device.
422 */
423static unsigned dp_size(struct udevice *dev)
424{
425 if (!dev || !dev->driver)
426 return sizeof(ROOT);
427
428 switch (dev->driver->id) {
429 case UCLASS_ROOT:
430 case UCLASS_SIMPLE_BUS:
431 /* stop traversing parents at this point: */
432 return sizeof(ROOT);
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100433 case UCLASS_ETH:
434 return dp_size(dev->parent) +
435 sizeof(struct efi_device_path_mac_addr);
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100436#ifdef CONFIG_BLK
437 case UCLASS_BLK:
438 switch (dev->parent->uclass->uc_drv->id) {
439#ifdef CONFIG_IDE
440 case UCLASS_IDE:
441 return dp_size(dev->parent) +
442 sizeof(struct efi_device_path_atapi);
443#endif
444#if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
445 case UCLASS_SCSI:
446 return dp_size(dev->parent) +
447 sizeof(struct efi_device_path_scsi);
448#endif
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100449#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
450 case UCLASS_MMC:
451 return dp_size(dev->parent) +
452 sizeof(struct efi_device_path_sd_mmc_path);
453#endif
AKASHI Takahiro659a6262019-09-12 13:52:35 +0900454#ifdef CONFIG_SANDBOX
455 case UCLASS_ROOT:
456 /*
457 * Sandbox's host device will be represented
458 * as vendor device with extra one byte for
459 * device number
460 */
461 return dp_size(dev->parent)
462 + sizeof(struct efi_device_path_vendor) + 1;
463#endif
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100464 default:
465 return dp_size(dev->parent);
466 }
467#endif
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100468#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400469 case UCLASS_MMC:
470 return dp_size(dev->parent) +
471 sizeof(struct efi_device_path_sd_mmc_path);
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100472#endif
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400473 case UCLASS_MASS_STORAGE:
474 case UCLASS_USB_HUB:
475 return dp_size(dev->parent) +
476 sizeof(struct efi_device_path_usb_class);
477 default:
478 /* just skip over unknown classes: */
479 return dp_size(dev->parent);
480 }
481}
482
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100483/*
484 * Recursively build a device path.
485 *
486 * @buf pointer to the end of the device path
487 * @dev device
488 * @return pointer to the end of the device path
489 */
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400490static void *dp_fill(void *buf, struct udevice *dev)
491{
492 if (!dev || !dev->driver)
493 return buf;
494
495 switch (dev->driver->id) {
496 case UCLASS_ROOT:
497 case UCLASS_SIMPLE_BUS: {
498 /* stop traversing parents at this point: */
499 struct efi_device_path_vendor *vdp = buf;
500 *vdp = ROOT;
501 return &vdp[1];
502 }
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100503#ifdef CONFIG_DM_ETH
504 case UCLASS_ETH: {
505 struct efi_device_path_mac_addr *dp =
506 dp_fill(buf, dev->parent);
507 struct eth_pdata *pdata = dev->platdata;
508
509 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
510 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
511 dp->dp.length = sizeof(*dp);
512 memset(&dp->mac, 0, sizeof(dp->mac));
513 /* We only support IPv4 */
514 memcpy(&dp->mac, &pdata->enetaddr, ARP_HLEN);
515 /* Ethernet */
516 dp->if_type = 1;
517 return &dp[1];
518 }
519#endif
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100520#ifdef CONFIG_BLK
521 case UCLASS_BLK:
522 switch (dev->parent->uclass->uc_drv->id) {
AKASHI Takahiro659a6262019-09-12 13:52:35 +0900523#ifdef CONFIG_SANDBOX
524 case UCLASS_ROOT: {
525 /* stop traversing parents at this point: */
526 struct efi_device_path_vendor *dp = buf;
527 struct blk_desc *desc = dev_get_uclass_platdata(dev);
528
529 dp_fill(buf, dev->parent);
530 dp = buf;
531 ++dp;
532 dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
533 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
534 dp->dp.length = sizeof(*dp) + 1;
535 memcpy(&dp->guid, &efi_guid_host_dev,
536 sizeof(efi_guid_t));
537 dp->vendor_data[0] = desc->devnum;
538 return &dp->vendor_data[1];
539 }
540#endif
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100541#ifdef CONFIG_IDE
542 case UCLASS_IDE: {
543 struct efi_device_path_atapi *dp =
544 dp_fill(buf, dev->parent);
545 struct blk_desc *desc = dev_get_uclass_platdata(dev);
546
547 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
548 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_ATAPI;
549 dp->dp.length = sizeof(*dp);
550 dp->logical_unit_number = desc->devnum;
551 dp->primary_secondary = IDE_BUS(desc->devnum);
552 dp->slave_master = desc->devnum %
553 (CONFIG_SYS_IDE_MAXDEVICE /
554 CONFIG_SYS_IDE_MAXBUS);
555 return &dp[1];
556 }
557#endif
558#if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
559 case UCLASS_SCSI: {
560 struct efi_device_path_scsi *dp =
561 dp_fill(buf, dev->parent);
562 struct blk_desc *desc = dev_get_uclass_platdata(dev);
563
564 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
565 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
566 dp->dp.length = sizeof(*dp);
567 dp->logical_unit_number = desc->lun;
568 dp->target_id = desc->target;
569 return &dp[1];
570 }
571#endif
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100572#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
573 case UCLASS_MMC: {
574 struct efi_device_path_sd_mmc_path *sddp =
575 dp_fill(buf, dev->parent);
576 struct blk_desc *desc = dev_get_uclass_platdata(dev);
577
578 sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
579 sddp->dp.sub_type = is_sd(desc) ?
580 DEVICE_PATH_SUB_TYPE_MSG_SD :
581 DEVICE_PATH_SUB_TYPE_MSG_MMC;
582 sddp->dp.length = sizeof(*sddp);
583 sddp->slot_number = dev->seq;
584 return &sddp[1];
585 }
586#endif
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100587 default:
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100588 debug("%s(%u) %s: unhandled parent class: %s (%u)\n",
589 __FILE__, __LINE__, __func__,
590 dev->name, dev->parent->uclass->uc_drv->id);
Heinrich Schuchardte2dcb9a2017-12-11 12:56:44 +0100591 return dp_fill(buf, dev->parent);
592 }
593#endif
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400594#if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
595 case UCLASS_MMC: {
596 struct efi_device_path_sd_mmc_path *sddp =
597 dp_fill(buf, dev->parent);
598 struct mmc *mmc = mmc_get_mmc_dev(dev);
599 struct blk_desc *desc = mmc_get_blk_desc(mmc);
600
601 sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
Heinrich Schuchardt7d569db2017-12-11 12:56:39 +0100602 sddp->dp.sub_type = is_sd(desc) ?
603 DEVICE_PATH_SUB_TYPE_MSG_SD :
604 DEVICE_PATH_SUB_TYPE_MSG_MMC;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400605 sddp->dp.length = sizeof(*sddp);
606 sddp->slot_number = dev->seq;
607
608 return &sddp[1];
609 }
610#endif
611 case UCLASS_MASS_STORAGE:
612 case UCLASS_USB_HUB: {
613 struct efi_device_path_usb_class *udp =
614 dp_fill(buf, dev->parent);
615 struct usb_device *udev = dev_get_parent_priv(dev);
616 struct usb_device_descriptor *desc = &udev->descriptor;
617
618 udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
619 udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS;
620 udp->dp.length = sizeof(*udp);
621 udp->vendor_id = desc->idVendor;
622 udp->product_id = desc->idProduct;
623 udp->device_class = desc->bDeviceClass;
624 udp->device_subclass = desc->bDeviceSubClass;
625 udp->device_protocol = desc->bDeviceProtocol;
626
627 return &udp[1];
628 }
629 default:
Heinrich Schuchardt1f1d49d2018-01-20 21:02:18 +0100630 debug("%s(%u) %s: unhandled device class: %s (%u)\n",
631 __FILE__, __LINE__, __func__,
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400632 dev->name, dev->driver->id);
633 return dp_fill(buf, dev->parent);
634 }
635}
636
637/* Construct a device-path from a device: */
638struct efi_device_path *efi_dp_from_dev(struct udevice *dev)
639{
640 void *buf, *start;
641
642 start = buf = dp_alloc(dp_size(dev) + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100643 if (!buf)
644 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400645 buf = dp_fill(buf, dev);
646 *((struct efi_device_path *)buf) = END;
647
648 return start;
649}
650#endif
651
652static unsigned dp_part_size(struct blk_desc *desc, int part)
653{
654 unsigned dpsize;
655
656#ifdef CONFIG_BLK
Heinrich Schuchardt3a615c82017-12-11 12:56:43 +0100657 {
658 struct udevice *dev;
659 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
660
661 if (ret)
662 dev = desc->bdev->parent;
663 dpsize = dp_size(dev);
664 }
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400665#else
666 dpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);
667#endif
668
669 if (part == 0) /* the actual disk, not a partition */
670 return dpsize;
671
672 if (desc->part_type == PART_TYPE_ISO)
673 dpsize += sizeof(struct efi_device_path_cdrom_path);
674 else
675 dpsize += sizeof(struct efi_device_path_hard_drive_path);
676
677 return dpsize;
678}
679
Heinrich Schuchardt8983ffd2017-12-11 12:56:42 +0100680/*
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100681 * Create a device node for a block device partition.
Heinrich Schuchardt8983ffd2017-12-11 12:56:42 +0100682 *
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200683 * @buf buffer to which the device path is written
Heinrich Schuchardt8983ffd2017-12-11 12:56:42 +0100684 * @desc block device descriptor
685 * @part partition number, 0 identifies a block device
686 */
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100687static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400688{
689 disk_partition_t info;
690
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400691 part_get_info(desc, part, &info);
692
693 if (desc->part_type == PART_TYPE_ISO) {
694 struct efi_device_path_cdrom_path *cddp = buf;
695
Heinrich Schuchardt2aae6db2017-12-11 12:56:40 +0100696 cddp->boot_entry = part;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400697 cddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
698 cddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH;
699 cddp->dp.length = sizeof(*cddp);
700 cddp->partition_start = info.start;
Heinrich Schuchardt28dfd1a2019-09-04 13:56:01 +0200701 cddp->partition_size = info.size;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400702
703 buf = &cddp[1];
704 } else {
705 struct efi_device_path_hard_drive_path *hddp = buf;
706
707 hddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
708 hddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH;
709 hddp->dp.length = sizeof(*hddp);
Heinrich Schuchardt2aae6db2017-12-11 12:56:40 +0100710 hddp->partition_number = part;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400711 hddp->partition_start = info.start;
712 hddp->partition_end = info.size;
713 if (desc->part_type == PART_TYPE_EFI)
714 hddp->partmap_type = 2;
715 else
716 hddp->partmap_type = 1;
Jonathan Gray84b4d702017-11-22 14:18:59 +1100717
718 switch (desc->sig_type) {
719 case SIG_TYPE_NONE:
720 default:
721 hddp->signature_type = 0;
722 memset(hddp->partition_signature, 0,
723 sizeof(hddp->partition_signature));
724 break;
725 case SIG_TYPE_MBR:
726 hddp->signature_type = 1;
727 memset(hddp->partition_signature, 0,
728 sizeof(hddp->partition_signature));
729 memcpy(hddp->partition_signature, &desc->mbr_sig,
730 sizeof(desc->mbr_sig));
731 break;
732 case SIG_TYPE_GUID:
733 hddp->signature_type = 2;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400734 memcpy(hddp->partition_signature, &desc->guid_sig,
735 sizeof(hddp->partition_signature));
Jonathan Gray84b4d702017-11-22 14:18:59 +1100736 break;
737 }
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400738
739 buf = &hddp[1];
740 }
741
742 return buf;
743}
744
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100745/*
746 * Create a device path for a block device or one of its partitions.
747 *
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200748 * @buf buffer to which the device path is written
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100749 * @desc block device descriptor
750 * @part partition number, 0 identifies a block device
751 */
752static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
753{
754#ifdef CONFIG_BLK
755 {
756 struct udevice *dev;
757 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
758
759 if (ret)
760 dev = desc->bdev->parent;
761 buf = dp_fill(buf, dev);
762 }
763#else
764 /*
765 * We *could* make a more accurate path, by looking at if_type
766 * and handling all the different cases like we do for non-
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200767 * legacy (i.e. CONFIG_BLK=y) case. But most important thing
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100768 * is just to have a unique device-path for if_type+devnum.
769 * So map things to a fictitious USB device.
770 */
771 struct efi_device_path_usb *udp;
772
773 memcpy(buf, &ROOT, sizeof(ROOT));
774 buf += sizeof(ROOT);
775
776 udp = buf;
777 udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
778 udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB;
779 udp->dp.length = sizeof(*udp);
780 udp->parent_port_number = desc->if_type;
781 udp->usb_interface = desc->devnum;
782 buf = &udp[1];
783#endif
784
785 if (part == 0) /* the actual disk, not a partition */
786 return buf;
787
788 return dp_part_node(buf, desc, part);
789}
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400790
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200791/* Construct a device-path from a partition on a block device: */
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400792struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
793{
794 void *buf, *start;
795
796 start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100797 if (!buf)
798 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400799
800 buf = dp_part_fill(buf, desc, part);
801
802 *((struct efi_device_path *)buf) = END;
803
804 return start;
805}
806
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100807/*
808 * Create a device node for a block device partition.
809 *
Heinrich Schuchardtb21f8392018-10-17 21:55:24 +0200810 * @buf buffer to which the device path is written
Heinrich Schuchardt6c6307c2018-01-19 20:24:46 +0100811 * @desc block device descriptor
812 * @part partition number, 0 identifies a block device
813 */
814struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
815{
816 efi_uintn_t dpsize;
817 void *buf;
818
819 if (desc->part_type == PART_TYPE_ISO)
820 dpsize = sizeof(struct efi_device_path_cdrom_path);
821 else
822 dpsize = sizeof(struct efi_device_path_hard_drive_path);
823 buf = dp_alloc(dpsize);
824
825 dp_part_node(buf, desc, part);
826
827 return buf;
828}
829
Heinrich Schuchardt8d80af82019-07-14 19:26:47 +0200830/**
831 * path_to_uefi() - convert UTF-8 path to an UEFI style path
832 *
833 * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path
834 * separators and UTF-16).
835 *
836 * @src: source buffer
837 * @uefi: target buffer, possibly unaligned
838 */
839static void path_to_uefi(void *uefi, const char *src)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400840{
Heinrich Schuchardt8d80af82019-07-14 19:26:47 +0200841 u16 *pos = uefi;
842
843 /*
844 * efi_set_bootdev() calls this routine indirectly before the UEFI
845 * subsystem is initialized. So we cannot assume unaligned access to be
846 * enabled.
847 */
848 allow_unaligned();
849
850 while (*src) {
851 s32 code = utf8_get(&src);
852
853 if (code < 0)
854 code = '?';
855 else if (code == '/')
856 code = '\\';
857 utf16_put(code, &pos);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400858 }
Heinrich Schuchardt8d80af82019-07-14 19:26:47 +0200859 *pos = 0;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400860}
861
862/*
863 * If desc is NULL, this creates a path with only the file component,
864 * otherwise it creates a full path with both device and file components
865 */
866struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
867 const char *path)
868{
869 struct efi_device_path_file_path *fp;
870 void *buf, *start;
871 unsigned dpsize = 0, fpsize;
872
873 if (desc)
874 dpsize = dp_part_size(desc, part);
875
Heinrich Schuchardt8d80af82019-07-14 19:26:47 +0200876 fpsize = sizeof(struct efi_device_path) +
877 2 * (utf8_utf16_strlen(path) + 1);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400878 dpsize += fpsize;
879
880 start = buf = dp_alloc(dpsize + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100881 if (!buf)
882 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400883
884 if (desc)
885 buf = dp_part_fill(buf, desc, part);
886
887 /* add file-path: */
888 fp = buf;
889 fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
890 fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
891 fp->dp.length = fpsize;
892 path_to_uefi(fp->str, path);
893 buf += fpsize;
894
895 *((struct efi_device_path *)buf) = END;
896
897 return start;
898}
899
Joe Hershberger5277a972018-04-13 15:26:39 -0500900#ifdef CONFIG_NET
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400901struct efi_device_path *efi_dp_from_eth(void)
902{
Alexander Grafc4e983f2018-03-15 17:33:38 +0100903#ifndef CONFIG_DM_ETH
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400904 struct efi_device_path_mac_addr *ndp;
Alexander Grafc4e983f2018-03-15 17:33:38 +0100905#endif
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400906 void *buf, *start;
907 unsigned dpsize = 0;
908
909 assert(eth_get_dev());
910
911#ifdef CONFIG_DM_ETH
912 dpsize += dp_size(eth_get_dev());
913#else
914 dpsize += sizeof(ROOT);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400915 dpsize += sizeof(*ndp);
Alexander Grafc4e983f2018-03-15 17:33:38 +0100916#endif
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400917
918 start = buf = dp_alloc(dpsize + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100919 if (!buf)
920 return NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400921
922#ifdef CONFIG_DM_ETH
923 buf = dp_fill(buf, eth_get_dev());
924#else
925 memcpy(buf, &ROOT, sizeof(ROOT));
926 buf += sizeof(ROOT);
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400927
928 ndp = buf;
929 ndp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
930 ndp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
931 ndp->dp.length = sizeof(*ndp);
Alexander Grafc4e983f2018-03-15 17:33:38 +0100932 ndp->if_type = 1; /* Ethernet */
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400933 memcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);
934 buf = &ndp[1];
Alexander Grafc4e983f2018-03-15 17:33:38 +0100935#endif
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400936
937 *((struct efi_device_path *)buf) = END;
938
939 return start;
940}
941#endif
942
Rob Clark18ceba72017-10-10 08:23:06 -0400943/* Construct a device-path for memory-mapped image */
944struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
945 uint64_t start_address,
946 uint64_t end_address)
947{
948 struct efi_device_path_memory *mdp;
949 void *buf, *start;
950
951 start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100952 if (!buf)
953 return NULL;
Rob Clark18ceba72017-10-10 08:23:06 -0400954
955 mdp = buf;
956 mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
957 mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY;
958 mdp->dp.length = sizeof(*mdp);
959 mdp->memory_type = memory_type;
960 mdp->start_address = start_address;
961 mdp->end_address = end_address;
962 buf = &mdp[1];
963
964 *((struct efi_device_path *)buf) = END;
965
966 return start;
967}
968
Heinrich Schuchardt0d36adc2019-02-04 12:49:43 +0100969/**
970 * efi_dp_split_file_path() - split of relative file path from device path
971 *
972 * Given a device path indicating a file on a device, separate the device
973 * path in two: the device path of the actual device and the file path
974 * relative to this device.
975 *
976 * @full_path: device path including device and file path
977 * @device_path: path of the device
AKASHI Takahiro9c6531f2019-04-16 17:39:26 +0200978 * @file_path: relative path of the file or NULL if there is none
Heinrich Schuchardt0d36adc2019-02-04 12:49:43 +0100979 * Return: status code
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400980 */
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100981efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
982 struct efi_device_path **device_path,
983 struct efi_device_path **file_path)
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400984{
AKASHI Takahiro9c6531f2019-04-16 17:39:26 +0200985 struct efi_device_path *p, *dp, *fp = NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400986
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100987 *device_path = NULL;
988 *file_path = NULL;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400989 dp = efi_dp_dup(full_path);
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100990 if (!dp)
991 return EFI_OUT_OF_RESOURCES;
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400992 p = dp;
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100993 while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) {
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400994 p = efi_dp_next(p);
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100995 if (!p)
AKASHI Takahiro9c6531f2019-04-16 17:39:26 +0200996 goto out;
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100997 }
Rob Clarkf90cb9f2017-09-13 18:05:28 -0400998 fp = efi_dp_dup(p);
Heinrich Schuchardt468bf972018-01-19 20:24:37 +0100999 if (!fp)
1000 return EFI_OUT_OF_RESOURCES;
Rob Clarkf90cb9f2017-09-13 18:05:28 -04001001 p->type = DEVICE_PATH_TYPE_END;
1002 p->sub_type = DEVICE_PATH_SUB_TYPE_END;
1003 p->length = sizeof(*p);
1004
AKASHI Takahiro9c6531f2019-04-16 17:39:26 +02001005out:
Rob Clarkf90cb9f2017-09-13 18:05:28 -04001006 *device_path = dp;
1007 *file_path = fp;
Heinrich Schuchardt468bf972018-01-19 20:24:37 +01001008 return EFI_SUCCESS;
Rob Clarkf90cb9f2017-09-13 18:05:28 -04001009}
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001010
1011efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
1012 const char *path,
1013 struct efi_device_path **device,
1014 struct efi_device_path **file)
1015{
1016 int is_net;
1017 struct blk_desc *desc = NULL;
1018 disk_partition_t fs_partition;
1019 int part = 0;
1020 char filename[32] = { 0 }; /* dp->str is u16[32] long */
1021 char *s;
1022
AKASHI Takahiro39844412018-11-05 18:06:40 +09001023 if (path && !file)
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001024 return EFI_INVALID_PARAMETER;
1025
1026 is_net = !strcmp(dev, "Net");
1027 if (!is_net) {
1028 part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
1029 1);
Patrick Delaunayba7a9502019-04-10 11:02:58 +02001030 if (part < 0 || !desc)
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001031 return EFI_INVALID_PARAMETER;
1032
AKASHI Takahiro39844412018-11-05 18:06:40 +09001033 if (device)
1034 *device = efi_dp_from_part(desc, part);
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001035 } else {
1036#ifdef CONFIG_NET
AKASHI Takahiro39844412018-11-05 18:06:40 +09001037 if (device)
1038 *device = efi_dp_from_eth();
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001039#endif
1040 }
1041
1042 if (!path)
1043 return EFI_SUCCESS;
1044
Heinrich Schuchardt7d698072019-02-23 11:20:23 +01001045 snprintf(filename, sizeof(filename), "%s", path);
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001046 /* DOS style file path: */
1047 s = filename;
1048 while ((s = strchr(s, '/')))
1049 *s++ = '\\';
AKASHI Takahiro39844412018-11-05 18:06:40 +09001050 *file = efi_dp_from_file(((!is_net && device) ? desc : NULL),
1051 part, filename);
AKASHI Takahiro035fb012018-10-17 16:32:03 +09001052
1053 return EFI_SUCCESS;
1054}