Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for bootdev functions. All start with 'bootdev' |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootstd.h> |
| 11 | #include <dm.h> |
| 12 | #include <bootdev.h> |
| 13 | #include <bootflow.h> |
| 14 | #include <mapmem.h> |
| 15 | #include <os.h> |
| 16 | #include <test/suites.h> |
| 17 | #include <test/ut.h> |
| 18 | #include "bootstd_common.h" |
| 19 | |
| 20 | /* Allow reseting the USB-started flag */ |
| 21 | extern char usb_started; |
| 22 | |
| 23 | /* Check 'bootdev list' command */ |
| 24 | static int bootdev_test_cmd_list(struct unit_test_state *uts) |
| 25 | { |
| 26 | int probed; |
| 27 | |
| 28 | console_record_reset_enable(); |
| 29 | for (probed = 0; probed < 2; probed++) { |
| 30 | int probe_ch = probed ? '+' : ' '; |
| 31 | |
| 32 | ut_assertok(run_command(probed ? "bootdev list -p" : |
| 33 | "bootdev list", 0)); |
| 34 | ut_assert_nextline("Seq Probed Status Uclass Name"); |
| 35 | ut_assert_nextlinen("---"); |
| 36 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 0, probe_ch, "OK", |
| 37 | "mmc", "mmc2.bootdev"); |
| 38 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 1, probe_ch, "OK", |
| 39 | "mmc", "mmc1.bootdev"); |
| 40 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 2, probe_ch, "OK", |
| 41 | "mmc", "mmc0.bootdev"); |
| 42 | ut_assert_nextlinen("---"); |
| 43 | ut_assert_nextline("(3 bootdevs)"); |
| 44 | ut_assert_console_end(); |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | BOOTSTD_TEST(bootdev_test_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 50 | |
| 51 | /* Check 'bootdev select' and 'info' commands */ |
| 52 | static int bootdev_test_cmd_select(struct unit_test_state *uts) |
| 53 | { |
| 54 | struct bootstd_priv *std; |
| 55 | |
| 56 | /* get access to the CLI's cur_bootdev */ |
| 57 | ut_assertok(bootstd_get_priv(&std)); |
| 58 | |
| 59 | console_record_reset_enable(); |
| 60 | ut_asserteq(1, run_command("bootdev info", 0)); |
| 61 | ut_assert_nextlinen("Please use"); |
| 62 | ut_assert_console_end(); |
| 63 | |
| 64 | /* select by sequence */ |
| 65 | ut_assertok(run_command("bootdev select 0", 0)); |
| 66 | ut_assert_console_end(); |
| 67 | |
| 68 | ut_assertok(run_command("bootdev info", 0)); |
| 69 | ut_assert_nextline("Name: mmc2.bootdev"); |
| 70 | ut_assert_nextline("Sequence: 0"); |
| 71 | ut_assert_nextline("Status: Probed"); |
| 72 | ut_assert_nextline("Uclass: mmc"); |
| 73 | ut_assert_nextline("Bootflows: 0 (0 valid)"); |
| 74 | ut_assert_console_end(); |
| 75 | |
| 76 | /* select by bootdev name */ |
| 77 | ut_assertok(run_command("bootdev select mmc1.bootdev", 0)); |
| 78 | ut_assert_console_end(); |
| 79 | ut_assertnonnull(std->cur_bootdev); |
| 80 | ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name); |
| 81 | |
| 82 | /* select by bootdev label*/ |
| 83 | ut_assertok(run_command("bootdev select mmc1", 0)); |
| 84 | ut_assert_console_end(); |
| 85 | ut_assertnonnull(std->cur_bootdev); |
| 86 | ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name); |
| 87 | |
| 88 | /* deselect */ |
| 89 | ut_assertok(run_command("bootdev select", 0)); |
| 90 | ut_assert_console_end(); |
| 91 | ut_assertnull(std->cur_bootdev); |
| 92 | |
| 93 | ut_asserteq(1, run_command("bootdev info", 0)); |
| 94 | ut_assert_nextlinen("Please use"); |
| 95 | ut_assert_console_end(); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | BOOTSTD_TEST(bootdev_test_cmd_select, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 100 | |
| 101 | /* Check bootdev labels */ |
| 102 | static int bootdev_test_labels(struct unit_test_state *uts) |
| 103 | { |
| 104 | struct udevice *dev, *media; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 105 | int mflags = 0; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 106 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 107 | ut_assertok(bootdev_find_by_label("mmc2", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 108 | ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev)); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 109 | ut_asserteq(0, mflags); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 110 | media = dev_get_parent(dev); |
| 111 | ut_asserteq(UCLASS_MMC, device_get_uclass_id(media)); |
| 112 | ut_asserteq_str("mmc2", media->name); |
| 113 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 114 | /* Check method flags */ |
| 115 | ut_assertok(bootdev_find_by_label("pxe", &dev, &mflags)); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 116 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 117 | mflags); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 118 | ut_assertok(bootdev_find_by_label("dhcp", &dev, &mflags)); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 119 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, |
| 120 | mflags); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 121 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 122 | /* Check invalid uclass */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 123 | ut_asserteq(-EINVAL, bootdev_find_by_label("fred0", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 124 | |
| 125 | /* Check unknown sequence number */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 126 | ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 127 | |
| 128 | return 0; |
| 129 | } |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 130 | BOOTSTD_TEST(bootdev_test_labels, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 131 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 132 | |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 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 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 189 | /* Check bootdev ordering with the bootdev-order property */ |
| 190 | static int bootdev_test_order(struct unit_test_state *uts) |
| 191 | { |
| 192 | struct bootflow_iter iter; |
| 193 | struct bootflow bflow; |
| 194 | |
| 195 | /* |
| 196 | * First try the order set by the bootdev-order property |
| 197 | * Like all sandbox unit tests this relies on the devicetree setting up |
| 198 | * the required devices: |
| 199 | * |
| 200 | * mmc0 - nothing connected |
| 201 | * mmc1 - connected to mmc1.img file |
| 202 | * mmc2 - nothing connected |
| 203 | */ |
| 204 | ut_assertok(env_set("boot_targets", NULL)); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 205 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 206 | ut_asserteq(2, iter.num_devs); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 207 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); |
| 208 | ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 209 | bootflow_iter_uninit(&iter); |
| 210 | |
| 211 | /* Use the environment variable to override it */ |
| 212 | ut_assertok(env_set("boot_targets", "mmc1 mmc2")); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 213 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 214 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 215 | ut_asserteq(2, iter.num_devs); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 216 | ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name); |
| 217 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 218 | bootflow_iter_uninit(&iter); |
| 219 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 223 | |
| 224 | /* Check default bootdev ordering */ |
| 225 | static int bootdev_test_order_default(struct unit_test_state *uts) |
| 226 | { |
| 227 | struct bootflow_iter iter; |
| 228 | struct bootflow bflow; |
| 229 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 230 | /* |
| 231 | * Now drop both orderings, to check the default (prioriy/sequence) |
| 232 | * ordering |
| 233 | */ |
| 234 | ut_assertok(env_set("boot_targets", NULL)); |
| 235 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 236 | |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 237 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 238 | ut_asserteq(2, iter.num_devs); |
| 239 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); |
| 240 | ut_asserteq_str("mmc1.bootdev", iter.dev_used[1]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 241 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 242 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 243 | ut_asserteq(3, iter.num_devs); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 244 | ut_asserteq_str("mmc0.bootdev", iter.dev_used[2]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 245 | bootflow_iter_uninit(&iter); |
| 246 | |
| 247 | return 0; |
| 248 | } |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 249 | BOOTSTD_TEST(bootdev_test_order_default, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 250 | |
| 251 | /* Check bootdev ordering with the uclass priority */ |
| 252 | static int bootdev_test_prio(struct unit_test_state *uts) |
| 253 | { |
| 254 | struct bootdev_uc_plat *ucp; |
| 255 | struct bootflow_iter iter; |
| 256 | struct bootflow bflow; |
| 257 | struct udevice *blk; |
| 258 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 259 | test_set_skip_delays(true); |
| 260 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 261 | /* disable ethernet since the hunter will run dhcp */ |
| 262 | test_set_eth_enable(false); |
| 263 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 264 | /* Start up USB which gives us three additional bootdevs */ |
| 265 | usb_started = false; |
| 266 | ut_assertok(run_command("usb start", 0)); |
| 267 | |
| 268 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 269 | |
| 270 | /* 3 MMC and 3 USB bootdevs: MMC should come before USB */ |
| 271 | console_record_reset_enable(); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 272 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 273 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 274 | ut_asserteq(6, iter.num_devs); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 275 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 276 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 277 | iter.dev_used[3]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 278 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 279 | ut_assertok(bootdev_get_sibling_blk(iter.dev_used[3], &blk)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 280 | ut_asserteq_str("usb_mass_storage.lun0", blk->name); |
| 281 | |
| 282 | /* adjust the priority of the first USB bootdev to the highest */ |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 283 | ucp = dev_get_uclass_plat(iter.dev_used[3]); |
| 284 | ucp->prio = BOOTDEVP_1_PRE_SCAN; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 285 | |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 286 | /* try again but enable hunting, which brings in SCSI */ |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 287 | bootflow_iter_uninit(&iter); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 288 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWF_HUNT, |
| 289 | &bflow)); |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 290 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
| 291 | ut_asserteq(7, iter.num_devs); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 292 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
Simon Glass | cb2a5cd | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 293 | iter.dev_used[0]->name); |
| 294 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[1]->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 295 | |
| 296 | return 0; |
| 297 | } |
| 298 | BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 299 | |
| 300 | /* Check listing hunters */ |
| 301 | static int bootdev_test_hunter(struct unit_test_state *uts) |
| 302 | { |
| 303 | struct bootstd_priv *std; |
| 304 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 305 | test_set_skip_delays(true); |
| 306 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 307 | /* get access to the used hunters */ |
| 308 | ut_assertok(bootstd_get_priv(&std)); |
| 309 | |
| 310 | console_record_reset_enable(); |
| 311 | bootdev_list_hunters(std); |
| 312 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 313 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 314 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 315 | ut_assert_nextline(" 1 simple_bus (none)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 316 | ut_assert_nextline(" 5 ide ide_bootdev"); |
| 317 | ut_assert_nextline(" 2 mmc mmc_bootdev"); |
| 318 | ut_assert_nextline(" 4 nvme nvme_bootdev"); |
| 319 | ut_assert_nextline(" 4 scsi scsi_bootdev"); |
| 320 | ut_assert_nextline(" 4 spi_flash sf_bootdev"); |
| 321 | ut_assert_nextline(" 5 usb usb_bootdev"); |
| 322 | ut_assert_nextline(" 4 virtio virtio_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 323 | ut_assert_nextline("(total hunters: 9)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 324 | ut_assert_console_end(); |
| 325 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 326 | ut_assertok(bootdev_hunt("usb1", false)); |
| 327 | ut_assert_nextline( |
| 328 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
Simon Glass | 1248d2b | 2023-01-17 10:47:34 -0700 | [diff] [blame] | 329 | ut_assert_console_end(); |
| 330 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 331 | /* USB is sixth in the list, so bit 7 */ |
| 332 | ut_asserteq(BIT(7), std->hunters_used); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 333 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 337 | |
| 338 | /* Check 'bootdev hunt' command */ |
| 339 | static int bootdev_test_cmd_hunt(struct unit_test_state *uts) |
| 340 | { |
| 341 | struct bootstd_priv *std; |
| 342 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 343 | test_set_skip_delays(true); |
| 344 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 345 | /* get access to the used hunters */ |
| 346 | ut_assertok(bootstd_get_priv(&std)); |
| 347 | |
| 348 | console_record_reset_enable(); |
| 349 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 350 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 351 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 352 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 353 | ut_assert_skip_to_line("(total hunters: 9)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 354 | ut_assert_console_end(); |
| 355 | |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 356 | /* Use the MMC hunter and see that it updates */ |
| 357 | ut_assertok(run_command("bootdev hunt mmc", 0)); |
| 358 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 359 | ut_assert_skip_to_line(" 5 ide ide_bootdev"); |
| 360 | ut_assert_nextline(" 2 * mmc mmc_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 361 | ut_assert_skip_to_line("(total hunters: 9)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 362 | ut_assert_console_end(); |
| 363 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 364 | /* Scan all hunters */ |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 365 | test_set_eth_enable(false); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 366 | test_set_skip_delays(true); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 367 | ut_assertok(run_command("bootdev hunt", 0)); |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 368 | ut_assert_nextline("Hunting with: ethernet"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 369 | |
| 370 | /* This is the extension feature which has no uclass at present */ |
| 371 | ut_assert_nextline("Hunting with: simple_bus"); |
| 372 | ut_assert_nextline("Found 2 extension board(s)."); |
Simon Glass | be7c666 | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 373 | ut_assert_nextline("Hunting with: ide"); |
| 374 | ut_assert_nextline("Bus 0: not available "); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 375 | |
| 376 | /* mmc hunter has already been used so should not run again */ |
| 377 | |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 378 | ut_assert_nextline("Hunting with: nvme"); |
Simon Glass | 9985e9c | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 379 | ut_assert_nextline("Hunting with: scsi"); |
| 380 | ut_assert_nextline("scanning bus for devices..."); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 381 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 382 | ut_assert_nextline("Hunting with: usb"); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 383 | ut_assert_nextline( |
| 384 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 385 | ut_assert_nextline("Hunting with: virtio"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 386 | ut_assert_console_end(); |
| 387 | |
| 388 | /* List available hunters */ |
| 389 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 390 | ut_assert_nextlinen("Prio"); |
| 391 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 392 | ut_assert_nextline(" 6 * ethernet eth_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 393 | ut_assert_nextline(" 1 * simple_bus (none)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 394 | ut_assert_nextline(" 5 * ide ide_bootdev"); |
| 395 | ut_assert_nextline(" 2 * mmc mmc_bootdev"); |
| 396 | ut_assert_nextline(" 4 * nvme nvme_bootdev"); |
| 397 | ut_assert_nextline(" 4 * scsi scsi_bootdev"); |
| 398 | ut_assert_nextline(" 4 * spi_flash sf_bootdev"); |
| 399 | ut_assert_nextline(" 5 * usb usb_bootdev"); |
| 400 | ut_assert_nextline(" 4 * virtio virtio_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 401 | ut_assert_nextline("(total hunters: 9)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 402 | ut_assert_console_end(); |
| 403 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 404 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 405 | |
| 406 | return 0; |
| 407 | } |
| 408 | BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 409 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 410 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 411 | /* Check searching for bootdevs using the hunters */ |
| 412 | static int bootdev_test_hunt_scan(struct unit_test_state *uts) |
| 413 | { |
| 414 | struct bootflow_iter iter; |
| 415 | struct bootstd_priv *std; |
| 416 | struct bootflow bflow; |
| 417 | |
| 418 | /* get access to the used hunters */ |
| 419 | ut_assertok(bootstd_get_priv(&std)); |
| 420 | |
| 421 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 422 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, |
| 423 | BOOTFLOWF_SHOW | BOOTFLOWF_HUNT | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 424 | BOOTFLOWF_SKIP_GLOBAL, &bflow)); |
| 425 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | BOOTSTD_TEST(bootdev_test_hunt_scan, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 430 | |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 431 | /* Check that only bootable partitions are processed */ |
| 432 | static int bootdev_test_bootable(struct unit_test_state *uts) |
| 433 | { |
| 434 | struct bootflow_iter iter; |
| 435 | struct bootflow bflow; |
| 436 | struct udevice *blk; |
| 437 | |
| 438 | memset(&iter, '\0', sizeof(iter)); |
| 439 | memset(&bflow, '\0', sizeof(bflow)); |
| 440 | iter.part = 0; |
| 441 | ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk)); |
| 442 | iter.dev = blk; |
| 443 | ut_assertok(device_find_next_child(&iter.dev)); |
| 444 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 445 | |
| 446 | /* |
| 447 | * initially we don't have any knowledge of which partitions are |
| 448 | * bootable, but mmc1 has two partitions, with the first one being |
| 449 | * bootable |
| 450 | */ |
| 451 | iter.part = 2; |
| 452 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 453 | ut_asserteq(0, iter.first_bootable); |
| 454 | |
| 455 | /* scan with part == 0 to get the partition info */ |
| 456 | iter.part = 0; |
| 457 | ut_asserteq(-ENOENT, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 458 | ut_asserteq(1, iter.first_bootable); |
| 459 | |
| 460 | /* now it will refuse to use non-bootable partitions */ |
| 461 | iter.part = 2; |
| 462 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 467 | |
| 468 | /* Check hunting for bootdev of a particular priority */ |
| 469 | static int bootdev_test_hunt_prio(struct unit_test_state *uts) |
| 470 | { |
| 471 | test_set_skip_delays(true); |
| 472 | |
| 473 | console_record_reset_enable(); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 474 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false)); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 475 | ut_assert_nextline("scanning bus for devices..."); |
| 476 | ut_assert_skip_to_line(" Type: Hard Disk"); |
| 477 | ut_assert_nextlinen(" Capacity:"); |
| 478 | ut_assert_console_end(); |
| 479 | |
| 480 | /* now try a different priority, verbosely */ |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 481 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 482 | ut_assert_nextline("Hunting with: ide"); |
| 483 | ut_assert_nextline("Bus 0: not available "); |
| 484 | ut_assert_nextline("Hunting with: usb"); |
| 485 | ut_assert_nextline( |
| 486 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
| 487 | ut_assert_console_end(); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 492 | |
| 493 | /* Check hunting for bootdevs with a particular label */ |
| 494 | static int bootdev_test_hunt_label(struct unit_test_state *uts) |
| 495 | { |
| 496 | struct udevice *dev, *old; |
| 497 | struct bootstd_priv *std; |
| 498 | int mflags; |
| 499 | |
| 500 | /* get access to the used hunters */ |
| 501 | ut_assertok(bootstd_get_priv(&std)); |
| 502 | |
| 503 | /* scan an unknown uclass */ |
| 504 | console_record_reset_enable(); |
| 505 | old = (void *)&mflags; /* arbitrary pointer to check against dev */ |
| 506 | dev = old; |
| 507 | mflags = 123; |
| 508 | ut_asserteq(-EINVAL, |
| 509 | bootdev_hunt_and_find_by_label("fred", &dev, &mflags)); |
| 510 | ut_assert_nextline("Unknown uclass 'fred' in label"); |
| 511 | ut_asserteq_ptr(old, dev); |
| 512 | ut_asserteq(123, mflags); |
| 513 | ut_assert_console_end(); |
| 514 | ut_asserteq(0, std->hunters_used); |
| 515 | |
| 516 | /* scan an invalid mmc controllers */ |
| 517 | ut_asserteq(-ENOENT, |
| 518 | bootdev_hunt_and_find_by_label("mmc4", &dev, &mflags)); |
| 519 | ut_asserteq_ptr(old, dev); |
| 520 | ut_asserteq(123, mflags); |
| 521 | ut_assert_nextline("Unknown seq 4 for label 'mmc4'"); |
| 522 | ut_assert_console_end(); |
| 523 | |
| 524 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 525 | |
| 526 | /* scan for a particular mmc controller */ |
| 527 | ut_assertok(bootdev_hunt_and_find_by_label("mmc1", &dev, &mflags)); |
| 528 | ut_assertnonnull(dev); |
| 529 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 530 | ut_asserteq(0, mflags); |
| 531 | ut_assert_console_end(); |
| 532 | |
| 533 | /* scan all of usb */ |
| 534 | test_set_skip_delays(true); |
| 535 | ut_assertok(bootdev_hunt_and_find_by_label("usb", &dev, &mflags)); |
| 536 | ut_assertnonnull(dev); |
| 537 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); |
| 538 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 539 | ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); |
| 540 | ut_assert_console_end(); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | BOOTSTD_TEST(bootdev_test_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 545 | |
| 546 | /* Check iterating to the next label in a list */ |
| 547 | static int bootdev_test_next_label(struct unit_test_state *uts) |
| 548 | { |
| 549 | const char *const labels[] = {"mmc0", "scsi", "dhcp", "pxe", NULL}; |
| 550 | struct bootflow_iter iter; |
| 551 | struct bootstd_priv *std; |
| 552 | struct bootflow bflow; |
| 553 | struct udevice *dev; |
| 554 | int mflags; |
| 555 | |
| 556 | test_set_eth_enable(false); |
| 557 | |
| 558 | /* get access to the used hunters */ |
| 559 | ut_assertok(bootstd_get_priv(&std)); |
| 560 | |
| 561 | memset(&iter, '\0', sizeof(iter)); |
| 562 | memset(&bflow, '\0', sizeof(bflow)); |
| 563 | iter.part = 0; |
| 564 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 565 | iter.cur_label = -1; |
| 566 | iter.labels = labels; |
| 567 | |
| 568 | dev = NULL; |
| 569 | mflags = 123; |
| 570 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 571 | console_record_reset_enable(); |
| 572 | ut_assert_console_end(); |
| 573 | ut_assertnonnull(dev); |
| 574 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 575 | ut_asserteq(0, mflags); |
| 576 | |
| 577 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 578 | |
| 579 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 580 | ut_assert_nextline("scanning bus for devices..."); |
| 581 | ut_assert_skip_to_line( |
| 582 | " Capacity: 1.9 MB = 0.0 GB (4095 x 512)"); |
| 583 | ut_assert_console_end(); |
| 584 | ut_assertnonnull(dev); |
| 585 | ut_asserteq_str("scsi.id0lun0.bootdev", dev->name); |
| 586 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 587 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 588 | /* SCSI is sixth in the list, so bit 5 */ |
| 589 | ut_asserteq(BIT(MMC_HUNTER) | BIT(5), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 590 | |
| 591 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 592 | ut_assert_console_end(); |
| 593 | ut_assertnonnull(dev); |
| 594 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 595 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, |
| 596 | mflags); |
| 597 | |
| 598 | /* dhcp: Ethernet is first so bit 0 */ |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 599 | ut_asserteq(BIT(MMC_HUNTER) | BIT(5) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 600 | |
| 601 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 602 | ut_assert_console_end(); |
| 603 | ut_assertnonnull(dev); |
| 604 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 605 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 606 | mflags); |
| 607 | |
| 608 | /* pxe: Ethernet is first so bit 0 */ |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 609 | ut_asserteq(BIT(MMC_HUNTER) | BIT(5) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 610 | |
| 611 | mflags = 123; |
| 612 | ut_asserteq(-ENODEV, bootdev_next_label(&iter, &dev, &mflags)); |
| 613 | ut_asserteq(123, mflags); |
| 614 | ut_assert_console_end(); |
| 615 | |
| 616 | /* no change */ |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 617 | ut_asserteq(BIT(MMC_HUNTER) | BIT(5) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 622 | UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 623 | |
| 624 | |
| 625 | /* Check iterating to the next prioirty in a list */ |
| 626 | static int bootdev_test_next_prio(struct unit_test_state *uts) |
| 627 | { |
| 628 | struct bootflow_iter iter; |
| 629 | struct bootstd_priv *std; |
| 630 | struct bootflow bflow; |
| 631 | struct udevice *dev; |
| 632 | int ret; |
| 633 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 634 | test_set_eth_enable(false); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 635 | test_set_skip_delays(true); |
| 636 | |
| 637 | /* get access to the used hunters */ |
| 638 | ut_assertok(bootstd_get_priv(&std)); |
| 639 | |
| 640 | memset(&iter, '\0', sizeof(iter)); |
| 641 | memset(&bflow, '\0', sizeof(bflow)); |
| 642 | iter.part = 0; |
| 643 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 644 | iter.cur_prio = 0; |
| 645 | iter.flags = BOOTFLOWF_SHOW; |
| 646 | |
| 647 | dev = NULL; |
| 648 | console_record_reset_enable(); |
| 649 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 650 | ut_assertnonnull(dev); |
| 651 | ut_asserteq_str("mmc2.bootdev", dev->name); |
| 652 | |
| 653 | /* hunt flag not set, so this should not use any hunters */ |
| 654 | ut_asserteq(0, std->hunters_used); |
| 655 | ut_assert_console_end(); |
| 656 | |
| 657 | /* now try again with hunting enabled */ |
| 658 | iter.flags = BOOTFLOWF_SHOW | BOOTFLOWF_HUNT; |
| 659 | iter.cur_prio = 0; |
| 660 | iter.part = 0; |
| 661 | |
| 662 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 663 | ut_asserteq_str("mmc2.bootdev", dev->name); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 664 | ut_assert_nextline("Hunting with: simple_bus"); |
| 665 | ut_assert_nextline("Found 2 extension board(s)."); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 666 | ut_assert_nextline("Hunting with: mmc"); |
| 667 | ut_assert_console_end(); |
| 668 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 669 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 670 | |
| 671 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 672 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 673 | |
| 674 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 675 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 676 | ut_assert_console_end(); |
| 677 | |
| 678 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 679 | ut_asserteq_str("spi.bin@0.bootdev", dev->name); |
| 680 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 681 | |
| 682 | /* |
| 683 | * this scans all bootdevs of priority BOOTDEVP_4_SCAN_FAST before it |
| 684 | * starts looking at the devices, so we se virtio as well |
| 685 | */ |
| 686 | ut_assert_nextline("Hunting with: virtio"); |
| 687 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 688 | |
| 689 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 690 | ut_asserteq_str("spi.bin@1.bootdev", dev->name); |
| 691 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 692 | ut_assert_console_end(); |
| 693 | |
| 694 | /* keep going until there are no more bootdevs */ |
| 695 | do { |
| 696 | ret = bootdev_next_prio(&iter, &dev); |
| 697 | } while (!ret); |
| 698 | ut_asserteq(-ENODEV, ret); |
| 699 | ut_assertnull(dev); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 700 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 701 | |
| 702 | ut_assert_skip_to_line("Hunting with: ethernet"); |
| 703 | ut_assert_console_end(); |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 708 | UT_TESTF_SF_BOOTDEV); |