@@ -113,9 +113,11 @@ static int bootdev_test_labels(struct unit_test_state *uts)
113113
114114 /* Check method flags */
115115 ut_assertok (bootdev_find_by_label ("pxe" , & dev , & mflags ));
116- ut_asserteq (BOOTFLOW_METHF_PXE_ONLY , mflags );
116+ ut_asserteq (BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY ,
117+ mflags );
117118 ut_assertok (bootdev_find_by_label ("dhcp" , & dev , & mflags ));
118- ut_asserteq (BOOTFLOW_METHF_DHCP_ONLY , mflags );
119+ ut_asserteq (BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY ,
120+ mflags );
119121
120122 /* Check invalid uclass */
121123 ut_asserteq (- EINVAL , bootdev_find_by_label ("fred0" , & dev , & mflags ));
@@ -128,6 +130,62 @@ static int bootdev_test_labels(struct unit_test_state *uts)
128130BOOTSTD_TEST (bootdev_test_labels , UT_TESTF_DM | UT_TESTF_SCAN_FDT |
129131 UT_TESTF_ETH_BOOTDEV );
130132
133+ /* Check bootdev_find_by_any() */
134+ static int bootdev_test_any (struct unit_test_state * uts )
135+ {
136+ struct udevice * dev , * media ;
137+ int mflags ;
138+
139+ /*
140+ * with ethernet enabled we have 8 devices ahead of the mmc ones:
141+ *
142+ * ut_assertok(run_command("bootdev list", 0));
143+ * Seq Probed Status Uclass Name
144+ * --- ------ ------ -------- ------------------
145+ * 0 [ + ] OK ethernet eth@10002000.bootdev
146+ * 1 [ ] OK ethernet eth@10003000.bootdev
147+ * 2 [ ] OK ethernet sbe5.bootdev
148+ * 3 [ ] OK ethernet eth@10004000.bootdev
149+ * 4 [ ] OK ethernet phy-test-eth.bootdev
150+ * 5 [ ] OK ethernet dsa-test-eth.bootdev
151+ * 6 [ ] OK ethernet dsa-test@0.bootdev
152+ * 7 [ ] OK ethernet dsa-test@1.bootdev
153+ * 8 [ ] OK mmc mmc2.bootdev
154+ * 9 [ + ] OK mmc mmc1.bootdev
155+ * a [ ] OK mmc mmc0.bootdev
156+ */
157+ console_record_reset_enable ();
158+ ut_assertok (bootdev_find_by_any ("8" , & dev , & mflags ));
159+ ut_asserteq (UCLASS_BOOTDEV , device_get_uclass_id (dev ));
160+ ut_asserteq (BOOTFLOW_METHF_SINGLE_DEV , mflags );
161+ media = dev_get_parent (dev );
162+ ut_asserteq (UCLASS_MMC , device_get_uclass_id (media ));
163+ ut_asserteq_str ("mmc2" , media -> name );
164+ ut_assert_console_end ();
165+
166+ /* there should not be this many bootdevs */
167+ ut_asserteq (- ENODEV , bootdev_find_by_any ("50" , & dev , & mflags ));
168+ ut_assert_nextline ("Cannot find '50' (err=-19)" );
169+ ut_assert_console_end ();
170+
171+ /* Check method flags */
172+ ut_assertok (bootdev_find_by_any ("pxe" , & dev , & mflags ));
173+ ut_asserteq (BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY ,
174+ mflags );
175+
176+ /* Check invalid uclass */
177+ mflags = 123 ;
178+ ut_asserteq (- EINVAL , bootdev_find_by_any ("fred0" , & dev , & mflags ));
179+ ut_assert_nextline ("Unknown uclass 'fred0' in label" );
180+ ut_assert_nextline ("Cannot find bootdev 'fred0' (err=-22)" );
181+ ut_asserteq (123 , mflags );
182+ ut_assert_console_end ();
183+
184+ return 0 ;
185+ }
186+ BOOTSTD_TEST (bootdev_test_any , UT_TESTF_DM | UT_TESTF_SCAN_FDT |
187+ UT_TESTF_ETH_BOOTDEV );
188+
131189/* Check bootdev ordering with the bootdev-order property */
132190static int bootdev_test_order (struct unit_test_state * uts )
133191{
@@ -399,3 +457,56 @@ static int bootdev_test_hunt_prio(struct unit_test_state *uts)
399457 return 0 ;
400458}
401459BOOTSTD_TEST (bootdev_test_hunt_prio , UT_TESTF_DM | UT_TESTF_SCAN_FDT );
460+
461+ /* Check hunting for bootdevs with a particular label */
462+ static int bootdev_test_hunt_label (struct unit_test_state * uts )
463+ {
464+ struct udevice * dev , * old ;
465+ struct bootstd_priv * std ;
466+ int mflags ;
467+
468+ /* get access to the used hunters */
469+ ut_assertok (bootstd_get_priv (& std ));
470+
471+ /* scan an unknown uclass */
472+ console_record_reset_enable ();
473+ old = (void * )& mflags ; /* arbitrary pointer to check against dev */
474+ dev = old ;
475+ mflags = 123 ;
476+ ut_asserteq (- EINVAL ,
477+ bootdev_hunt_and_find_by_label ("fred" , & dev , & mflags ));
478+ ut_assert_nextline ("Unknown uclass 'fred' in label" );
479+ ut_asserteq_ptr (old , dev );
480+ ut_asserteq (123 , mflags );
481+ ut_assert_console_end ();
482+ ut_asserteq (0 , std -> hunters_used );
483+
484+ /* scan an invalid mmc controllers */
485+ ut_asserteq (- ENOENT ,
486+ bootdev_hunt_and_find_by_label ("mmc4" , & dev , & mflags ));
487+ ut_asserteq_ptr (old , dev );
488+ ut_asserteq (123 , mflags );
489+ ut_assert_nextline ("Unknown seq 4 for label 'mmc4'" );
490+ ut_assert_console_end ();
491+
492+ ut_assertok (bootstd_test_check_mmc_hunter (uts ));
493+
494+ /* scan for a particular mmc controller */
495+ ut_assertok (bootdev_hunt_and_find_by_label ("mmc1" , & dev , & mflags ));
496+ ut_assertnonnull (dev );
497+ ut_asserteq_str ("mmc1.bootdev" , dev -> name );
498+ ut_asserteq (0 , mflags );
499+ ut_assert_console_end ();
500+
501+ /* scan all of usb */
502+ test_set_skip_delays (true);
503+ ut_assertok (bootdev_hunt_and_find_by_label ("usb" , & dev , & mflags ));
504+ ut_assertnonnull (dev );
505+ ut_asserteq_str ("usb_mass_storage.lun0.bootdev" , dev -> name );
506+ ut_asserteq (BOOTFLOW_METHF_SINGLE_UCLASS , mflags );
507+ ut_assert_nextlinen ("Bus usb@1: scanning bus usb@1" );
508+ ut_assert_console_end ();
509+
510+ return 0 ;
511+ }
512+ BOOTSTD_TEST (bootdev_test_hunt_label , UT_TESTF_DM | UT_TESTF_SCAN_FDT );
0 commit comments