1 // SPDX-License-Identifier: GPL-2.0+
3 * EFI device path from u-boot device-model mapping
5 * (C) Copyright 2017 Rob Clark
13 #include <efi_loader.h>
15 #include <sandboxblockdev.h>
16 #include <asm-generic/unaligned.h>
19 const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
22 /* template END node: */
23 static const struct efi_device_path END = {
24 .type = DEVICE_PATH_TYPE_END,
25 .sub_type = DEVICE_PATH_SUB_TYPE_END,
26 .length = sizeof(END),
29 /* template ROOT node: */
30 static const struct efi_device_path_vendor ROOT = {
32 .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE,
33 .sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,
34 .length = sizeof(ROOT),
39 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
41 * Determine if an MMC device is an SD card.
43 * @desc block device descriptor
44 * @return true if the device is an SD card
46 static bool is_sd(struct blk_desc *desc)
48 struct mmc *mmc = find_mmc_device(desc->devnum);
53 return IS_SD(mmc) != 0U;
57 static void *dp_alloc(size_t sz)
61 if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) !=
63 debug("EFI: ERROR: out of memory in %s\n", __func__);
72 * Iterate to next block in device-path, terminating (returning NULL)
75 struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
79 if (dp->type == DEVICE_PATH_TYPE_END)
81 dp = ((void *)dp) + dp->length;
82 if (dp->type == DEVICE_PATH_TYPE_END)
84 return (struct efi_device_path *)dp;
88 * Compare two device-paths, stopping when the shorter of the two hits
89 * an End* node. This is useful to, for example, compare a device-path
90 * representing a device with one representing a file on the device, or
91 * a device with a parent device.
93 int efi_dp_match(const struct efi_device_path *a,
94 const struct efi_device_path *b)
99 ret = memcmp(&a->length, &b->length, sizeof(a->length));
103 ret = memcmp(a, b, a->length);
116 * 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
120 * - MESSAGING:USB_WWID
121 * - MESSAGING:USB_CLASS
126 * See UEFI spec (section 3.1.2, about short-form device-paths)
128 static struct efi_device_path *shorten_path(struct efi_device_path *dp)
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.
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))
141 dp = efi_dp_next(dp);
147 static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
148 struct efi_device_path **rem)
150 struct efi_object *efiobj;
151 efi_uintn_t dp_size = efi_dp_instance_size(dp);
153 list_for_each_entry(efiobj, &efi_obj_list, link) {
154 struct efi_handler *handler;
155 struct efi_device_path *obj_dp;
158 ret = efi_search_protocol(efiobj,
159 &efi_guid_device_path, &handler);
160 if (ret != EFI_SUCCESS)
162 obj_dp = handler->protocol_interface;
165 if (efi_dp_match(dp, obj_dp) == 0) {
168 * Allow partial matches, but inform
171 *rem = ((void *)dp) +
172 efi_dp_instance_size(obj_dp);
175 /* Only return on exact matches */
176 if (efi_dp_instance_size(obj_dp) ==
182 obj_dp = shorten_path(efi_dp_next(obj_dp));
183 } while (short_path && obj_dp);
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.
193 struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
194 struct efi_device_path **rem)
196 struct efi_object *efiobj;
198 /* Search for an exact match first */
199 efiobj = find_obj(dp, false, NULL);
201 /* Then for a fuzzy match */
203 efiobj = find_obj(dp, false, rem);
205 /* And now for a fuzzy short match */
207 efiobj = find_obj(dp, true, rem);
213 * Determine the last device path node that is not the end node.
216 * @return last node before the end node if it exists
219 const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp)
221 struct efi_device_path *ret;
223 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
226 ret = (struct efi_device_path *)dp;
227 dp = efi_dp_next(dp);
232 /* get size of the first device path instance excluding end node */
233 efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp)
237 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
241 dp = efi_dp_next(dp);
247 /* get size of multi-instance device path excluding end node */
248 efi_uintn_t efi_dp_size(const struct efi_device_path *dp)
250 const struct efi_device_path *p = dp;
254 while (p->type != DEVICE_PATH_TYPE_END ||
255 p->sub_type != DEVICE_PATH_SUB_TYPE_END)
256 p = (void *)p + p->length;
258 return (void *)p - (void *)dp;
261 /* copy multi-instance device path */
262 struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
264 struct efi_device_path *ndp;
265 size_t sz = efi_dp_size(dp) + sizeof(END);
278 struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
279 const struct efi_device_path *dp2)
281 struct efi_device_path *ret;
284 /* return an end node */
285 ret = efi_dp_dup(&END);
287 ret = efi_dp_dup(dp2);
289 ret = efi_dp_dup(dp1);
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));
298 /* the end node of the second device path has to be retained */
299 memcpy(p + sz1, dp2, sz2 + sizeof(END));
306 struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
307 const struct efi_device_path *node)
309 struct efi_device_path *ret;
312 ret = efi_dp_dup(&END);
314 ret = efi_dp_dup(dp);
316 size_t sz = node->length;
317 void *p = dp_alloc(sz + sizeof(END));
321 memcpy(p + sz, &END, sizeof(END));
324 /* both dp and node are non-null */
325 size_t sz = efi_dp_size(dp);
326 void *p = dp_alloc(sz + node->length + sizeof(END));
330 memcpy(p + sz, node, node->length);
331 memcpy(p + sz + node->length, &END, sizeof(END));
338 struct efi_device_path *efi_dp_create_device_node(const u8 type,
342 struct efi_device_path *ret;
344 if (length < sizeof(struct efi_device_path))
347 ret = dp_alloc(length);
351 ret->sub_type = sub_type;
352 ret->length = length;
356 struct efi_device_path *efi_dp_append_instance(
357 const struct efi_device_path *dp,
358 const struct efi_device_path *dpi)
361 struct efi_device_path *p, *ret;
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));
373 memcpy(p, dp, sz + sizeof(END));
375 p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END;
376 p = (void *)p + sizeof(END);
379 memcpy(p, &END, sizeof(END));
383 struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
387 struct efi_device_path *p;
393 sz = efi_dp_instance_size(*dp);
394 p = dp_alloc(sz + sizeof(END));
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);
404 *size = sz + sizeof(END);
408 bool efi_dp_is_multi_instance(const struct efi_device_path *dp)
410 const struct efi_device_path *p = dp;
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;
420 /* size of device-path not including END node for device and all parents
421 * up to the root device.
423 static unsigned dp_size(struct udevice *dev)
425 if (!dev || !dev->driver)
428 switch (dev->driver->id) {
430 case UCLASS_SIMPLE_BUS:
431 /* stop traversing parents at this point: */
434 return dp_size(dev->parent) +
435 sizeof(struct efi_device_path_mac_addr);
438 switch (dev->parent->uclass->uc_drv->id) {
441 return dp_size(dev->parent) +
442 sizeof(struct efi_device_path_atapi);
444 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
446 return dp_size(dev->parent) +
447 sizeof(struct efi_device_path_scsi);
449 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
451 return dp_size(dev->parent) +
452 sizeof(struct efi_device_path_sd_mmc_path);
454 #ifdef CONFIG_SANDBOX
457 * Sandbox's host device will be represented
458 * as vendor device with extra one byte for
461 return dp_size(dev->parent)
462 + sizeof(struct efi_device_path_vendor) + 1;
465 return dp_size(dev->parent);
468 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
470 return dp_size(dev->parent) +
471 sizeof(struct efi_device_path_sd_mmc_path);
473 case UCLASS_MASS_STORAGE:
475 return dp_size(dev->parent) +
476 sizeof(struct efi_device_path_usb_class);
478 /* just skip over unknown classes: */
479 return dp_size(dev->parent);
484 * Recursively build a device path.
486 * @buf pointer to the end of the device path
488 * @return pointer to the end of the device path
490 static void *dp_fill(void *buf, struct udevice *dev)
492 if (!dev || !dev->driver)
495 switch (dev->driver->id) {
497 case UCLASS_SIMPLE_BUS: {
498 /* stop traversing parents at this point: */
499 struct efi_device_path_vendor *vdp = buf;
505 struct efi_device_path_mac_addr *dp =
506 dp_fill(buf, dev->parent);
507 struct eth_pdata *pdata = dev->platdata;
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);
522 switch (dev->parent->uclass->uc_drv->id) {
523 #ifdef CONFIG_SANDBOX
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);
529 dp_fill(buf, dev->parent);
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,
537 dp->vendor_data[0] = desc->devnum;
538 return &dp->vendor_data[1];
543 struct efi_device_path_atapi *dp =
544 dp_fill(buf, dev->parent);
545 struct blk_desc *desc = dev_get_uclass_platdata(dev);
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);
558 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
560 struct efi_device_path_scsi *dp =
561 dp_fill(buf, dev->parent);
562 struct blk_desc *desc = dev_get_uclass_platdata(dev);
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;
572 #if defined(CONFIG_DM_MMC) && defined(CONFIG_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);
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;
588 debug("%s(%u) %s: unhandled parent class: %s (%u)\n",
589 __FILE__, __LINE__, __func__,
590 dev->name, dev->parent->uclass->uc_drv->id);
591 return dp_fill(buf, dev->parent);
594 #if defined(CONFIG_DM_MMC) && defined(CONFIG_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);
601 sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
602 sddp->dp.sub_type = is_sd(desc) ?
603 DEVICE_PATH_SUB_TYPE_MSG_SD :
604 DEVICE_PATH_SUB_TYPE_MSG_MMC;
605 sddp->dp.length = sizeof(*sddp);
606 sddp->slot_number = dev->seq;
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;
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;
630 debug("%s(%u) %s: unhandled device class: %s (%u)\n",
631 __FILE__, __LINE__, __func__,
632 dev->name, dev->driver->id);
633 return dp_fill(buf, dev->parent);
637 /* Construct a device-path from a device: */
638 struct efi_device_path *efi_dp_from_dev(struct udevice *dev)
642 start = buf = dp_alloc(dp_size(dev) + sizeof(END));
645 buf = dp_fill(buf, dev);
646 *((struct efi_device_path *)buf) = END;
652 static unsigned dp_part_size(struct blk_desc *desc, int part)
659 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
662 dev = desc->bdev->parent;
663 dpsize = dp_size(dev);
666 dpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);
669 if (part == 0) /* the actual disk, not a partition */
672 if (desc->part_type == PART_TYPE_ISO)
673 dpsize += sizeof(struct efi_device_path_cdrom_path);
675 dpsize += sizeof(struct efi_device_path_hard_drive_path);
681 * Create a device node for a block device partition.
683 * @buf buffer to which the device path is written
684 * @desc block device descriptor
685 * @part partition number, 0 identifies a block device
687 static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
689 disk_partition_t info;
691 part_get_info(desc, part, &info);
693 if (desc->part_type == PART_TYPE_ISO) {
694 struct efi_device_path_cdrom_path *cddp = buf;
696 cddp->boot_entry = part;
697 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;
701 cddp->partition_size = info.size;
705 struct efi_device_path_hard_drive_path *hddp = buf;
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);
710 hddp->partition_number = part;
711 hddp->partition_start = info.start;
712 hddp->partition_end = info.size;
713 if (desc->part_type == PART_TYPE_EFI)
714 hddp->partmap_type = 2;
716 hddp->partmap_type = 1;
718 switch (desc->sig_type) {
721 hddp->signature_type = 0;
722 memset(hddp->partition_signature, 0,
723 sizeof(hddp->partition_signature));
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));
733 hddp->signature_type = 2;
734 memcpy(hddp->partition_signature, &desc->guid_sig,
735 sizeof(hddp->partition_signature));
746 * Create a device path for a block device or one of its partitions.
748 * @buf buffer to which the device path is written
749 * @desc block device descriptor
750 * @part partition number, 0 identifies a block device
752 static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
757 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
760 dev = desc->bdev->parent;
761 buf = dp_fill(buf, dev);
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-
767 * legacy (i.e. CONFIG_BLK=y) case. But most important thing
768 * is just to have a unique device-path for if_type+devnum.
769 * So map things to a fictitious USB device.
771 struct efi_device_path_usb *udp;
773 memcpy(buf, &ROOT, sizeof(ROOT));
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;
785 if (part == 0) /* the actual disk, not a partition */
788 return dp_part_node(buf, desc, part);
791 /* Construct a device-path from a partition on a block device: */
792 struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
796 start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
800 buf = dp_part_fill(buf, desc, part);
802 *((struct efi_device_path *)buf) = END;
808 * Create a device node for a block device partition.
810 * @buf buffer to which the device path is written
811 * @desc block device descriptor
812 * @part partition number, 0 identifies a block device
814 struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
819 if (desc->part_type == PART_TYPE_ISO)
820 dpsize = sizeof(struct efi_device_path_cdrom_path);
822 dpsize = sizeof(struct efi_device_path_hard_drive_path);
823 buf = dp_alloc(dpsize);
825 dp_part_node(buf, desc, part);
831 * path_to_uefi() - convert UTF-8 path to an UEFI style path
833 * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path
834 * separators and UTF-16).
836 * @src: source buffer
837 * @uefi: target buffer, possibly unaligned
839 static void path_to_uefi(void *uefi, const char *src)
844 * efi_set_bootdev() calls this routine indirectly before the UEFI
845 * subsystem is initialized. So we cannot assume unaligned access to be
851 s32 code = utf8_get(&src);
855 else if (code == '/')
857 utf16_put(code, &pos);
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
866 struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
869 struct efi_device_path_file_path *fp;
871 unsigned dpsize = 0, fpsize;
874 dpsize = dp_part_size(desc, part);
876 fpsize = sizeof(struct efi_device_path) +
877 2 * (utf8_utf16_strlen(path) + 1);
880 start = buf = dp_alloc(dpsize + sizeof(END));
885 buf = dp_part_fill(buf, desc, part);
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);
895 *((struct efi_device_path *)buf) = END;
901 struct efi_device_path *efi_dp_from_eth(void)
903 #ifndef CONFIG_DM_ETH
904 struct efi_device_path_mac_addr *ndp;
909 assert(eth_get_dev());
912 dpsize += dp_size(eth_get_dev());
914 dpsize += sizeof(ROOT);
915 dpsize += sizeof(*ndp);
918 start = buf = dp_alloc(dpsize + sizeof(END));
923 buf = dp_fill(buf, eth_get_dev());
925 memcpy(buf, &ROOT, sizeof(ROOT));
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);
932 ndp->if_type = 1; /* Ethernet */
933 memcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);
937 *((struct efi_device_path *)buf) = END;
943 /* Construct a device-path for memory-mapped image */
944 struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
945 uint64_t start_address,
946 uint64_t end_address)
948 struct efi_device_path_memory *mdp;
951 start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
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;
964 *((struct efi_device_path *)buf) = END;
970 * efi_dp_split_file_path() - split of relative file path from device path
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.
976 * @full_path: device path including device and file path
977 * @device_path: path of the device
978 * @file_path: relative path of the file or NULL if there is none
979 * Return: status code
981 efi_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)
985 struct efi_device_path *p, *dp, *fp = NULL;
989 dp = efi_dp_dup(full_path);
991 return EFI_OUT_OF_RESOURCES;
993 while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) {
1000 return EFI_OUT_OF_RESOURCES;
1001 p->type = DEVICE_PATH_TYPE_END;
1002 p->sub_type = DEVICE_PATH_SUB_TYPE_END;
1003 p->length = sizeof(*p);
1011 efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
1013 struct efi_device_path **device,
1014 struct efi_device_path **file)
1017 struct blk_desc *desc = NULL;
1018 disk_partition_t fs_partition;
1020 char filename[32] = { 0 }; /* dp->str is u16[32] long */
1024 return EFI_INVALID_PARAMETER;
1026 is_net = !strcmp(dev, "Net");
1028 part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
1030 if (part < 0 || !desc)
1031 return EFI_INVALID_PARAMETER;
1034 *device = efi_dp_from_part(desc, part);
1038 *device = efi_dp_from_eth();
1045 snprintf(filename, sizeof(filename), "%s", path);
1046 /* DOS style file path: */
1048 while ((s = strchr(s, '/')))
1050 *file = efi_dp_from_file(((!is_net && device) ? desc : NULL),