1 // SPDX-License-Identifier: GPL-2.0+
3 * EFI device path from u-boot device-model mapping
5 * (C) Copyright 2017 Rob Clark
14 #include <efi_loader.h>
16 #include <sandboxblockdev.h>
17 #include <asm-generic/unaligned.h>
20 const efi_guid_t efi_guid_host_dev = U_BOOT_HOST_DEV_GUID;
23 /* template END node: */
24 static const struct efi_device_path END = {
25 .type = DEVICE_PATH_TYPE_END,
26 .sub_type = DEVICE_PATH_SUB_TYPE_END,
27 .length = sizeof(END),
30 /* template ROOT node: */
31 static const struct efi_device_path_vendor ROOT = {
33 .type = DEVICE_PATH_TYPE_HARDWARE_DEVICE,
34 .sub_type = DEVICE_PATH_SUB_TYPE_VENDOR,
35 .length = sizeof(ROOT),
40 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
42 * Determine if an MMC device is an SD card.
44 * @desc block device descriptor
45 * @return true if the device is an SD card
47 static bool is_sd(struct blk_desc *desc)
49 struct mmc *mmc = find_mmc_device(desc->devnum);
54 return IS_SD(mmc) != 0U;
58 static void *dp_alloc(size_t sz)
62 if (efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES, sz, &buf) !=
64 debug("EFI: ERROR: out of memory in %s\n", __func__);
73 * Iterate to next block in device-path, terminating (returning NULL)
76 struct efi_device_path *efi_dp_next(const struct efi_device_path *dp)
80 if (dp->type == DEVICE_PATH_TYPE_END)
82 dp = ((void *)dp) + dp->length;
83 if (dp->type == DEVICE_PATH_TYPE_END)
85 return (struct efi_device_path *)dp;
89 * Compare two device-paths, stopping when the shorter of the two hits
90 * an End* node. This is useful to, for example, compare a device-path
91 * representing a device with one representing a file on the device, or
92 * a device with a parent device.
94 int efi_dp_match(const struct efi_device_path *a,
95 const struct efi_device_path *b)
100 ret = memcmp(&a->length, &b->length, sizeof(a->length));
104 ret = memcmp(a, b, a->length);
117 * We can have device paths that start with a USB WWID or a USB Class node,
118 * and a few other cases which don't encode the full device path with bus
121 * - MESSAGING:USB_WWID
122 * - MESSAGING:USB_CLASS
127 * See UEFI spec (section 3.1.2, about short-form device-paths)
129 static struct efi_device_path *shorten_path(struct efi_device_path *dp)
133 * TODO: Add MESSAGING:USB_WWID and MESSAGING:URI..
134 * in practice fallback.efi just uses MEDIA:HARD_DRIVE
135 * so not sure when we would see these other cases.
137 if (EFI_DP_TYPE(dp, MESSAGING_DEVICE, MSG_USB_CLASS) ||
138 EFI_DP_TYPE(dp, MEDIA_DEVICE, HARD_DRIVE_PATH) ||
139 EFI_DP_TYPE(dp, MEDIA_DEVICE, FILE_PATH))
142 dp = efi_dp_next(dp);
148 static struct efi_object *find_obj(struct efi_device_path *dp, bool short_path,
149 struct efi_device_path **rem)
151 struct efi_object *efiobj;
152 efi_uintn_t dp_size = efi_dp_instance_size(dp);
154 list_for_each_entry(efiobj, &efi_obj_list, link) {
155 struct efi_handler *handler;
156 struct efi_device_path *obj_dp;
159 ret = efi_search_protocol(efiobj,
160 &efi_guid_device_path, &handler);
161 if (ret != EFI_SUCCESS)
163 obj_dp = handler->protocol_interface;
166 if (efi_dp_match(dp, obj_dp) == 0) {
169 * Allow partial matches, but inform
172 *rem = ((void *)dp) +
173 efi_dp_instance_size(obj_dp);
176 /* Only return on exact matches */
177 if (efi_dp_instance_size(obj_dp) ==
183 obj_dp = shorten_path(efi_dp_next(obj_dp));
184 } while (short_path && obj_dp);
191 * Find an efiobj from device-path, if 'rem' is not NULL, returns the
192 * remaining part of the device path after the matched object.
194 struct efi_object *efi_dp_find_obj(struct efi_device_path *dp,
195 struct efi_device_path **rem)
197 struct efi_object *efiobj;
199 /* Search for an exact match first */
200 efiobj = find_obj(dp, false, NULL);
202 /* Then for a fuzzy match */
204 efiobj = find_obj(dp, false, rem);
206 /* And now for a fuzzy short match */
208 efiobj = find_obj(dp, true, rem);
214 * Determine the last device path node that is not the end node.
217 * @return last node before the end node if it exists
220 const struct efi_device_path *efi_dp_last_node(const struct efi_device_path *dp)
222 struct efi_device_path *ret;
224 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
227 ret = (struct efi_device_path *)dp;
228 dp = efi_dp_next(dp);
233 /* get size of the first device path instance excluding end node */
234 efi_uintn_t efi_dp_instance_size(const struct efi_device_path *dp)
238 if (!dp || dp->type == DEVICE_PATH_TYPE_END)
242 dp = efi_dp_next(dp);
248 /* get size of multi-instance device path excluding end node */
249 efi_uintn_t efi_dp_size(const struct efi_device_path *dp)
251 const struct efi_device_path *p = dp;
255 while (p->type != DEVICE_PATH_TYPE_END ||
256 p->sub_type != DEVICE_PATH_SUB_TYPE_END)
257 p = (void *)p + p->length;
259 return (void *)p - (void *)dp;
262 /* copy multi-instance device path */
263 struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp)
265 struct efi_device_path *ndp;
266 size_t sz = efi_dp_size(dp) + sizeof(END);
279 struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1,
280 const struct efi_device_path *dp2)
282 struct efi_device_path *ret;
285 /* return an end node */
286 ret = efi_dp_dup(&END);
288 ret = efi_dp_dup(dp2);
290 ret = efi_dp_dup(dp1);
292 /* both dp1 and dp2 are non-null */
293 unsigned sz1 = efi_dp_size(dp1);
294 unsigned sz2 = efi_dp_size(dp2);
295 void *p = dp_alloc(sz1 + sz2 + sizeof(END));
299 /* the end node of the second device path has to be retained */
300 memcpy(p + sz1, dp2, sz2 + sizeof(END));
307 struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp,
308 const struct efi_device_path *node)
310 struct efi_device_path *ret;
313 ret = efi_dp_dup(&END);
315 ret = efi_dp_dup(dp);
317 size_t sz = node->length;
318 void *p = dp_alloc(sz + sizeof(END));
322 memcpy(p + sz, &END, sizeof(END));
325 /* both dp and node are non-null */
326 size_t sz = efi_dp_size(dp);
327 void *p = dp_alloc(sz + node->length + sizeof(END));
331 memcpy(p + sz, node, node->length);
332 memcpy(p + sz + node->length, &END, sizeof(END));
339 struct efi_device_path *efi_dp_create_device_node(const u8 type,
343 struct efi_device_path *ret;
345 if (length < sizeof(struct efi_device_path))
348 ret = dp_alloc(length);
352 ret->sub_type = sub_type;
353 ret->length = length;
357 struct efi_device_path *efi_dp_append_instance(
358 const struct efi_device_path *dp,
359 const struct efi_device_path *dpi)
362 struct efi_device_path *p, *ret;
367 return efi_dp_dup(dpi);
368 sz = efi_dp_size(dp);
369 szi = efi_dp_instance_size(dpi);
370 p = dp_alloc(sz + szi + 2 * sizeof(END));
374 memcpy(p, dp, sz + sizeof(END));
376 p->sub_type = DEVICE_PATH_SUB_TYPE_INSTANCE_END;
377 p = (void *)p + sizeof(END);
380 memcpy(p, &END, sizeof(END));
384 struct efi_device_path *efi_dp_get_next_instance(struct efi_device_path **dp,
388 struct efi_device_path *p;
394 sz = efi_dp_instance_size(*dp);
395 p = dp_alloc(sz + sizeof(END));
398 memcpy(p, *dp, sz + sizeof(END));
399 *dp = (void *)*dp + sz;
400 if ((*dp)->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END)
401 *dp = (void *)*dp + sizeof(END);
405 *size = sz + sizeof(END);
409 bool efi_dp_is_multi_instance(const struct efi_device_path *dp)
411 const struct efi_device_path *p = dp;
415 while (p->type != DEVICE_PATH_TYPE_END)
416 p = (void *)p + p->length;
417 return p->sub_type == DEVICE_PATH_SUB_TYPE_INSTANCE_END;
421 /* size of device-path not including END node for device and all parents
422 * up to the root device.
424 static unsigned dp_size(struct udevice *dev)
426 if (!dev || !dev->driver)
429 switch (dev->driver->id) {
431 case UCLASS_SIMPLE_BUS:
432 /* stop traversing parents at this point: */
435 return dp_size(dev->parent) +
436 sizeof(struct efi_device_path_mac_addr);
439 switch (dev->parent->uclass->uc_drv->id) {
442 return dp_size(dev->parent) +
443 sizeof(struct efi_device_path_atapi);
445 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
447 return dp_size(dev->parent) +
448 sizeof(struct efi_device_path_scsi);
450 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
452 return dp_size(dev->parent) +
453 sizeof(struct efi_device_path_sd_mmc_path);
455 #if defined(CONFIG_NVME)
457 return dp_size(dev->parent) +
458 sizeof(struct efi_device_path_nvme);
460 #ifdef CONFIG_SANDBOX
463 * Sandbox's host device will be represented
464 * as vendor device with extra one byte for
467 return dp_size(dev->parent)
468 + sizeof(struct efi_device_path_vendor) + 1;
471 return dp_size(dev->parent);
474 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
476 return dp_size(dev->parent) +
477 sizeof(struct efi_device_path_sd_mmc_path);
479 case UCLASS_MASS_STORAGE:
481 return dp_size(dev->parent) +
482 sizeof(struct efi_device_path_usb_class);
484 /* just skip over unknown classes: */
485 return dp_size(dev->parent);
490 * Recursively build a device path.
492 * @buf pointer to the end of the device path
494 * @return pointer to the end of the device path
496 static void *dp_fill(void *buf, struct udevice *dev)
498 if (!dev || !dev->driver)
501 switch (dev->driver->id) {
503 case UCLASS_SIMPLE_BUS: {
504 /* stop traversing parents at this point: */
505 struct efi_device_path_vendor *vdp = buf;
511 struct efi_device_path_mac_addr *dp =
512 dp_fill(buf, dev->parent);
513 struct eth_pdata *pdata = dev->platdata;
515 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
516 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
517 dp->dp.length = sizeof(*dp);
518 memset(&dp->mac, 0, sizeof(dp->mac));
519 /* We only support IPv4 */
520 memcpy(&dp->mac, &pdata->enetaddr, ARP_HLEN);
528 switch (dev->parent->uclass->uc_drv->id) {
529 #ifdef CONFIG_SANDBOX
531 /* stop traversing parents at this point: */
532 struct efi_device_path_vendor *dp = buf;
533 struct blk_desc *desc = dev_get_uclass_platdata(dev);
535 dp_fill(buf, dev->parent);
538 dp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
539 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_VENDOR;
540 dp->dp.length = sizeof(*dp) + 1;
541 memcpy(&dp->guid, &efi_guid_host_dev,
543 dp->vendor_data[0] = desc->devnum;
544 return &dp->vendor_data[1];
549 struct efi_device_path_atapi *dp =
550 dp_fill(buf, dev->parent);
551 struct blk_desc *desc = dev_get_uclass_platdata(dev);
553 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
554 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_ATAPI;
555 dp->dp.length = sizeof(*dp);
556 dp->logical_unit_number = desc->devnum;
557 dp->primary_secondary = IDE_BUS(desc->devnum);
558 dp->slave_master = desc->devnum %
559 (CONFIG_SYS_IDE_MAXDEVICE /
560 CONFIG_SYS_IDE_MAXBUS);
564 #if defined(CONFIG_SCSI) && defined(CONFIG_DM_SCSI)
566 struct efi_device_path_scsi *dp =
567 dp_fill(buf, dev->parent);
568 struct blk_desc *desc = dev_get_uclass_platdata(dev);
570 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
571 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_SCSI;
572 dp->dp.length = sizeof(*dp);
573 dp->logical_unit_number = desc->lun;
574 dp->target_id = desc->target;
578 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
580 struct efi_device_path_sd_mmc_path *sddp =
581 dp_fill(buf, dev->parent);
582 struct blk_desc *desc = dev_get_uclass_platdata(dev);
584 sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
585 sddp->dp.sub_type = is_sd(desc) ?
586 DEVICE_PATH_SUB_TYPE_MSG_SD :
587 DEVICE_PATH_SUB_TYPE_MSG_MMC;
588 sddp->dp.length = sizeof(*sddp);
589 sddp->slot_number = dev->seq;
593 #if defined(CONFIG_NVME)
595 struct efi_device_path_nvme *dp =
596 dp_fill(buf, dev->parent);
599 dp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
600 dp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_NVME;
601 dp->dp.length = sizeof(*dp);
602 nvme_get_namespace_id(dev, &ns_id, dp->eui64);
603 memcpy(&dp->ns_id, &ns_id, sizeof(ns_id));
608 debug("%s(%u) %s: unhandled parent class: %s (%u)\n",
609 __FILE__, __LINE__, __func__,
610 dev->name, dev->parent->uclass->uc_drv->id);
611 return dp_fill(buf, dev->parent);
614 #if defined(CONFIG_DM_MMC) && defined(CONFIG_MMC)
616 struct efi_device_path_sd_mmc_path *sddp =
617 dp_fill(buf, dev->parent);
618 struct mmc *mmc = mmc_get_mmc_dev(dev);
619 struct blk_desc *desc = mmc_get_blk_desc(mmc);
621 sddp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
622 sddp->dp.sub_type = is_sd(desc) ?
623 DEVICE_PATH_SUB_TYPE_MSG_SD :
624 DEVICE_PATH_SUB_TYPE_MSG_MMC;
625 sddp->dp.length = sizeof(*sddp);
626 sddp->slot_number = dev->seq;
631 case UCLASS_MASS_STORAGE:
632 case UCLASS_USB_HUB: {
633 struct efi_device_path_usb_class *udp =
634 dp_fill(buf, dev->parent);
635 struct usb_device *udev = dev_get_parent_priv(dev);
636 struct usb_device_descriptor *desc = &udev->descriptor;
638 udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
639 udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB_CLASS;
640 udp->dp.length = sizeof(*udp);
641 udp->vendor_id = desc->idVendor;
642 udp->product_id = desc->idProduct;
643 udp->device_class = desc->bDeviceClass;
644 udp->device_subclass = desc->bDeviceSubClass;
645 udp->device_protocol = desc->bDeviceProtocol;
650 debug("%s(%u) %s: unhandled device class: %s (%u)\n",
651 __FILE__, __LINE__, __func__,
652 dev->name, dev->driver->id);
653 return dp_fill(buf, dev->parent);
657 /* Construct a device-path from a device: */
658 struct efi_device_path *efi_dp_from_dev(struct udevice *dev)
662 start = buf = dp_alloc(dp_size(dev) + sizeof(END));
665 buf = dp_fill(buf, dev);
666 *((struct efi_device_path *)buf) = END;
672 static unsigned dp_part_size(struct blk_desc *desc, int part)
679 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
682 dev = desc->bdev->parent;
683 dpsize = dp_size(dev);
686 dpsize = sizeof(ROOT) + sizeof(struct efi_device_path_usb);
689 if (part == 0) /* the actual disk, not a partition */
692 if (desc->part_type == PART_TYPE_ISO)
693 dpsize += sizeof(struct efi_device_path_cdrom_path);
695 dpsize += sizeof(struct efi_device_path_hard_drive_path);
701 * Create a device node for a block device partition.
703 * @buf buffer to which the device path is written
704 * @desc block device descriptor
705 * @part partition number, 0 identifies a block device
707 static void *dp_part_node(void *buf, struct blk_desc *desc, int part)
709 disk_partition_t info;
711 part_get_info(desc, part, &info);
713 if (desc->part_type == PART_TYPE_ISO) {
714 struct efi_device_path_cdrom_path *cddp = buf;
716 cddp->boot_entry = part;
717 cddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
718 cddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_CDROM_PATH;
719 cddp->dp.length = sizeof(*cddp);
720 cddp->partition_start = info.start;
721 cddp->partition_size = info.size;
725 struct efi_device_path_hard_drive_path *hddp = buf;
727 hddp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
728 hddp->dp.sub_type = DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH;
729 hddp->dp.length = sizeof(*hddp);
730 hddp->partition_number = part;
731 hddp->partition_start = info.start;
732 hddp->partition_end = info.size;
733 if (desc->part_type == PART_TYPE_EFI)
734 hddp->partmap_type = 2;
736 hddp->partmap_type = 1;
738 switch (desc->sig_type) {
741 hddp->signature_type = 0;
742 memset(hddp->partition_signature, 0,
743 sizeof(hddp->partition_signature));
746 hddp->signature_type = 1;
747 memset(hddp->partition_signature, 0,
748 sizeof(hddp->partition_signature));
749 memcpy(hddp->partition_signature, &desc->mbr_sig,
750 sizeof(desc->mbr_sig));
753 hddp->signature_type = 2;
754 memcpy(hddp->partition_signature, &desc->guid_sig,
755 sizeof(hddp->partition_signature));
766 * Create a device path for a block device or one of its partitions.
768 * @buf buffer to which the device path is written
769 * @desc block device descriptor
770 * @part partition number, 0 identifies a block device
772 static void *dp_part_fill(void *buf, struct blk_desc *desc, int part)
777 int ret = blk_find_device(desc->if_type, desc->devnum, &dev);
780 dev = desc->bdev->parent;
781 buf = dp_fill(buf, dev);
785 * We *could* make a more accurate path, by looking at if_type
786 * and handling all the different cases like we do for non-
787 * legacy (i.e. CONFIG_BLK=y) case. But most important thing
788 * is just to have a unique device-path for if_type+devnum.
789 * So map things to a fictitious USB device.
791 struct efi_device_path_usb *udp;
793 memcpy(buf, &ROOT, sizeof(ROOT));
797 udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
798 udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB;
799 udp->dp.length = sizeof(*udp);
800 udp->parent_port_number = desc->if_type;
801 udp->usb_interface = desc->devnum;
805 if (part == 0) /* the actual disk, not a partition */
808 return dp_part_node(buf, desc, part);
811 /* Construct a device-path from a partition on a block device: */
812 struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part)
816 start = buf = dp_alloc(dp_part_size(desc, part) + sizeof(END));
820 buf = dp_part_fill(buf, desc, part);
822 *((struct efi_device_path *)buf) = END;
828 * Create a device node for a block device partition.
830 * @buf buffer to which the device path is written
831 * @desc block device descriptor
832 * @part partition number, 0 identifies a block device
834 struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part)
839 if (desc->part_type == PART_TYPE_ISO)
840 dpsize = sizeof(struct efi_device_path_cdrom_path);
842 dpsize = sizeof(struct efi_device_path_hard_drive_path);
843 buf = dp_alloc(dpsize);
845 dp_part_node(buf, desc, part);
851 * path_to_uefi() - convert UTF-8 path to an UEFI style path
853 * Convert UTF-8 path to a UEFI style path (i.e. with backslashes as path
854 * separators and UTF-16).
856 * @src: source buffer
857 * @uefi: target buffer, possibly unaligned
859 static void path_to_uefi(void *uefi, const char *src)
864 * efi_set_bootdev() calls this routine indirectly before the UEFI
865 * subsystem is initialized. So we cannot assume unaligned access to be
871 s32 code = utf8_get(&src);
875 else if (code == '/')
877 utf16_put(code, &pos);
883 * If desc is NULL, this creates a path with only the file component,
884 * otherwise it creates a full path with both device and file components
886 struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part,
889 struct efi_device_path_file_path *fp;
891 unsigned dpsize = 0, fpsize;
894 dpsize = dp_part_size(desc, part);
896 fpsize = sizeof(struct efi_device_path) +
897 2 * (utf8_utf16_strlen(path) + 1);
900 start = buf = dp_alloc(dpsize + sizeof(END));
905 buf = dp_part_fill(buf, desc, part);
909 fp->dp.type = DEVICE_PATH_TYPE_MEDIA_DEVICE;
910 fp->dp.sub_type = DEVICE_PATH_SUB_TYPE_FILE_PATH;
911 fp->dp.length = fpsize;
912 path_to_uefi(fp->str, path);
915 *((struct efi_device_path *)buf) = END;
921 struct efi_device_path *efi_dp_from_eth(void)
923 #ifndef CONFIG_DM_ETH
924 struct efi_device_path_mac_addr *ndp;
929 assert(eth_get_dev());
932 dpsize += dp_size(eth_get_dev());
934 dpsize += sizeof(ROOT);
935 dpsize += sizeof(*ndp);
938 start = buf = dp_alloc(dpsize + sizeof(END));
943 buf = dp_fill(buf, eth_get_dev());
945 memcpy(buf, &ROOT, sizeof(ROOT));
949 ndp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE;
950 ndp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR;
951 ndp->dp.length = sizeof(*ndp);
952 ndp->if_type = 1; /* Ethernet */
953 memcpy(ndp->mac.addr, eth_get_ethaddr(), ARP_HLEN);
957 *((struct efi_device_path *)buf) = END;
963 /* Construct a device-path for memory-mapped image */
964 struct efi_device_path *efi_dp_from_mem(uint32_t memory_type,
965 uint64_t start_address,
966 uint64_t end_address)
968 struct efi_device_path_memory *mdp;
971 start = buf = dp_alloc(sizeof(*mdp) + sizeof(END));
976 mdp->dp.type = DEVICE_PATH_TYPE_HARDWARE_DEVICE;
977 mdp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MEMORY;
978 mdp->dp.length = sizeof(*mdp);
979 mdp->memory_type = memory_type;
980 mdp->start_address = start_address;
981 mdp->end_address = end_address;
984 *((struct efi_device_path *)buf) = END;
990 * efi_dp_split_file_path() - split of relative file path from device path
992 * Given a device path indicating a file on a device, separate the device
993 * path in two: the device path of the actual device and the file path
994 * relative to this device.
996 * @full_path: device path including device and file path
997 * @device_path: path of the device
998 * @file_path: relative path of the file or NULL if there is none
999 * Return: status code
1001 efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path,
1002 struct efi_device_path **device_path,
1003 struct efi_device_path **file_path)
1005 struct efi_device_path *p, *dp, *fp = NULL;
1007 *device_path = NULL;
1009 dp = efi_dp_dup(full_path);
1011 return EFI_OUT_OF_RESOURCES;
1013 while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH)) {
1020 return EFI_OUT_OF_RESOURCES;
1021 p->type = DEVICE_PATH_TYPE_END;
1022 p->sub_type = DEVICE_PATH_SUB_TYPE_END;
1023 p->length = sizeof(*p);
1031 efi_status_t efi_dp_from_name(const char *dev, const char *devnr,
1033 struct efi_device_path **device,
1034 struct efi_device_path **file)
1037 struct blk_desc *desc = NULL;
1038 disk_partition_t fs_partition;
1040 char filename[32] = { 0 }; /* dp->str is u16[32] long */
1044 return EFI_INVALID_PARAMETER;
1046 is_net = !strcmp(dev, "Net");
1048 part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition,
1050 if (part < 0 || !desc)
1051 return EFI_INVALID_PARAMETER;
1054 *device = efi_dp_from_part(desc, part);
1058 *device = efi_dp_from_eth();
1065 snprintf(filename, sizeof(filename), "%s", path);
1066 /* DOS style file path: */
1068 while ((s = strchr(s, '/')))
1070 *file = efi_dp_from_file(((!is_net && device) ? desc : NULL),