The driver name is typically not unique so using that as a basis for the block and bootdev devices makes them hard to distinguish. This happens when there are multiple USB controllers using the same driver.
Make use of the parent-device name and the hub port number. This gives a reasonable chance that the name is unique. Signed-off-by: Simon Glass <s...@chromium.org> --- drivers/usb/host/usb-uclass.c | 14 ++++++++++++-- test/boot/bootdev.c | 12 ++++++------ test/boot/bootflow.c | 6 +++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c index bfec303e7af..43c8ec352f0 100644 --- a/drivers/usb/host/usb-uclass.c +++ b/drivers/usb/host/usb-uclass.c @@ -574,10 +574,20 @@ static int usb_find_and_bind_driver(struct udevice *parent, struct usb_dev_plat *plat; for (id = entry->match; id->match_flags; id++) { + char dev_name[30], *str; + if (!usb_match_one_id(desc, iface, id)) continue; drv = entry->driver; + snprintf(dev_name, sizeof(dev_name), "%s.p%d.%s", + parent->name, port, drv->name); + str = strdup(dev_name); + if (!str) { + ret = -ENOMEM; + goto error; + } + /* * We could pass the descriptor to the driver as * plat (instead of NULL) and allow its bind() @@ -586,10 +596,10 @@ static int usb_find_and_bind_driver(struct udevice *parent, * find another driver. For now this doesn't seem * necesssary, so just bind the first match. */ - ret = device_bind(parent, drv, drv->name, NULL, node, - &dev); + ret = device_bind(parent, drv, str, NULL, node, &dev); if (ret) goto error; + device_set_name_alloced(dev); debug("%s: Match found: %s\n", __func__, drv->name); dev->driver_data = id->driver_info; plat = dev_get_parent_plat(dev); diff --git a/test/boot/bootdev.c b/test/boot/bootdev.c index 4333f3c977c..7ef724f65bb 100644 --- a/test/boot/bootdev.c +++ b/test/boot/bootdev.c @@ -231,7 +231,7 @@ static int bootdev_test_order(struct unit_test_state *uts) ut_asserteq(6, iter.num_devs); ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name); ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); - ut_asserteq_str("usb_mass_storage.lun0.bootdev", + ut_asserteq_str("hub.p1.usb_mass_storage.lun0.bootdev", iter.dev_used[2]->name); bootflow_iter_uninit(&iter); @@ -277,7 +277,7 @@ static int bootdev_test_order(struct unit_test_state *uts) ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name); ut_asserteq_str("mmc0.bootdev", iter.dev_used[2]->name); - ut_asserteq_str("usb_mass_storage.lun0.bootdev", + ut_asserteq_str("hub.p1.usb_mass_storage.lun0.bootdev", iter.dev_used[3]->name); bootflow_iter_uninit(&iter); @@ -343,11 +343,11 @@ static int bootdev_test_prio(struct unit_test_state *uts) ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(7, iter.num_devs); ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); - ut_asserteq_str("usb_mass_storage.lun0.bootdev", + ut_asserteq_str("hub.p1.usb_mass_storage.lun0.bootdev", iter.dev_used[3]->name); ut_assertok(bootdev_get_sibling_blk(iter.dev_used[3], &blk)); - ut_asserteq_str("usb_mass_storage.lun0", blk->name); + ut_asserteq_str("hub.p1.usb_mass_storage.lun0", blk->name); /* adjust the priority of the first USB bootdev to the highest */ ucp = dev_get_uclass_plat(iter.dev_used[3]); @@ -366,7 +366,7 @@ static int bootdev_test_prio(struct unit_test_state *uts) ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); ut_asserteq(8, iter.num_devs); - ut_asserteq_str("usb_mass_storage.lun0.bootdev", + ut_asserteq_str("hub.p1.usb_mass_storage.lun0.bootdev", iter.dev_used[0]->name); ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); @@ -612,7 +612,7 @@ static int bootdev_test_hunt_label(struct unit_test_state *uts) test_set_skip_delays(true); ut_assertok(bootdev_hunt_and_find_by_label("usb", &dev, &mflags)); ut_assertnonnull(dev); - ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); + ut_asserteq_str("hub.p1.usb_mass_storage.lun0.bootdev", dev->name); ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); ut_assert_console_end(); diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 3ee87145dc8..f1341312dac 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1307,9 +1307,9 @@ static int bootflow_efi(struct unit_test_state *uts) ut_assert_nextlinen("---"); ut_assert_nextlinen(" 0 extlinux"); ut_assert_nextlinen( - " 1 efi ready usb_mass_ 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI"); + " 1 efi ready usb_mass_ 1 hub.p2.usb_mass_storage.l /EFI/BOOT/BOOTSBOX.EFI"); ut_assert_nextlinen( - " 2 extlinux ready usb_mass_ 1 usb_mass_storage.lun0.boo /extlinux/extlinux.conf"); + " 2 extlinux ready usb_mass_ 1 hub.p4.usb_mass_storage.l /extlinux/extlinux.conf"); ut_assert_nextlinen("---"); ut_assert_skip_to_line("(3 bootflows, 3 valid)"); ut_assert_console_end(); @@ -1325,7 +1325,7 @@ static int bootflow_efi(struct unit_test_state *uts) ut_asserteq(1, run_command("bootflow boot", 0)); ut_assert_nextline( - "** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi"); + "** Booting bootflow 'hub.p2.usb_mass_storage.lun0.bootdev.part_1' with efi"); if (IS_ENABLED(CONFIG_LOGF_FUNC)) ut_assert_skip_to_line(" efi_run_image() Booting /\\EFI\\BOOT\\BOOTSBOX.EFI"); else -- 2.43.0