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