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