Simon Glass | fb1451b | 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 | 0c1413f | 2023-01-23 23:07:21 +0100 | [diff] [blame] | 21 | #if defined(CONFIG_USB_HOST) || defined(CONFIG_USB_GADGET) |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 22 | extern char usb_started; |
Linus Walleij | 0c1413f | 2023-01-23 23:07:21 +0100 | [diff] [blame] | 23 | #else |
| 24 | char usb_started; |
| 25 | #endif |
Simon Glass | fb1451b | 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 | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 109 | int mflags = 0; |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 110 | |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 111 | ut_assertok(bootdev_find_by_label("mmc2", &dev, &mflags)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 112 | ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev)); |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 113 | ut_asserteq(0, mflags); |
Simon Glass | fb1451b | 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 | d9f4857 | 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 | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 120 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 121 | mflags); |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 122 | ut_assertok(bootdev_find_by_label("dhcp", &dev, &mflags)); |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 123 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, |
| 124 | mflags); |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 125 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 126 | /* Check invalid uclass */ |
Simon Glass | 1736b4a | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 127 | ut_asserteq(-EPFNOSUPPORT, |
| 128 | bootdev_find_by_label("fred0", &dev, &mflags)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 129 | |
| 130 | /* Check unknown sequence number */ |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 131 | ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 132 | |
| 133 | return 0; |
| 134 | } |
Simon Glass | d9f4857 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 135 | BOOTSTD_TEST(bootdev_test_labels, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 136 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 137 | |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 138 | /* Check bootdev_find_by_any() */ |
| 139 | static int bootdev_test_any(struct unit_test_state *uts) |
| 140 | { |
| 141 | struct udevice *dev, *media; |
| 142 | int mflags; |
| 143 | |
| 144 | /* |
| 145 | * with ethernet enabled we have 8 devices ahead of the mmc ones: |
| 146 | * |
| 147 | * ut_assertok(run_command("bootdev list", 0)); |
| 148 | * Seq Probed Status Uclass Name |
| 149 | * --- ------ ------ -------- ------------------ |
| 150 | * 0 [ + ] OK ethernet eth@10002000.bootdev |
| 151 | * 1 [ ] OK ethernet eth@10003000.bootdev |
| 152 | * 2 [ ] OK ethernet sbe5.bootdev |
| 153 | * 3 [ ] OK ethernet eth@10004000.bootdev |
| 154 | * 4 [ ] OK ethernet phy-test-eth.bootdev |
| 155 | * 5 [ ] OK ethernet dsa-test-eth.bootdev |
| 156 | * 6 [ ] OK ethernet dsa-test@0.bootdev |
| 157 | * 7 [ ] OK ethernet dsa-test@1.bootdev |
| 158 | * 8 [ ] OK mmc mmc2.bootdev |
| 159 | * 9 [ + ] OK mmc mmc1.bootdev |
| 160 | * a [ ] OK mmc mmc0.bootdev |
| 161 | */ |
| 162 | console_record_reset_enable(); |
| 163 | ut_assertok(bootdev_find_by_any("8", &dev, &mflags)); |
| 164 | ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev)); |
| 165 | ut_asserteq(BOOTFLOW_METHF_SINGLE_DEV, mflags); |
| 166 | media = dev_get_parent(dev); |
| 167 | ut_asserteq(UCLASS_MMC, device_get_uclass_id(media)); |
| 168 | ut_asserteq_str("mmc2", media->name); |
| 169 | ut_assert_console_end(); |
| 170 | |
| 171 | /* there should not be this many bootdevs */ |
| 172 | ut_asserteq(-ENODEV, bootdev_find_by_any("50", &dev, &mflags)); |
| 173 | ut_assert_nextline("Cannot find '50' (err=-19)"); |
| 174 | ut_assert_console_end(); |
| 175 | |
| 176 | /* Check method flags */ |
| 177 | ut_assertok(bootdev_find_by_any("pxe", &dev, &mflags)); |
| 178 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 179 | mflags); |
| 180 | |
| 181 | /* Check invalid uclass */ |
| 182 | mflags = 123; |
Simon Glass | 1736b4a | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 183 | ut_asserteq(-EPFNOSUPPORT, bootdev_find_by_any("fred0", &dev, &mflags)); |
| 184 | ut_assert_nextline("Cannot find bootdev 'fred0' (err=-96)"); |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 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 | fb1451b | 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 | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 209 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 210 | ut_asserteq(2, iter.num_devs); |
Simon Glass | a950f28 | 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 | fb1451b | 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 | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 217 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 218 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 219 | ut_asserteq(2, iter.num_devs); |
Simon Glass | a950f28 | 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 | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 222 | bootflow_iter_uninit(&iter); |
| 223 | |
Simon Glass | a950f28 | 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 | fb1451b | 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 | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 241 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | a950f28 | 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 | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 245 | |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 246 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 247 | ut_asserteq(3, iter.num_devs); |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 248 | ut_asserteq_str("mmc0.bootdev", iter.dev_used[2]->name); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 249 | bootflow_iter_uninit(&iter); |
| 250 | |
| 251 | return 0; |
| 252 | } |
Simon Glass | a950f28 | 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 | fb1451b | 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 | 04fb2b6 | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 263 | test_set_skip_delays(true); |
| 264 | |
Simon Glass | a950f28 | 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 | fb1451b | 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 | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 276 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 277 | ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 278 | ut_asserteq(6, iter.num_devs); |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 279 | ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 280 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 281 | iter.dev_used[3]->name); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 282 | |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 283 | ut_assertok(bootdev_get_sibling_blk(iter.dev_used[3], &blk)); |
Simon Glass | fb1451b | 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 | a950f28 | 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 | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 289 | |
Simon Glass | a950f28 | 2023-01-17 10:48:17 -0700 | [diff] [blame] | 290 | /* try again but enable hunting, which brings in SCSI */ |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 291 | bootflow_iter_uninit(&iter); |
Simon Glass | 4f806f3 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 292 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT, |
Simon Glass | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 293 | &bflow)); |
Simon Glass | a950f28 | 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 | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 296 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
Simon Glass | a950f28 | 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 | fb1451b | 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 | bd90b09 | 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 | 04fb2b6 | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 309 | test_set_skip_delays(true); |
| 310 | |
Simon Glass | bd90b09 | 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 | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 318 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 319 | ut_assert_nextline(" 1 simple_bus (none)"); |
Simon Glass | eacc261 | 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 | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 323 | ut_assert_nextline(" 4 qfw qfw_bootdev"); |
Simon Glass | eacc261 | 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 | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 328 | ut_assert_nextline("(total hunters: 10)"); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 329 | ut_assert_console_end(); |
| 330 | |
Simon Glass | 04fb2b6 | 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 | c7b63d5 | 2023-01-17 10:47:34 -0700 | [diff] [blame] | 334 | ut_assert_console_end(); |
| 335 | |
Simon Glass | 662cfa0 | 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 | 04fb2b6 | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 338 | |
Simon Glass | bd90b09 | 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 | 04fb2b6 | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 348 | test_set_skip_delays(true); |
| 349 | |
Simon Glass | bd90b09 | 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 | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 357 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 358 | ut_assert_skip_to_line("(total hunters: 10)"); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 359 | ut_assert_console_end(); |
| 360 | |
| 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 | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 366 | ut_assert_skip_to_line("(total hunters: 10)"); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 367 | ut_assert_console_end(); |
| 368 | |
| 369 | /* Scan all hunters */ |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 370 | test_set_eth_enable(false); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 371 | test_set_skip_delays(true); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 372 | ut_assertok(run_command("bootdev hunt", 0)); |
Simon Glass | 4146c82 | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 373 | ut_assert_nextline("Hunting with: ethernet"); |
Simon Glass | 18552d2 | 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 | 0d77f8f | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 378 | ut_assert_nextline("Hunting with: ide"); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 379 | |
| 380 | /* mmc hunter has already been used so should not run again */ |
| 381 | |
Simon Glass | 758c706 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 382 | ut_assert_nextline("Hunting with: nvme"); |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 383 | ut_assert_nextline("Hunting with: qfw"); |
Simon Glass | 8f090b6 | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 384 | ut_assert_nextline("Hunting with: scsi"); |
| 385 | ut_assert_nextline("scanning bus for devices..."); |
Simon Glass | 0c1f4a9 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 386 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 387 | ut_assert_nextline("Hunting with: usb"); |
Simon Glass | 04fb2b6 | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 388 | ut_assert_nextline( |
| 389 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
Simon Glass | 0c1f4a9 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 390 | ut_assert_nextline("Hunting with: virtio"); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 391 | ut_assert_console_end(); |
| 392 | |
| 393 | /* List available hunters */ |
| 394 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 395 | ut_assert_nextlinen("Prio"); |
| 396 | ut_assert_nextlinen("----"); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 397 | ut_assert_nextline(" 6 * ethernet eth_bootdev"); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 398 | ut_assert_nextline(" 1 * simple_bus (none)"); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 399 | ut_assert_nextline(" 5 * ide ide_bootdev"); |
| 400 | ut_assert_nextline(" 2 * mmc mmc_bootdev"); |
| 401 | ut_assert_nextline(" 4 * nvme nvme_bootdev"); |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 402 | ut_assert_nextline(" 4 * qfw qfw_bootdev"); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 403 | ut_assert_nextline(" 4 * scsi scsi_bootdev"); |
| 404 | ut_assert_nextline(" 4 * spi_flash sf_bootdev"); |
| 405 | ut_assert_nextline(" 5 * usb usb_bootdev"); |
| 406 | ut_assert_nextline(" 4 * virtio virtio_bootdev"); |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 407 | ut_assert_nextline("(total hunters: 10)"); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 408 | ut_assert_console_end(); |
| 409 | |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 410 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | bd90b09 | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 411 | |
| 412 | return 0; |
| 413 | } |
| 414 | BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 415 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | f0e358f | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 416 | |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 417 | /* Check searching for bootdevs using the hunters */ |
| 418 | static int bootdev_test_hunt_scan(struct unit_test_state *uts) |
| 419 | { |
| 420 | struct bootflow_iter iter; |
| 421 | struct bootstd_priv *std; |
| 422 | struct bootflow bflow; |
| 423 | |
| 424 | /* get access to the used hunters */ |
| 425 | ut_assertok(bootstd_get_priv(&std)); |
| 426 | |
| 427 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
Simon Glass | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 428 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, |
Simon Glass | 4f806f3 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 429 | BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT | |
| 430 | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 431 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | BOOTSTD_TEST(bootdev_test_hunt_scan, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 436 | |
Simon Glass | f0e358f | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 437 | /* Check that only bootable partitions are processed */ |
| 438 | static int bootdev_test_bootable(struct unit_test_state *uts) |
| 439 | { |
| 440 | struct bootflow_iter iter; |
| 441 | struct bootflow bflow; |
| 442 | struct udevice *blk; |
| 443 | |
| 444 | memset(&iter, '\0', sizeof(iter)); |
| 445 | memset(&bflow, '\0', sizeof(bflow)); |
| 446 | iter.part = 0; |
| 447 | ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk)); |
| 448 | iter.dev = blk; |
| 449 | ut_assertok(device_find_next_child(&iter.dev)); |
| 450 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 451 | |
| 452 | /* |
| 453 | * initially we don't have any knowledge of which partitions are |
| 454 | * bootable, but mmc1 has two partitions, with the first one being |
| 455 | * bootable |
| 456 | */ |
| 457 | iter.part = 2; |
| 458 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 459 | ut_asserteq(0, iter.first_bootable); |
| 460 | |
| 461 | /* scan with part == 0 to get the partition info */ |
| 462 | iter.part = 0; |
| 463 | ut_asserteq(-ENOENT, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 464 | ut_asserteq(1, iter.first_bootable); |
| 465 | |
| 466 | /* now it will refuse to use non-bootable partitions */ |
| 467 | iter.part = 2; |
| 468 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 79a7d4a | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 473 | |
| 474 | /* Check hunting for bootdev of a particular priority */ |
| 475 | static int bootdev_test_hunt_prio(struct unit_test_state *uts) |
| 476 | { |
| 477 | test_set_skip_delays(true); |
| 478 | |
| 479 | console_record_reset_enable(); |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 480 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false)); |
Simon Glass | 79a7d4a | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 481 | ut_assert_nextline("scanning bus for devices..."); |
| 482 | ut_assert_skip_to_line(" Type: Hard Disk"); |
| 483 | ut_assert_nextlinen(" Capacity:"); |
| 484 | ut_assert_console_end(); |
| 485 | |
| 486 | /* now try a different priority, verbosely */ |
Simon Glass | eacc261 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 487 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); |
Simon Glass | 79a7d4a | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 488 | ut_assert_nextline("Hunting with: ide"); |
Simon Glass | 79a7d4a | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 489 | ut_assert_nextline("Hunting with: usb"); |
| 490 | ut_assert_nextline( |
| 491 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
| 492 | ut_assert_console_end(); |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 497 | |
| 498 | /* Check hunting for bootdevs with a particular label */ |
| 499 | static int bootdev_test_hunt_label(struct unit_test_state *uts) |
| 500 | { |
| 501 | struct udevice *dev, *old; |
| 502 | struct bootstd_priv *std; |
| 503 | int mflags; |
| 504 | |
| 505 | /* get access to the used hunters */ |
| 506 | ut_assertok(bootstd_get_priv(&std)); |
| 507 | |
| 508 | /* scan an unknown uclass */ |
| 509 | console_record_reset_enable(); |
| 510 | old = (void *)&mflags; /* arbitrary pointer to check against dev */ |
| 511 | dev = old; |
| 512 | mflags = 123; |
Simon Glass | 1736b4a | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 513 | ut_asserteq(-EPFNOSUPPORT, |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 514 | bootdev_hunt_and_find_by_label("fred", &dev, &mflags)); |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 515 | ut_asserteq_ptr(old, dev); |
| 516 | ut_asserteq(123, mflags); |
| 517 | ut_assert_console_end(); |
| 518 | ut_asserteq(0, std->hunters_used); |
| 519 | |
| 520 | /* scan an invalid mmc controllers */ |
| 521 | ut_asserteq(-ENOENT, |
| 522 | bootdev_hunt_and_find_by_label("mmc4", &dev, &mflags)); |
| 523 | ut_asserteq_ptr(old, dev); |
| 524 | ut_asserteq(123, mflags); |
Simon Glass | 66e3dce | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 525 | ut_assert_console_end(); |
| 526 | |
| 527 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 528 | |
| 529 | /* scan for a particular mmc controller */ |
| 530 | ut_assertok(bootdev_hunt_and_find_by_label("mmc1", &dev, &mflags)); |
| 531 | ut_assertnonnull(dev); |
| 532 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 533 | ut_asserteq(0, mflags); |
| 534 | ut_assert_console_end(); |
| 535 | |
| 536 | /* scan all of usb */ |
| 537 | test_set_skip_delays(true); |
| 538 | ut_assertok(bootdev_hunt_and_find_by_label("usb", &dev, &mflags)); |
| 539 | ut_assertnonnull(dev); |
| 540 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); |
| 541 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 542 | ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); |
| 543 | ut_assert_console_end(); |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | BOOTSTD_TEST(bootdev_test_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 548 | |
| 549 | /* Check iterating to the next label in a list */ |
| 550 | static int bootdev_test_next_label(struct unit_test_state *uts) |
| 551 | { |
| 552 | const char *const labels[] = {"mmc0", "scsi", "dhcp", "pxe", NULL}; |
| 553 | struct bootflow_iter iter; |
| 554 | struct bootstd_priv *std; |
| 555 | struct bootflow bflow; |
| 556 | struct udevice *dev; |
| 557 | int mflags; |
| 558 | |
| 559 | test_set_eth_enable(false); |
| 560 | |
| 561 | /* get access to the used hunters */ |
| 562 | ut_assertok(bootstd_get_priv(&std)); |
| 563 | |
| 564 | memset(&iter, '\0', sizeof(iter)); |
| 565 | memset(&bflow, '\0', sizeof(bflow)); |
| 566 | iter.part = 0; |
| 567 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 568 | iter.cur_label = -1; |
| 569 | iter.labels = labels; |
| 570 | |
| 571 | dev = NULL; |
| 572 | mflags = 123; |
| 573 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 574 | console_record_reset_enable(); |
| 575 | ut_assert_console_end(); |
| 576 | ut_assertnonnull(dev); |
| 577 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 578 | ut_asserteq(0, mflags); |
| 579 | |
| 580 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 581 | |
| 582 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 583 | ut_assert_nextline("scanning bus for devices..."); |
| 584 | ut_assert_skip_to_line( |
| 585 | " Capacity: 1.9 MB = 0.0 GB (4095 x 512)"); |
| 586 | ut_assert_console_end(); |
| 587 | ut_assertnonnull(dev); |
| 588 | ut_asserteq_str("scsi.id0lun0.bootdev", dev->name); |
| 589 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 590 | |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 591 | /* SCSI is 7th in the list, so bit 6 */ |
| 592 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6), std->hunters_used); |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 593 | |
| 594 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 595 | ut_assert_console_end(); |
| 596 | ut_assertnonnull(dev); |
| 597 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 598 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, |
| 599 | mflags); |
| 600 | |
| 601 | /* dhcp: Ethernet is first so bit 0 */ |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 602 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 603 | |
| 604 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 605 | ut_assert_console_end(); |
| 606 | ut_assertnonnull(dev); |
| 607 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 608 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 609 | mflags); |
| 610 | |
| 611 | /* pxe: Ethernet is first so bit 0 */ |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 612 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 613 | |
| 614 | mflags = 123; |
| 615 | ut_asserteq(-ENODEV, bootdev_next_label(&iter, &dev, &mflags)); |
| 616 | ut_asserteq(123, mflags); |
| 617 | ut_assert_console_end(); |
| 618 | |
| 619 | /* no change */ |
Simon Glass | 662cfa0 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 620 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | e4b6948 | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 625 | UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV); |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 626 | |
| 627 | |
| 628 | /* Check iterating to the next prioirty in a list */ |
| 629 | static int bootdev_test_next_prio(struct unit_test_state *uts) |
| 630 | { |
| 631 | struct bootflow_iter iter; |
| 632 | struct bootstd_priv *std; |
| 633 | struct bootflow bflow; |
| 634 | struct udevice *dev; |
| 635 | int ret; |
| 636 | |
Simon Glass | 91943ff | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 637 | test_set_eth_enable(false); |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 638 | test_set_skip_delays(true); |
| 639 | |
| 640 | /* get access to the used hunters */ |
| 641 | ut_assertok(bootstd_get_priv(&std)); |
| 642 | |
| 643 | memset(&iter, '\0', sizeof(iter)); |
| 644 | memset(&bflow, '\0', sizeof(bflow)); |
| 645 | iter.part = 0; |
| 646 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 647 | iter.cur_prio = 0; |
Simon Glass | 4f806f3 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 648 | iter.flags = BOOTFLOWIF_SHOW; |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 649 | |
| 650 | dev = NULL; |
| 651 | console_record_reset_enable(); |
| 652 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 653 | ut_assertnonnull(dev); |
| 654 | ut_asserteq_str("mmc2.bootdev", dev->name); |
| 655 | |
| 656 | /* hunt flag not set, so this should not use any hunters */ |
| 657 | ut_asserteq(0, std->hunters_used); |
| 658 | ut_assert_console_end(); |
| 659 | |
| 660 | /* now try again with hunting enabled */ |
Simon Glass | 4f806f3 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 661 | iter.flags = BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT; |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 662 | iter.cur_prio = 0; |
| 663 | iter.part = 0; |
| 664 | |
| 665 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 666 | ut_asserteq_str("mmc2.bootdev", dev->name); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 667 | ut_assert_nextline("Hunting with: simple_bus"); |
| 668 | ut_assert_nextline("Found 2 extension board(s)."); |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 669 | ut_assert_nextline("Hunting with: mmc"); |
| 670 | ut_assert_console_end(); |
| 671 | |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 672 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 673 | |
| 674 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 675 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 676 | |
| 677 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 678 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 679 | ut_assert_console_end(); |
| 680 | |
| 681 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 682 | ut_asserteq_str("spi.bin@0.bootdev", dev->name); |
| 683 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 684 | |
| 685 | /* |
| 686 | * this scans all bootdevs of priority BOOTDEVP_4_SCAN_FAST before it |
| 687 | * starts looking at the devices, so we se virtio as well |
| 688 | */ |
| 689 | ut_assert_nextline("Hunting with: virtio"); |
| 690 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 691 | |
| 692 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 693 | ut_asserteq_str("spi.bin@1.bootdev", dev->name); |
| 694 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 695 | ut_assert_console_end(); |
| 696 | |
| 697 | /* keep going until there are no more bootdevs */ |
| 698 | do { |
| 699 | ret = bootdev_next_prio(&iter, &dev); |
| 700 | } while (!ret); |
| 701 | ut_asserteq(-ENODEV, ret); |
| 702 | ut_assertnull(dev); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 703 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | 43e89a3 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 704 | |
| 705 | ut_assert_skip_to_line("Hunting with: ethernet"); |
| 706 | ut_assert_console_end(); |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 711 | UT_TESTF_SF_BOOTDEV); |