Commit 98d48bdf415e318a11f9f9a44dff2b70aef3fb10
Committed by
Alexander Graf
1 parent
b3dd14b6b1
Exists in
smarc_8mq_lf_v2020.04
and in
17 other branches
efi_loader: provide a function to create a partition node
Provide new function efi_dp_part_node() to create a device node for a partition. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
Showing 2 changed files with 72 additions and 36 deletions Side-by-side Diff
include/efi_loader.h
... | ... | @@ -300,6 +300,8 @@ |
300 | 300 | |
301 | 301 | struct efi_device_path *efi_dp_from_dev(struct udevice *dev); |
302 | 302 | struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part); |
303 | +/* Create a device node for a block device partition. */ | |
304 | +struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part); | |
303 | 305 | struct efi_device_path *efi_dp_from_file(struct blk_desc *desc, int part, |
304 | 306 | const char *path); |
305 | 307 | struct efi_device_path *efi_dp_from_eth(void); |
lib/efi_loader/efi_device_path.c
... | ... | @@ -484,50 +484,16 @@ |
484 | 484 | } |
485 | 485 | |
486 | 486 | /* |
487 | - * Create a device path for a block device or one of its partitions. | |
487 | + * Create a device node for a block device partition. | |
488 | 488 | * |
489 | 489 | * @buf buffer to which the device path is wirtten |
490 | 490 | * @desc block device descriptor |
491 | 491 | * @part partition number, 0 identifies a block device |
492 | 492 | */ |
493 | -static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) | |
493 | +static void *dp_part_node(void *buf, struct blk_desc *desc, int part) | |
494 | 494 | { |
495 | 495 | disk_partition_t info; |
496 | 496 | |
497 | -#ifdef CONFIG_BLK | |
498 | - { | |
499 | - struct udevice *dev; | |
500 | - int ret = blk_find_device(desc->if_type, desc->devnum, &dev); | |
501 | - | |
502 | - if (ret) | |
503 | - dev = desc->bdev->parent; | |
504 | - buf = dp_fill(buf, dev); | |
505 | - } | |
506 | -#else | |
507 | - /* | |
508 | - * We *could* make a more accurate path, by looking at if_type | |
509 | - * and handling all the different cases like we do for non- | |
510 | - * legacy (ie CONFIG_BLK=y) case. But most important thing | |
511 | - * is just to have a unique device-path for if_type+devnum. | |
512 | - * So map things to a fictitious USB device. | |
513 | - */ | |
514 | - struct efi_device_path_usb *udp; | |
515 | - | |
516 | - memcpy(buf, &ROOT, sizeof(ROOT)); | |
517 | - buf += sizeof(ROOT); | |
518 | - | |
519 | - udp = buf; | |
520 | - udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; | |
521 | - udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB; | |
522 | - udp->dp.length = sizeof(*udp); | |
523 | - udp->parent_port_number = desc->if_type; | |
524 | - udp->usb_interface = desc->devnum; | |
525 | - buf = &udp[1]; | |
526 | -#endif | |
527 | - | |
528 | - if (part == 0) /* the actual disk, not a partition */ | |
529 | - return buf; | |
530 | - | |
531 | 497 | part_get_info(desc, part, &info); |
532 | 498 | |
533 | 499 | if (desc->part_type == PART_TYPE_ISO) { |
534 | 500 | |
... | ... | @@ -582,7 +548,52 @@ |
582 | 548 | return buf; |
583 | 549 | } |
584 | 550 | |
551 | +/* | |
552 | + * Create a device path for a block device or one of its partitions. | |
553 | + * | |
554 | + * @buf buffer to which the device path is wirtten | |
555 | + * @desc block device descriptor | |
556 | + * @part partition number, 0 identifies a block device | |
557 | + */ | |
558 | +static void *dp_part_fill(void *buf, struct blk_desc *desc, int part) | |
559 | +{ | |
560 | +#ifdef CONFIG_BLK | |
561 | + { | |
562 | + struct udevice *dev; | |
563 | + int ret = blk_find_device(desc->if_type, desc->devnum, &dev); | |
585 | 564 | |
565 | + if (ret) | |
566 | + dev = desc->bdev->parent; | |
567 | + buf = dp_fill(buf, dev); | |
568 | + } | |
569 | +#else | |
570 | + /* | |
571 | + * We *could* make a more accurate path, by looking at if_type | |
572 | + * and handling all the different cases like we do for non- | |
573 | + * legacy (ie CONFIG_BLK=y) case. But most important thing | |
574 | + * is just to have a unique device-path for if_type+devnum. | |
575 | + * So map things to a fictitious USB device. | |
576 | + */ | |
577 | + struct efi_device_path_usb *udp; | |
578 | + | |
579 | + memcpy(buf, &ROOT, sizeof(ROOT)); | |
580 | + buf += sizeof(ROOT); | |
581 | + | |
582 | + udp = buf; | |
583 | + udp->dp.type = DEVICE_PATH_TYPE_MESSAGING_DEVICE; | |
584 | + udp->dp.sub_type = DEVICE_PATH_SUB_TYPE_MSG_USB; | |
585 | + udp->dp.length = sizeof(*udp); | |
586 | + udp->parent_port_number = desc->if_type; | |
587 | + udp->usb_interface = desc->devnum; | |
588 | + buf = &udp[1]; | |
589 | +#endif | |
590 | + | |
591 | + if (part == 0) /* the actual disk, not a partition */ | |
592 | + return buf; | |
593 | + | |
594 | + return dp_part_node(buf, desc, part); | |
595 | +} | |
596 | + | |
586 | 597 | /* Construct a device-path from a partition on a blk device: */ |
587 | 598 | struct efi_device_path *efi_dp_from_part(struct blk_desc *desc, int part) |
588 | 599 | { |
... | ... | @@ -597,6 +608,29 @@ |
597 | 608 | *((struct efi_device_path *)buf) = END; |
598 | 609 | |
599 | 610 | return start; |
611 | +} | |
612 | + | |
613 | +/* | |
614 | + * Create a device node for a block device partition. | |
615 | + * | |
616 | + * @buf buffer to which the device path is wirtten | |
617 | + * @desc block device descriptor | |
618 | + * @part partition number, 0 identifies a block device | |
619 | + */ | |
620 | +struct efi_device_path *efi_dp_part_node(struct blk_desc *desc, int part) | |
621 | +{ | |
622 | + efi_uintn_t dpsize; | |
623 | + void *buf; | |
624 | + | |
625 | + if (desc->part_type == PART_TYPE_ISO) | |
626 | + dpsize = sizeof(struct efi_device_path_cdrom_path); | |
627 | + else | |
628 | + dpsize = sizeof(struct efi_device_path_hard_drive_path); | |
629 | + buf = dp_alloc(dpsize); | |
630 | + | |
631 | + dp_part_node(buf, desc, part); | |
632 | + | |
633 | + return buf; | |
600 | 634 | } |
601 | 635 | |
602 | 636 | /* convert path to an UEFI style path (ie. DOS style backslashes and utf16) */ |