1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * EFI device path from u-boot device-model mapping
4  *
5  * (C) Copyright 2017 Rob Clark
6  */
7 
8 #include <common.h>
9 #include <blk.h>
10 #include <dm.h>
11 #include <log.h>
12 #include <net.h>
13 #include <usb.h>
14 #include <mmc.h>
15 #include <nvme.h>
16 #include <efi_loader.h>
17 #include <part.h>
18 #include <sandboxblockdev.h>
19 #include <asm-generic/unaligned.h>
20 #include <linux/compat.h> /* U16_MAX */
21 
22 #ifdef CONFIG_SANDBOX
23 const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
24 #endif
25 #ifdef CONFIG_VIRTIO_BLK
26 const efi_guid_t efi_guid_virtio_dev = U_BOOT_VIRTIO_DEV_GUID;
27 #endif
28 
29 /* template END node: */
30 static const struct efi_device_path END = {
31 	.type     = DEVICE_PATH_TYPE_END,
32 	.sub_type = DEVICE_PATH_SUB_TYPE_END,
33 	.length   = sizeof(END),
34 };
35 
36 /* template ROOT node: */
37 static const struct efi_device_path_vendor ROOT = {
38 	.dp = {
39 		.type     = DEVICE_PATH_TYPE_HARDWARE_DEVICE,
40 		.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,
41 		.length   = sizeof(ROOT),
42 	},
43 	.guid = U_BOOT_GUID,
44 };
45 
46 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
47 /*
48  * Determine if an MMC device is an SD card.
49  *
50  * @desc	block device descriptor
51  * @return	true if the device is an SD card
52  */
is_sd(struct blk_desc * desc)53 static bool is_sd(struct blk_desc *desc)
54 {
55 	struct mmc *mmc = find_mmc_device(desc->devnum);
56 
57 	if (!mmc)
58 		return false;
59 
60 	return IS_SD(mmc) != 0U;
61 }
62 #endif
63 
dp_alloc(size_t sz)64 static void *dp_alloc(size_t sz)
65 {
66 	void *buf;
67 
68 	if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) !=
69 	    EFI_SUCCESS) {
70 		debug("EFI: ERROR: out of memory in %s\n", __func__);
71 		return NULL;
72 	}
73 
74 	memset(buf, 0, sz);
75 	return buf;
76 }
77 
78 /*
79  * Iterate to next block in device-path, terminating (returning NULL)
80  * at /End* node.
81  */
efi_dp_next(const struct efi_device_path * dp)82 struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
83 {
84 	if (dp == NULL)
85 		return NULL;
86 	if (dp->type == DEVICE_PATH_TYPE_END)
87 		return NULL;
88 	dp = ((void *)dp) + dp->length;
89 	if (dp->type == DEVICE_PATH_TYPE_END)
90 		return NULL;
91 	return (struct efi_device_path *)dp;
92 }
93 
94 /*
95  * Compare two device-paths, stopping when the shorter of the two hits
96  * an End* node. This is useful to, for example, compare a device-path
97  * representing a device with one representing a file on the device, or
98  * a device with a parent device.
99  */
efi_dp_match(const struct efi_device_path * a,const struct efi_device_path * b)100 int efi_dp_match(const struct efi_device_path *a,
101 		 const struct efi_device_path *b)
102 {
103 	while (1) {
104 		int ret;
105 
106 		ret = memcmp(&a->length, &b->length, sizeof(a->length));
107 		if (ret)
108 			return ret;
109 
110 		ret = memcmp(a, b, a->length);
111 		if (ret)
112 			return ret;
113 
114 		a = efi_dp_next(a);
115 		b = efi_dp_next(b);
116 
117 		if (!a || !b)
118 			return 0;
119 	}
120 }
121 
122 /*
123  * We can have device paths that start with a USB WWID or a USB Class node,
124  * and a few other cases which don't encode the full device path with bus
125  * hierarchy:
126  *
127  *   - MESSAGING:USB_WWID
128  *   - MESSAGING:USB_CLASS
129  *   - MEDIA:FILE_PATH
130  *   - MEDIA:HARD_DRIVE
131  *   - MESSAGING:URI
132  *
133  * See UEFI spec (section 3.1.2, about short-form device-paths)
134  */
shorten_path(struct efi_device_path * dp)135 static struct efi_device_path *shorten_path(struct efi_device_path *dp)
136 {
137 	while (dp) {
138 		/*
139 		 * TODO: Add MESSAGING:USB_WWID and MESSAGING:URI..
140 		 * in practice fallback.efi just uses MEDIA:HARD_DRIVE
141 		 * so not sure when we would see these other cases.
142 		 */
143 		if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
144 		    EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
145 		    EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
146 			return dp;
147 
148 		dp = efi_dp_next(dp);
149 	}
150 
151 	return dp;
152 }
153 
find_obj(struct efi_device_path * dp,bool short_path,struct efi_device_path ** rem)154 static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
155 				   struct efi_device_path **rem)
156 {
157 	struct efi_object *efiobj;
158 	efi_uintn_t dp_size = efi_dp_instance_size(dp);
159 
160 	list_for_each_entry(efiobj, &efi_obj_list, link) {
161 		struct efi_handler *handler;
162 		struct efi_device_path *obj_dp;
163 		efi_status_t ret;
164 
165 		ret = efi_search_protocol(efiobj,
166 					  &efi_guid_device_path, &handler);
167 		if (ret != EFI_SUCCESS)
168 			continue;
169 		obj_dp = handler->protocol_interface;
170 
171 		do {
172 			if (efi_dp_match(dp, obj_dp) == 0) {
173 				if (rem) {
174 					/*
175 					 * Allow partial matches, but inform
176 					 * the caller.
177 					 */
178 					*rem = ((void *)dp) +
179 						efi_dp_instance_size(obj_dp);
180 					return efiobj;
181 				} else {
182 					/* Only return on exact matches */
183 					if (efi_dp_instance_size(obj_dp) ==
184 					    dp_size)
185 						return efiobj;
186 				}
187 			}
188 
189 			obj_dp = shorten_path(efi_dp_next(obj_dp));
190 		} while (short_path && obj_dp);
191 	}
192 
193 	return NULL;
194 }
195 
196 /*
197  * Find an efiobj from device-path, if 'rem' is not NULL, returns the
198  * remaining part of the device path after the matched object.
199  */
efi_dp_find_obj(struct efi_device_path * dp,struct efi_device_path ** rem)200 struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
201 				   struct efi_device_path **rem)
202 {
203 	struct efi_object *efiobj;
204 
205 	/* Search for an exact match first */
206 	efiobj = find_obj(dp, false, NULL);
207 
208 	/* Then for a fuzzy match */
209 	if (!efiobj)
210 		efiobj = find_obj(dp, false, rem);
211 
212 	/* And now for a fuzzy short match */
213 	if (!efiobj)
214 		efiobj = find_obj(dp, true, rem);
215 
216 	return efiobj;
217 }
218 
219 /*
220  * Determine the last device path node that is not the end node.
221  *
222  * @dp		device path
223  * @return	last node before the end node if it exists
224  *		otherwise NULL
225  */
efi_dp_last_node(const struct efi_device_path * dp)226 const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp)
227 {
228 	struct efi_device_path *ret;
229 
230 	if (!dp || dp->type == DEVICE_PATH_TYPE_END)
231 		return NULL;
232 	while (dp) {
233 		ret = (struct efi_device_path *)dp;
234 		dp = efi_dp_next(dp);
235 	}
236 	return ret;
237 }
238 
239 /* get size of the first device path instance excluding end node */
efi_dp_instance_size(const struct efi_device_path * dp)240 efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp)
241 {
242 	efi_uintn_t sz = 0;
243 
244 	if (!dp || dp->type == DEVICE_PATH_TYPE_END)
245 		return 0;
246 	while (dp) {
247 		sz += dp->length;
248 		dp = efi_dp_next(dp);
249 	}
250 
251 	return sz;
252 }
253 
254 /* get size of multi-instance device path excluding end node */
efi_dp_size(const struct efi_device_path * dp)255 efi_uintn_t efi_dp_size(const struct efi_device_path *dp)
256 {
257 	const struct efi_device_path *p = dp;
258 
259 	if (!p)
260 		return 0;
261 	while (p->type != DEVICE_PATH_TYPE_END ||
262 	       p->sub_type != DEVICE_PATH_SUB_TYPE_END)
263 		p = (void *)p + p->length;
264 
265 	return (void *)p - (void *)dp;
266 }
267 
268 /* copy multi-instance device path */
efi_dp_dup(const struct efi_device_path * dp)269 struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
270 {
271 	struct efi_device_path *ndp;
272 	size_t sz = efi_dp_size(dp) + sizeof(END);
273 
274 	if (!dp)
275 		return NULL;
276 
277 	ndp = dp_alloc(sz);
278 	if (!ndp)
279 		return NULL;
280 	memcpy(ndp, dp, sz);
281 
282 	return ndp;
283 }
284 
285 /**
286  * efi_dp_append_or_concatenate() - Append or concatenate two device paths.
287  *				    Concatenated device path will be separated
288  *				    by a sub-type 0xff end node
289  *
290  * @dp1:	First device path
291  * @dp2:	Second device path
292  * @concat:	If true the two device paths will be concatenated and separated
293  *		by an end of entrire device path sub-type 0xff end node.
294  *		If true the second device path will be appended to the first and
295  *		terminated by an end node
296  *
297  * Return:
298  * concatenated device path or NULL. Caller must free the returned value
299  */
300 static struct
efi_dp_append_or_concatenate(const struct efi_device_path * dp1,const struct efi_device_path * dp2,bool concat)301 efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path *dp1,
302 					      const struct efi_device_path *dp2,
303 					      bool concat)
304 {
305 	struct efi_device_path *ret;
306 	size_t end_size = sizeof(END);
307 
308 	if (concat)
309 		end_size = 2 * sizeof(END);
310 	if (!dp1 && !dp2) {
311 		/* return an end node */
312 		ret = efi_dp_dup(&END);
313 	} else if (!dp1) {
314 		ret = efi_dp_dup(dp2);
315 	} else if (!dp2) {
316 		ret = efi_dp_dup(dp1);
317 	} else {
318 		/* both dp1 and dp2 are non-null */
319 		unsigned sz1 = efi_dp_size(dp1);
320 		unsigned sz2 = efi_dp_size(dp2);
321 		void *p = dp_alloc(sz1 + sz2 + end_size);
322 		if (!p)
323 			return NULL;
324 		ret = p;
325 		memcpy(p, dp1, sz1);
326 		p += sz1;
327 
328 		if (concat) {
329 			memcpy(p, &END, sizeof(END));
330 			p += sizeof(END);
331 		}
332 
333 		/* the end node of the second device path has to be retained */
334 		memcpy(p, dp2, sz2);
335 		p += sz2;
336 		memcpy(p, &END, sizeof(END));
337 	}
338 
339 	return ret;
340 }
341 
342 /**
343  * efi_dp_append() - Append a device to an existing device path.
344  *
345  * @dp1:	First device path
346  * @dp2:	Second device path
347  *
348  * Return:
349  * concatenated device path or NULL. Caller must free the returned value
350  */
efi_dp_append(const struct efi_device_path * dp1,const struct efi_device_path * dp2)351 struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
352 				      const struct efi_device_path *dp2)
353 {
354 	return efi_dp_append_or_concatenate(dp1, dp2, false);
355 }
356 
357 /**
358  * efi_dp_concat() - Concatenate 2 device paths. The final device path will
359  *                   contain two device paths separated by and end node (0xff).
360  *
361  * @dp1:	First device path
362  * @dp2:	Second device path
363  *
364  * Return:
365  * concatenated device path or NULL. Caller must free the returned value
366  */
efi_dp_concat(const struct efi_device_path * dp1,const struct efi_device_path * dp2)367 struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1,
368 				      const struct efi_device_path *dp2)
369 {
370 	return efi_dp_append_or_concatenate(dp1, dp2, true);
371 }
372 
efi_dp_append_node(const struct efi_device_path * dp,const struct efi_device_path * node)373 struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
374 					   const struct efi_device_path *node)
375 {
376 	struct efi_device_path *ret;
377 
378 	if (!node && !dp) {
379 		ret = efi_dp_dup(&END);
380 	} else if (!node) {
381 		ret = efi_dp_dup(dp);
382 	} else if (!dp) {
383 		size_t sz = node->length;
384 		void *p = dp_alloc(sz + sizeof(END));
385 		if (!p)
386 			return NULL;
387 		memcpy(p, node, sz);
388 		memcpy(p + sz, &END, sizeof(END));
389 		ret = p;
390 	} else {
391 		/* both dp and node are non-null */
392 		size_t sz = efi_dp_size(dp);
393 		void *p = dp_alloc(sz + node->length + sizeof(END));
394 		if (!p)
395 			return NULL;
396 		memcpy(p, dp, sz);
397 		memcpy(p + sz, node, node->length);
398 		memcpy(p + sz + node->length, &END, sizeof(END));
399 		ret = p;
400 	}
401 
402 	return ret;
403 }
404 
efi_dp_create_device_node(const u8 type,const u8 sub_type,const u16 length)405 struct efi_device_path *efi_dp_create_device_node(const u8 type,
406 						  const u8 sub_type,
407 						  const u16 length)
408 {
409 	struct efi_device_path *ret;
410 
411 	if (length < sizeof(struct efi_device_path))
412 		return NULL;
413 
414 	ret = dp_alloc(length);
415 	if (!ret)
416 		return ret;
417 	ret->type = type;
418 	ret->sub_type = sub_type;
419 	ret->length = length;
420 	return ret;
421 }
422 
efi_dp_append_instance(const struct efi_device_path * dp,const struct efi_device_path * dpi)423 struct efi_device_path *efi_dp_append_instance(
424 		const struct efi_device_path *dp,
425 		const struct efi_device_path *dpi)
426 {
427 	size_t sz, szi;
428 	struct efi_device_path *p, *ret;
429 
430 	if (!dpi)
431 		return NULL;
432 	if (!dp)
433 		return efi_dp_dup(dpi);
434 	sz = efi_dp_size(dp);
435 	szi = efi_dp_instance_size(dpi);
436 	p = dp_alloc(sz + szi + 2 * sizeof(END));
437 	if (!p)
438 		return NULL;
439 	ret = p;
440 	memcpy(p, dp, sz + sizeof(END));
441 	p = (void *)p + sz;
442 	p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END;
443 	p = (void *)p + sizeof(END);
444 	memcpy(p, dpi, szi);
445 	p = (void *)p + szi;
446 	memcpy(p, &END, sizeof(END));
447 	return ret;
448 }
449 
efi_dp_get_next_instance(struct efi_device_path ** dp,efi_uintn_t * size)450 struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
451 						 efi_uintn_t *size)
452 {
453 	size_t sz;
454 	struct efi_device_path *p;
455 
456 	if (size)
457 		*size = 0;
458 	if (!dp || !*dp)
459 		return NULL;
460 	sz = efi_dp_instance_size(*dp);
461 	p = dp_alloc(sz + sizeof(END));
462 	if (!p)
463 		return NULL;
464 	memcpy(p, *dp, sz + sizeof(END));
465 	*dp = (void *)*dp + sz;
466 	if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END)
467 		*dp = (void *)*dp + sizeof(END);
468 	else
469 		*dp = NULL;
470 	if (size)
471 		*size = sz + sizeof(END);
472 	return p;
473 }
474 
efi_dp_is_multi_instance(const struct efi_device_path * dp)475 bool efi_dp_is_multi_instance(const struct efi_device_path *dp)
476 {
477 	const struct efi_device_path *p = dp;
478 
479 	if (!p)
480 		return false;
481 	while (p->type != DEVICE_PATH_TYPE_END)
482 		p = (void *)p + p->length;
483 	return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END;
484 }
485 
486 #ifdef CONFIG_DM
487 /* size of device-path not including END node for device and all parents
488  * up to the root device.
489  */
dp_size(struct udevice * dev)490 __maybe_unused static unsigned int dp_size(struct udevice *dev)
491 {
492 	if (!dev || !dev->driver)
493 		return sizeof(ROOT);
494 
495 	switch (dev->driver->id) {
496 	case UCLASS_ROOT:
497 	case UCLASS_SIMPLE_BUS:
498 		/* stop traversing parents at this point: */
499 		return sizeof(ROOT);
500 	case UCLASS_ETH:
501 		return dp_size(dev->parent) +
502 			sizeof(struct efi_device_path_mac_addr);
503 #ifdef CONFIG_BLK
504 	case UCLASS_BLK:
505 		switch (dev->parent->uclass->uc_drv->id) {
506 #ifdef CONFIG_IDE
507 		case UCLASS_IDE:
508 			return dp_size(dev->parent) +
509 				sizeof(struct efi_device_path_atapi);
510 #endif
511 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
512 		case UCLASS_SCSI:
513 			return dp_size(dev->parent) +
514 				sizeof(struct efi_device_path_scsi);
515 #endif
516 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
517 		case UCLASS_MMC:
518 			return dp_size(dev->parent) +
519 				sizeof(struct efi_device_path_sd_mmc_path);
520 #endif
521 #if defined(CONFIG_AHCI) || defined(CONFIG_SATA)
522 		case UCLASS_AHCI:
523 			return dp_size(dev->parent) +
524 				sizeof(struct efi_device_path_sata);
525 #endif
526 #if defined(CONFIG_NVME)
527 		case UCLASS_NVME:
528 			return dp_size(dev->parent) +
529 				sizeof(struct efi_device_path_nvme);
530 #endif
531 #ifdef CONFIG_SANDBOX
532 		case UCLASS_ROOT:
533 			 /*
534 			  * Sandbox's host device will be represented
535 			  * as vendor device with extra one byte for
536 			  * device number
537 			  */
538 			return dp_size(dev->parent)
539 				+ sizeof(struct efi_device_path_vendor) + 1;
540 #endif
541 #ifdef CONFIG_VIRTIO_BLK
542 		case UCLASS_VIRTIO:
543 			 /*
544 			  * Virtio devices will be represented as a vendor
545 			  * device node with an extra byte for the device
546 			  * number.
547 			  */
548 			return dp_size(dev->parent)
549 				+ sizeof(struct efi_device_path_vendor) + 1;
550 #endif
551 		default:
552 			return dp_size(dev->parent);
553 		}
554 #endif
555 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
556 	case UCLASS_MMC:
557 		return dp_size(dev->parent) +
558 			sizeof(struct efi_device_path_sd_mmc_path);
559 #endif
560 	case UCLASS_MASS_STORAGE:
561 	case UCLASS_USB_HUB:
562 		return dp_size(dev->parent) +
563 			sizeof(struct efi_device_path_usb_class);
564 	default:
565 		/* just skip over unknown classes: */
566 		return dp_size(dev->parent);
567 	}
568 }
569 
570 /*
571  * Recursively build a device path.
572  *
573  * @buf		pointer to the end of the device path
574  * @dev		device
575  * @return	pointer to the end of the device path
576  */
dp_fill(void * buf,struct udevice * dev)577 __maybe_unused static void *dp_fill(void *buf, struct udevice *dev)
578 {
579 	if (!dev || !dev->driver)
580 		return buf;
581 
582 	switch (dev->driver->id) {
583 	case UCLASS_ROOT:
584 	case UCLASS_SIMPLE_BUS: {
585 		/* stop traversing parents at this point: */
586 		struct efi_device_path_vendor *vdp = buf;
587 		*vdp = ROOT;
588 		return &vdp[1];
589 	}
590 #ifdef CONFIG_DM_ETH
591 	case UCLASS_ETH: {
592 		struct efi_device_path_mac_addr *dp =
593 			dp_fill(buf, dev->parent);
594 		struct eth_pdata *pdata = dev_get_plat(dev);
595 
596 		dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
597 		dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
598 		dp->dp.length = sizeof(*dp);
599 		memset(&dp->mac, 0, sizeof(dp->mac));
600 		/* We only support IPv4 */
601 		memcpy(&dp->mac, &pdata->enetaddr, ARP_HLEN);
602 		/* Ethernet */
603 		dp->if_type = 1;
604 		return &dp[1];
605 	}
606 #endif
607 #ifdef CONFIG_BLK
608 	case UCLASS_BLK:
609 		switch (dev->parent->uclass->uc_drv->id) {
610 #ifdef CONFIG_SANDBOX
611 		case UCLASS_ROOT: {
612 			/* stop traversing parents at this point: */
613 			struct efi_device_path_vendor *dp;
614 			struct blk_desc *desc = dev_get_uclass_plat(dev);
615 
616 			dp_fill(buf, dev->parent);
617 			dp = buf;
618 			++dp;
619 			dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
620 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
621 			dp->dp.length = sizeof(*dp) + 1;
622 			memcpy(&dp->guid, &efi_guid_host_dev,
623 			       sizeof(efi_guid_t));
624 			dp->vendor_data[0] = desc->devnum;
625 			return &dp->vendor_data[1];
626 			}
627 #endif
628 #ifdef CONFIG_VIRTIO_BLK
629 		case UCLASS_VIRTIO: {
630 			struct efi_device_path_vendor *dp;
631 			struct blk_desc *desc = dev_get_uclass_plat(dev);
632 
633 			dp_fill(buf, dev->parent);
634 			dp = buf;
635 			++dp;
636 			dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
637 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
638 			dp->dp.length = sizeof(*dp) + 1;
639 			memcpy(&dp->guid, &efi_guid_virtio_dev,
640 			       sizeof(efi_guid_t));
641 			dp->vendor_data[0] = desc->devnum;
642 			return &dp->vendor_data[1];
643 			}
644 #endif
645 #ifdef CONFIG_IDE
646 		case UCLASS_IDE: {
647 			struct efi_device_path_atapi *dp =
648 			dp_fill(buf, dev->parent);
649 			struct blk_desc *desc = dev_get_uclass_plat(dev);
650 
651 			dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
652 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_ATAPI;
653 			dp->dp.length = sizeof(*dp);
654 			dp->logical_unit_number = desc->devnum;
655 			dp->primary_secondary = IDE_BUS(desc->devnum);
656 			dp->slave_master = desc->devnum %
657 				(CONFIG_SYS_IDE_MAXDEVICE /
658 				 CONFIG_SYS_IDE_MAXBUS);
659 			return &dp[1];
660 			}
661 #endif
662 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
663 		case UCLASS_SCSI: {
664 			struct efi_device_path_scsi *dp =
665 				dp_fill(buf, dev->parent);
666 			struct blk_desc *desc = dev_get_uclass_plat(dev);
667 
668 			dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
669 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
670 			dp->dp.length = sizeof(*dp);
671 			dp->logical_unit_number = desc->lun;
672 			dp->target_id = desc->target;
673 			return &dp[1];
674 			}
675 #endif
676 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
677 		case UCLASS_MMC: {
678 			struct efi_device_path_sd_mmc_path *sddp =
679 				dp_fill(buf, dev->parent);
680 			struct blk_desc *desc = dev_get_uclass_plat(dev);
681 
682 			sddp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
683 			sddp->dp.sub_type = is_sd(desc) ?
684 				DEVICE_PATH_SUB_TYPE_MSG_SD :
685 				DEVICE_PATH_SUB_TYPE_MSG_MMC;
686 			sddp->dp.length   = sizeof(*sddp);
687 			sddp->slot_number = dev_seq(dev);
688 			return &sddp[1];
689 			}
690 #endif
691 #if defined(CONFIG_AHCI) || defined(CONFIG_SATA)
692 		case UCLASS_AHCI: {
693 			struct efi_device_path_sata *dp =
694 				dp_fill(buf, dev->parent);
695 			struct blk_desc *desc = dev_get_uclass_plat(dev);
696 
697 			dp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
698 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SATA;
699 			dp->dp.length   = sizeof(*dp);
700 			dp->hba_port = desc->devnum;
701 			/* default 0xffff implies no port multiplier */
702 			dp->port_multiplier_port = 0xffff;
703 			dp->logical_unit_number = desc->lun;
704 			return &dp[1];
705 			}
706 #endif
707 #if defined(CONFIG_NVME)
708 		case UCLASS_NVME: {
709 			struct efi_device_path_nvme *dp =
710 				dp_fill(buf, dev->parent);
711 			u32 ns_id;
712 
713 			dp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
714 			dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_NVME;
715 			dp->dp.length   = sizeof(*dp);
716 			nvme_get_namespace_id(dev, &ns_id, dp->eui64);
717 			memcpy(&dp->ns_id, &ns_id, sizeof(ns_id));
718 			return &dp[1];
719 			}
720 #endif
721 		default:
722 			debug("%s(%u) %s: unhandled parent class: %s (%u)\n",
723 			      __FILE__, __LINE__, __func__,
724 			      dev->name, dev->parent->uclass->uc_drv->id);
725 			return dp_fill(buf, dev->parent);
726 		}
727 #endif
728 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
729 	case UCLASS_MMC: {
730 		struct efi_device_path_sd_mmc_path *sddp =
731 			dp_fill(buf, dev->parent);
732 		struct mmc *mmc = mmc_get_mmc_dev(dev);
733 		struct blk_desc *desc = mmc_get_blk_desc(mmc);
734 
735 		sddp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
736 		sddp->dp.sub_type = is_sd(desc) ?
737 			DEVICE_PATH_SUB_TYPE_MSG_SD :
738 			DEVICE_PATH_SUB_TYPE_MSG_MMC;
739 		sddp->dp.length   = sizeof(*sddp);
740 		sddp->slot_number = dev_seq(dev);
741 
742 		return &sddp[1];
743 	}
744 #endif
745 	case UCLASS_MASS_STORAGE:
746 	case UCLASS_USB_HUB: {
747 		struct efi_device_path_usb_class *udp =
748 			dp_fill(buf, dev->parent);
749 		struct usb_device *udev = dev_get_parent_priv(dev);
750 		struct usb_device_descriptor *desc = &udev->descriptor;
751 
752 		udp->dp.type     = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
753 		udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS;
754 		udp->dp.length   = sizeof(*udp);
755 		udp->vendor_id   = desc->idVendor;
756 		udp->product_id  = desc->idProduct;
757 		udp->device_class    = desc->bDeviceClass;
758 		udp->device_subclass = desc->bDeviceSubClass;
759 		udp->device_protocol = desc->bDeviceProtocol;
760 
761 		return &udp[1];
762 	}
763 	default:
764 		debug("%s(%u) %s: unhandled device class: %s (%u)\n",
765 		      __FILE__, __LINE__, __func__,
766 		      dev->name, dev->driver->id);
767 		return dp_fill(buf, dev->parent);
768 	}
769 }
770 #endif
771 
dp_part_size(struct blk_desc * desc,int part)772 static unsigned dp_part_size(struct blk_desc *desc, int part)
773 {
774 	unsigned dpsize;
775 
776 #ifdef CONFIG_BLK
777 	{
778 		struct udevice *dev;
779 		int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
780 
781 		if (ret)
782 			dev = desc->bdev->parent;
783 		dpsize = dp_size(dev);
784 	}
785 #else
786 	dpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);
787 #endif
788 
789 	if (part == 0) /* the actual disk, not a partition */
790 		return dpsize;
791 
792 	if (desc->part_type == PART_TYPE_ISO)
793 		dpsize += sizeof(struct efi_device_path_cdrom_path);
794 	else
795 		dpsize += sizeof(struct efi_device_path_hard_drive_path);
796 
797 	return dpsize;
798 }
799 
800 /*
801  * Create a device node for a block device partition.
802  *
803  * @buf		buffer to which the device path is written
804  * @desc	block device descriptor
805  * @part	partition number, 0 identifies a block device
806  */
dp_part_node(void * buf,struct blk_desc * desc,int part)807 static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
808 {
809 	struct disk_partition info;
810 
811 	part_get_info(desc, part, &info);
812 
813 	if (desc->part_type == PART_TYPE_ISO) {
814 		struct efi_device_path_cdrom_path *cddp = buf;
815 
816 		cddp->boot_entry = part;
817 		cddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
818 		cddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH;
819 		cddp->dp.length = sizeof(*cddp);
820 		cddp->partition_start = info.start;
821 		cddp->partition_size = info.size;
822 
823 		buf = &cddp[1];
824 	} else {
825 		struct efi_device_path_hard_drive_path *hddp = buf;
826 
827 		hddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
828 		hddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH;
829 		hddp->dp.length = sizeof(*hddp);
830 		hddp->partition_number = part;
831 		hddp->partition_start = info.start;
832 		hddp->partition_end = info.size;
833 		if (desc->part_type == PART_TYPE_EFI)
834 			hddp->partmap_type = 2;
835 		else
836 			hddp->partmap_type = 1;
837 
838 		switch (desc->sig_type) {
839 		case SIG_TYPE_NONE:
840 		default:
841 			hddp->signature_type = 0;
842 			memset(hddp->partition_signature, 0,
843 			       sizeof(hddp->partition_signature));
844 			break;
845 		case SIG_TYPE_MBR:
846 			hddp->signature_type = 1;
847 			memset(hddp->partition_signature, 0,
848 			       sizeof(hddp->partition_signature));
849 			memcpy(hddp->partition_signature, &desc->mbr_sig,
850 			       sizeof(desc->mbr_sig));
851 			break;
852 		case SIG_TYPE_GUID:
853 			hddp->signature_type = 2;
854 			memcpy(hddp->partition_signature, &desc->guid_sig,
855 			       sizeof(hddp->partition_signature));
856 			break;
857 		}
858 
859 		buf = &hddp[1];
860 	}
861 
862 	return buf;
863 }
864 
865 /*
866  * Create a device path for a block device or one of its partitions.
867  *
868  * @buf		buffer to which the device path is written
869  * @desc	block device descriptor
870  * @part	partition number, 0 identifies a block device
871  */
dp_part_fill(void * buf,struct blk_desc * desc,int part)872 static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
873 {
874 #ifdef CONFIG_BLK
875 	{
876 		struct udevice *dev;
877 		int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
878 
879 		if (ret)
880 			dev = desc->bdev->parent;
881 		buf = dp_fill(buf, dev);
882 	}
883 #else
884 	/*
885 	 * We *could* make a more accurate path, by looking at if_type
886 	 * and handling all the different cases like we do for non-
887 	 * legacy (i.e. CONFIG_BLK=y) case. But most important thing
888 	 * is just to have a unique device-path for if_type+devnum.
889 	 * So map things to a fictitious USB device.
890 	 */
891 	struct efi_device_path_usb *udp;
892 
893 	memcpy(buf, &ROOT, sizeof(ROOT));
894 	buf += sizeof(ROOT);
895 
896 	udp = buf;
897 	udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
898 	udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB;
899 	udp->dp.length = sizeof(*udp);
900 	udp->parent_port_number = desc->if_type;
901 	udp->usb_interface = desc->devnum;
902 	buf = &udp[1];
903 #endif
904 
905 	if (part == 0) /* the actual disk, not a partition */
906 		return buf;
907 
908 	return dp_part_node(buf, desc, part);
909 }
910 
911 /* Construct a device-path from a partition on a block device: */
efi_dp_from_part(struct blk_desc * desc,int part)912 struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
913 {
914 	void *buf, *start;
915 
916 	start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
917 	if (!buf)
918 		return NULL;
919 
920 	buf = dp_part_fill(buf, desc, part);
921 
922 	*((struct efi_device_path *)buf) = END;
923 
924 	return start;
925 }
926 
927 /*
928  * Create a device node for a block device partition.
929  *
930  * @buf		buffer to which the device path is written
931  * @desc	block device descriptor
932  * @part	partition number, 0 identifies a block device
933  */
efi_dp_part_node(struct blk_desc * desc,int part)934 struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
935 {
936 	efi_uintn_t dpsize;
937 	void *buf;
938 
939 	if (desc->part_type == PART_TYPE_ISO)
940 		dpsize = sizeof(struct efi_device_path_cdrom_path);
941 	else
942 		dpsize = sizeof(struct efi_device_path_hard_drive_path);
943 	buf = dp_alloc(dpsize);
944 
945 	dp_part_node(buf, desc, part);
946 
947 	return buf;
948 }
949 
950 /**
951  * path_to_uefi() - convert UTF-8 path to an UEFI style path
952  *
953  * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path
954  * separators and UTF-16).
955  *
956  * @src:	source buffer
957  * @uefi:	target buffer, possibly unaligned
958  */
path_to_uefi(void * uefi,const char * src)959 static void path_to_uefi(void *uefi, const char *src)
960 {
961 	u16 *pos = uefi;
962 
963 	/*
964 	 * efi_set_bootdev() calls this routine indirectly before the UEFI
965 	 * subsystem is initialized. So we cannot assume unaligned access to be
966 	 * enabled.
967 	 */
968 	allow_unaligned();
969 
970 	while (*src) {
971 		s32 code = utf8_get(&src);
972 
973 		if (code < 0)
974 			code = '?';
975 		else if (code == '/')
976 			code = '\\';
977 		utf16_put(code, &pos);
978 	}
979 	*pos = 0;
980 }
981 
982 /*
983  * If desc is NULL, this creates a path with only the file component,
984  * otherwise it creates a full path with both device and file components
985  */
efi_dp_from_file(struct blk_desc * desc,int part,const char * path)986 struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
987 		const char *path)
988 {
989 	struct efi_device_path_file_path *fp;
990 	void *buf, *start;
991 	size_t dpsize = 0, fpsize;
992 
993 	if (desc)
994 		dpsize = dp_part_size(desc, part);
995 
996 	fpsize = sizeof(struct efi_device_path) +
997 		 2 * (utf8_utf16_strlen(path) + 1);
998 	if (fpsize > U16_MAX)
999 		return NULL;
1000 
1001 	dpsize += fpsize;
1002 
1003 	start = buf = dp_alloc(dpsize + sizeof(END));
1004 	if (!buf)
1005 		return NULL;
1006 
1007 	if (desc)
1008 		buf = dp_part_fill(buf, desc, part);
1009 
1010 	/* add file-path: */
1011 	fp = buf;
1012 	fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
1013 	fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
1014 	fp->dp.length = (u16)fpsize;
1015 	path_to_uefi(fp->str, path);
1016 	buf += fpsize;
1017 
1018 	*((struct efi_device_path *)buf) = END;
1019 
1020 	return start;
1021 }
1022 
efi_dp_from_uart(void)1023 struct efi_device_path *efi_dp_from_uart(void)
1024 {
1025 	void *buf, *pos;
1026 	struct efi_device_path_uart *uart;
1027 	size_t dpsize = sizeof(ROOT) + sizeof(*uart) + sizeof(END);
1028 
1029 	buf = dp_alloc(dpsize);
1030 	if (!buf)
1031 		return NULL;
1032 	pos = buf;
1033 	memcpy(pos, &ROOT, sizeof(ROOT));
1034 	pos += sizeof(ROOT);
1035 	uart = pos;
1036 	uart->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
1037 	uart->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_UART;
1038 	uart->dp.length = sizeof(*uart);
1039 	pos += sizeof(*uart);
1040 	memcpy(pos, &END, sizeof(END));
1041 
1042 	return buf;
1043 }
1044 
1045 #ifdef CONFIG_NET
efi_dp_from_eth(void)1046 struct efi_device_path *efi_dp_from_eth(void)
1047 {
1048 #ifndef CONFIG_DM_ETH
1049 	struct efi_device_path_mac_addr *ndp;
1050 #endif
1051 	void *buf, *start;
1052 	unsigned dpsize = 0;
1053 
1054 	assert(eth_get_dev());
1055 
1056 #ifdef CONFIG_DM_ETH
1057 	dpsize += dp_size(eth_get_dev());
1058 #else
1059 	dpsize += sizeof(ROOT);
1060 	dpsize += sizeof(*ndp);
1061 #endif
1062 
1063 	start = buf = dp_alloc(dpsize + sizeof(END));
1064 	if (!buf)
1065 		return NULL;
1066 
1067 #ifdef CONFIG_DM_ETH
1068 	buf = dp_fill(buf, eth_get_dev());
1069 #else
1070 	memcpy(buf, &ROOT, sizeof(ROOT));
1071 	buf += sizeof(ROOT);
1072 
1073 	ndp = buf;
1074 	ndp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
1075 	ndp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
1076 	ndp->dp.length = sizeof(*ndp);
1077 	ndp->if_type = 1; /* Ethernet */
1078 	memcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);
1079 	buf = &ndp[1];
1080 #endif
1081 
1082 	*((struct efi_device_path *)buf) = END;
1083 
1084 	return start;
1085 }
1086 #endif
1087 
1088 /* Construct a device-path for memory-mapped image */
efi_dp_from_mem(uint32_t memory_type,uint64_t start_address,uint64_t end_address)1089 struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
1090 					uint64_t start_address,
1091 					uint64_t end_address)
1092 {
1093 	struct efi_device_path_memory *mdp;
1094 	void *buf, *start;
1095 
1096 	start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
1097 	if (!buf)
1098 		return NULL;
1099 
1100 	mdp = buf;
1101 	mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
1102 	mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY;
1103 	mdp->dp.length = sizeof(*mdp);
1104 	mdp->memory_type = memory_type;
1105 	mdp->start_address = start_address;
1106 	mdp->end_address = end_address;
1107 	buf = &mdp[1];
1108 
1109 	*((struct efi_device_path *)buf) = END;
1110 
1111 	return start;
1112 }
1113 
1114 /**
1115  * efi_dp_split_file_path() - split of relative file path from device path
1116  *
1117  * Given a device path indicating a file on a device, separate the device
1118  * path in two: the device path of the actual device and the file path
1119  * relative to this device.
1120  *
1121  * @full_path:		device path including device and file path
1122  * @device_path:	path of the device
1123  * @file_path:		relative path of the file or NULL if there is none
1124  * Return:		status code
1125  */
efi_dp_split_file_path(struct efi_device_path * full_path,struct efi_device_path ** device_path,struct efi_device_path ** file_path)1126 efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
1127 				    struct efi_device_path **device_path,
1128 				    struct efi_device_path **file_path)
1129 {
1130 	struct efi_device_path *p, *dp, *fp = NULL;
1131 
1132 	*device_path = NULL;
1133 	*file_path = NULL;
1134 	dp = efi_dp_dup(full_path);
1135 	if (!dp)
1136 		return EFI_OUT_OF_RESOURCES;
1137 	p = dp;
1138 	while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) {
1139 		p = efi_dp_next(p);
1140 		if (!p)
1141 			goto out;
1142 	}
1143 	fp = efi_dp_dup(p);
1144 	if (!fp)
1145 		return EFI_OUT_OF_RESOURCES;
1146 	p->type = DEVICE_PATH_TYPE_END;
1147 	p->sub_type = DEVICE_PATH_SUB_TYPE_END;
1148 	p->length = sizeof(*p);
1149 
1150 out:
1151 	*device_path = dp;
1152 	*file_path = fp;
1153 	return EFI_SUCCESS;
1154 }
1155 
1156 /**
1157  * efi_dp_from_name() - convert U-Boot device and file path to device path
1158  *
1159  * @dev:	U-Boot device, e.g. 'mmc'
1160  * @devnr:	U-Boot device number, e.g. 1 for 'mmc:1'
1161  * @path:	file path relative to U-Boot device, may be NULL
1162  * @device:	pointer to receive device path of the device
1163  * @file:	pointer to receive device path for the file
1164  * Return:	status code
1165  */
efi_dp_from_name(const char * dev,const char * devnr,const char * path,struct efi_device_path ** device,struct efi_device_path ** file)1166 efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
1167 			      const char *path,
1168 			      struct efi_device_path **device,
1169 			      struct efi_device_path **file)
1170 {
1171 	struct blk_desc *desc = NULL;
1172 	struct disk_partition fs_partition;
1173 	int part = 0;
1174 	char *filename;
1175 	char *s;
1176 
1177 	if (path && !file)
1178 		return EFI_INVALID_PARAMETER;
1179 
1180 	if (!strcmp(dev, "Net")) {
1181 #ifdef CONFIG_NET
1182 		if (device)
1183 			*device = efi_dp_from_eth();
1184 #endif
1185 	} else if (!strcmp(dev, "Uart")) {
1186 		if (device)
1187 			*device = efi_dp_from_uart();
1188 	} else {
1189 		part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
1190 					       1);
1191 		if (part < 0 || !desc)
1192 			return EFI_INVALID_PARAMETER;
1193 
1194 		if (device)
1195 			*device = efi_dp_from_part(desc, part);
1196 	}
1197 
1198 	if (!path)
1199 		return EFI_SUCCESS;
1200 
1201 	filename = calloc(1, strlen(path) + 1);
1202 	if (!filename)
1203 		return EFI_OUT_OF_RESOURCES;
1204 
1205 	sprintf(filename, "%s", path);
1206 	/* DOS style file path: */
1207 	s = filename;
1208 	while ((s = strchr(s, '/')))
1209 		*s++ = '\\';
1210 	*file = efi_dp_from_file(desc, part, filename);
1211 	free(filename);
1212 
1213 	if (!*file)
1214 		return EFI_INVALID_PARAMETER;
1215 
1216 	return EFI_SUCCESS;
1217 }
1218 
1219 /**
1220  * efi_dp_check_length() - check length of a device path
1221  *
1222  * @dp:		pointer to device path
1223  * @maxlen:	maximum length of the device path
1224  * Return:
1225  * * length of the device path if it is less or equal @maxlen
1226  * * -1 if the device path is longer then @maxlen
1227  * * -1 if a device path node has a length of less than 4
1228  * * -EINVAL if maxlen exceeds SSIZE_MAX
1229  */
efi_dp_check_length(const struct efi_device_path * dp,const size_t maxlen)1230 ssize_t efi_dp_check_length(const struct efi_device_path *dp,
1231 			    const size_t maxlen)
1232 {
1233 	ssize_t ret = 0;
1234 	u16 len;
1235 
1236 	if (maxlen > SSIZE_MAX)
1237 		return -EINVAL;
1238 	for (;;) {
1239 		len = dp->length;
1240 		if (len < 4)
1241 			return -1;
1242 		ret += len;
1243 		if (ret > maxlen)
1244 			return -1;
1245 		if (dp->type == DEVICE_PATH_TYPE_END &&
1246 		    dp->sub_type == DEVICE_PATH_SUB_TYPE_END)
1247 			return ret;
1248 		dp = (const struct efi_device_path *)((const u8 *)dp + len);
1249 	}
1250 }
1251 
1252 /**
1253  * efi_dp_from_lo() - Get the instance of a VenMedia node in a
1254  *                    multi-instance device path that matches
1255  *                    a specific GUID. This kind of device paths
1256  *                    is found in Boot#### options describing an
1257  *                    initrd location
1258  *
1259  * @lo:		EFI_LOAD_OPTION containing a valid device path
1260  * @size:	size of the discovered device path
1261  * @guid:	guid to search for
1262  *
1263  * Return:
1264  * device path including the VenMedia node or NULL.
1265  * Caller must free the returned value.
1266  */
1267 struct
efi_dp_from_lo(struct efi_load_option * lo,efi_uintn_t * size,efi_guid_t guid)1268 efi_device_path *efi_dp_from_lo(struct efi_load_option *lo,
1269 				efi_uintn_t *size, efi_guid_t guid)
1270 {
1271 	struct efi_device_path *fp = lo->file_path;
1272 	struct efi_device_path_vendor *vendor;
1273 	int lo_len = lo->file_path_length;
1274 
1275 	for (; lo_len >=  sizeof(struct efi_device_path);
1276 	     lo_len -= fp->length, fp = (void *)fp + fp->length) {
1277 		if (lo_len < 0 || efi_dp_check_length(fp, lo_len) < 0)
1278 			break;
1279 		if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE ||
1280 		    fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH)
1281 			continue;
1282 
1283 		vendor = (struct efi_device_path_vendor *)fp;
1284 		if (!guidcmp(&vendor->guid, &guid))
1285 			return efi_dp_dup(fp);
1286 	}
1287 	log_debug("VenMedia(%pUl) not found in %ls\n", &guid, lo->label);
1288 
1289 	return NULL;
1290 }
1291