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