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 | 2510aab | 2023-05-05 20:03:03 -0600 | [diff] [blame] | 22 | extern bool usb_started; |
Linus Walleij | e3045d1 | 2023-01-23 23:07:21 +0100 | [diff] [blame] | 23 | #else |
Simon Glass | 2510aab | 2023-05-05 20:03:03 -0600 | [diff] [blame] | 24 | #include <usb.h> |
Linus Walleij | e3045d1 | 2023-01-23 23:07:21 +0100 | [diff] [blame] | 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 | 4108c6b | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 127 | ut_asserteq(-EPFNOSUPPORT, |
| 128 | bootdev_find_by_label("fred0", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 129 | |
| 130 | /* Check unknown sequence number */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 131 | ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 132 | |
| 133 | return 0; |
| 134 | } |
Simon Glass | e22fe92 | 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 | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 137 | |
Simon Glass | de567b1 | 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 | 4108c6b | 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 | de567b1 | 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 | 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 | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 292 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT, |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 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 | 4bb7c16 | 2023-05-05 20:03:04 -0600 | [diff] [blame^] | 309 | usb_started = false; |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 310 | test_set_skip_delays(true); |
| 311 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 312 | /* get access to the used hunters */ |
| 313 | ut_assertok(bootstd_get_priv(&std)); |
| 314 | |
| 315 | console_record_reset_enable(); |
| 316 | bootdev_list_hunters(std); |
| 317 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 318 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 319 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 320 | ut_assert_nextline(" 1 simple_bus (none)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 321 | ut_assert_nextline(" 5 ide ide_bootdev"); |
| 322 | ut_assert_nextline(" 2 mmc mmc_bootdev"); |
| 323 | ut_assert_nextline(" 4 nvme nvme_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 324 | ut_assert_nextline(" 4 qfw qfw_bootdev"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 325 | ut_assert_nextline(" 4 scsi scsi_bootdev"); |
| 326 | ut_assert_nextline(" 4 spi_flash sf_bootdev"); |
| 327 | ut_assert_nextline(" 5 usb usb_bootdev"); |
| 328 | ut_assert_nextline(" 4 virtio virtio_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 329 | ut_assert_nextline("(total hunters: 10)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 330 | ut_assert_console_end(); |
| 331 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 332 | ut_assertok(bootdev_hunt("usb1", false)); |
| 333 | ut_assert_nextline( |
| 334 | "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] | 335 | ut_assert_console_end(); |
| 336 | |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 337 | /* USB is 7th in the list, so bit 8 */ |
| 338 | ut_asserteq(BIT(8), std->hunters_used); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 339 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 343 | |
| 344 | /* Check 'bootdev hunt' command */ |
| 345 | static int bootdev_test_cmd_hunt(struct unit_test_state *uts) |
| 346 | { |
| 347 | struct bootstd_priv *std; |
| 348 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 349 | test_set_skip_delays(true); |
Simon Glass | 4bb7c16 | 2023-05-05 20:03:04 -0600 | [diff] [blame^] | 350 | usb_started = false; |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 351 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 352 | /* get access to the used hunters */ |
| 353 | ut_assertok(bootstd_get_priv(&std)); |
| 354 | |
| 355 | console_record_reset_enable(); |
| 356 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 357 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 358 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 359 | ut_assert_nextline(" 6 ethernet eth_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 360 | ut_assert_skip_to_line("(total hunters: 10)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 361 | ut_assert_console_end(); |
| 362 | |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 363 | /* Use the MMC hunter and see that it updates */ |
| 364 | ut_assertok(run_command("bootdev hunt mmc", 0)); |
| 365 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 366 | ut_assert_skip_to_line(" 5 ide ide_bootdev"); |
| 367 | ut_assert_nextline(" 2 * mmc mmc_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 368 | ut_assert_skip_to_line("(total hunters: 10)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 369 | ut_assert_console_end(); |
| 370 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 371 | /* Scan all hunters */ |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 372 | test_set_eth_enable(false); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 373 | test_set_skip_delays(true); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 374 | ut_assertok(run_command("bootdev hunt", 0)); |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 375 | ut_assert_nextline("Hunting with: ethernet"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 376 | |
| 377 | /* This is the extension feature which has no uclass at present */ |
| 378 | ut_assert_nextline("Hunting with: simple_bus"); |
| 379 | ut_assert_nextline("Found 2 extension board(s)."); |
Simon Glass | be7c666 | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 380 | ut_assert_nextline("Hunting with: ide"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 381 | |
| 382 | /* mmc hunter has already been used so should not run again */ |
| 383 | |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 384 | ut_assert_nextline("Hunting with: nvme"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 385 | ut_assert_nextline("Hunting with: qfw"); |
Simon Glass | 9985e9c | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 386 | ut_assert_nextline("Hunting with: scsi"); |
| 387 | ut_assert_nextline("scanning bus for devices..."); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 388 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 389 | ut_assert_nextline("Hunting with: usb"); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 390 | ut_assert_nextline( |
| 391 | "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] | 392 | ut_assert_nextline("Hunting with: virtio"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 393 | ut_assert_console_end(); |
| 394 | |
| 395 | /* List available hunters */ |
| 396 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 397 | ut_assert_nextlinen("Prio"); |
| 398 | ut_assert_nextlinen("----"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 399 | ut_assert_nextline(" 6 * ethernet eth_bootdev"); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 400 | ut_assert_nextline(" 1 * simple_bus (none)"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 401 | ut_assert_nextline(" 5 * ide ide_bootdev"); |
| 402 | ut_assert_nextline(" 2 * mmc mmc_bootdev"); |
| 403 | ut_assert_nextline(" 4 * nvme nvme_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 404 | ut_assert_nextline(" 4 * qfw qfw_bootdev"); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 405 | ut_assert_nextline(" 4 * scsi scsi_bootdev"); |
| 406 | ut_assert_nextline(" 4 * spi_flash sf_bootdev"); |
| 407 | ut_assert_nextline(" 5 * usb usb_bootdev"); |
| 408 | ut_assert_nextline(" 4 * virtio virtio_bootdev"); |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 409 | ut_assert_nextline("(total hunters: 10)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 410 | ut_assert_console_end(); |
| 411 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 412 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 413 | |
| 414 | return 0; |
| 415 | } |
| 416 | BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 417 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 418 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 419 | /* Check searching for bootdevs using the hunters */ |
| 420 | static int bootdev_test_hunt_scan(struct unit_test_state *uts) |
| 421 | { |
| 422 | struct bootflow_iter iter; |
| 423 | struct bootstd_priv *std; |
| 424 | struct bootflow bflow; |
| 425 | |
| 426 | /* get access to the used hunters */ |
| 427 | ut_assertok(bootstd_get_priv(&std)); |
| 428 | |
| 429 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 430 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 431 | BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT | |
| 432 | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 433 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | BOOTSTD_TEST(bootdev_test_hunt_scan, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 438 | |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 439 | /* Check that only bootable partitions are processed */ |
| 440 | static int bootdev_test_bootable(struct unit_test_state *uts) |
| 441 | { |
| 442 | struct bootflow_iter iter; |
| 443 | struct bootflow bflow; |
| 444 | struct udevice *blk; |
| 445 | |
| 446 | memset(&iter, '\0', sizeof(iter)); |
| 447 | memset(&bflow, '\0', sizeof(bflow)); |
| 448 | iter.part = 0; |
| 449 | ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk)); |
| 450 | iter.dev = blk; |
| 451 | ut_assertok(device_find_next_child(&iter.dev)); |
| 452 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 453 | |
| 454 | /* |
| 455 | * initially we don't have any knowledge of which partitions are |
| 456 | * bootable, but mmc1 has two partitions, with the first one being |
| 457 | * bootable |
| 458 | */ |
| 459 | iter.part = 2; |
| 460 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 461 | ut_asserteq(0, iter.first_bootable); |
| 462 | |
| 463 | /* scan with part == 0 to get the partition info */ |
| 464 | iter.part = 0; |
| 465 | ut_asserteq(-ENOENT, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 466 | ut_asserteq(1, iter.first_bootable); |
| 467 | |
| 468 | /* now it will refuse to use non-bootable partitions */ |
| 469 | iter.part = 2; |
| 470 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 475 | |
| 476 | /* Check hunting for bootdev of a particular priority */ |
| 477 | static int bootdev_test_hunt_prio(struct unit_test_state *uts) |
| 478 | { |
Simon Glass | 4bb7c16 | 2023-05-05 20:03:04 -0600 | [diff] [blame^] | 479 | usb_started = false; |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 480 | test_set_skip_delays(true); |
| 481 | |
| 482 | console_record_reset_enable(); |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 483 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_4_SCAN_FAST, false)); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 484 | ut_assert_nextline("scanning bus for devices..."); |
| 485 | ut_assert_skip_to_line(" Type: Hard Disk"); |
| 486 | ut_assert_nextlinen(" Capacity:"); |
| 487 | ut_assert_console_end(); |
| 488 | |
| 489 | /* now try a different priority, verbosely */ |
Simon Glass | 7e1f6a4 | 2023-01-17 10:48:08 -0700 | [diff] [blame] | 490 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_5_SCAN_SLOW, true)); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 491 | ut_assert_nextline("Hunting with: ide"); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame] | 492 | ut_assert_nextline("Hunting with: usb"); |
| 493 | ut_assert_nextline( |
| 494 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
| 495 | ut_assert_console_end(); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | 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] | 500 | |
| 501 | /* Check hunting for bootdevs with a particular label */ |
| 502 | static int bootdev_test_hunt_label(struct unit_test_state *uts) |
| 503 | { |
| 504 | struct udevice *dev, *old; |
| 505 | struct bootstd_priv *std; |
| 506 | int mflags; |
| 507 | |
Simon Glass | 4bb7c16 | 2023-05-05 20:03:04 -0600 | [diff] [blame^] | 508 | usb_started = false; |
| 509 | |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 510 | /* get access to the used hunters */ |
| 511 | ut_assertok(bootstd_get_priv(&std)); |
| 512 | |
| 513 | /* scan an unknown uclass */ |
| 514 | console_record_reset_enable(); |
| 515 | old = (void *)&mflags; /* arbitrary pointer to check against dev */ |
| 516 | dev = old; |
| 517 | mflags = 123; |
Simon Glass | 4108c6b | 2023-04-24 13:49:47 +1200 | [diff] [blame] | 518 | ut_asserteq(-EPFNOSUPPORT, |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 519 | bootdev_hunt_and_find_by_label("fred", &dev, &mflags)); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 520 | ut_asserteq_ptr(old, dev); |
| 521 | ut_asserteq(123, mflags); |
| 522 | ut_assert_console_end(); |
| 523 | ut_asserteq(0, std->hunters_used); |
| 524 | |
| 525 | /* scan an invalid mmc controllers */ |
| 526 | ut_asserteq(-ENOENT, |
| 527 | bootdev_hunt_and_find_by_label("mmc4", &dev, &mflags)); |
| 528 | ut_asserteq_ptr(old, dev); |
| 529 | ut_asserteq(123, mflags); |
Simon Glass | de567b1 | 2023-01-17 10:48:09 -0700 | [diff] [blame] | 530 | ut_assert_console_end(); |
| 531 | |
| 532 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 533 | |
| 534 | /* scan for a particular mmc controller */ |
| 535 | ut_assertok(bootdev_hunt_and_find_by_label("mmc1", &dev, &mflags)); |
| 536 | ut_assertnonnull(dev); |
| 537 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 538 | ut_asserteq(0, mflags); |
| 539 | ut_assert_console_end(); |
| 540 | |
| 541 | /* scan all of usb */ |
| 542 | test_set_skip_delays(true); |
| 543 | ut_assertok(bootdev_hunt_and_find_by_label("usb", &dev, &mflags)); |
| 544 | ut_assertnonnull(dev); |
| 545 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", dev->name); |
| 546 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 547 | ut_assert_nextlinen("Bus usb@1: scanning bus usb@1"); |
| 548 | ut_assert_console_end(); |
| 549 | |
| 550 | return 0; |
| 551 | } |
| 552 | 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] | 553 | |
| 554 | /* Check iterating to the next label in a list */ |
| 555 | static int bootdev_test_next_label(struct unit_test_state *uts) |
| 556 | { |
| 557 | const char *const labels[] = {"mmc0", "scsi", "dhcp", "pxe", NULL}; |
| 558 | struct bootflow_iter iter; |
| 559 | struct bootstd_priv *std; |
| 560 | struct bootflow bflow; |
| 561 | struct udevice *dev; |
| 562 | int mflags; |
| 563 | |
| 564 | test_set_eth_enable(false); |
| 565 | |
| 566 | /* get access to the used hunters */ |
| 567 | ut_assertok(bootstd_get_priv(&std)); |
| 568 | |
| 569 | memset(&iter, '\0', sizeof(iter)); |
| 570 | memset(&bflow, '\0', sizeof(bflow)); |
| 571 | iter.part = 0; |
| 572 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 573 | iter.cur_label = -1; |
| 574 | iter.labels = labels; |
| 575 | |
| 576 | dev = NULL; |
| 577 | mflags = 123; |
| 578 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 579 | console_record_reset_enable(); |
| 580 | ut_assert_console_end(); |
| 581 | ut_assertnonnull(dev); |
| 582 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 583 | ut_asserteq(0, mflags); |
| 584 | |
| 585 | ut_assertok(bootstd_test_check_mmc_hunter(uts)); |
| 586 | |
| 587 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 588 | ut_assert_nextline("scanning bus for devices..."); |
| 589 | ut_assert_skip_to_line( |
| 590 | " Capacity: 1.9 MB = 0.0 GB (4095 x 512)"); |
| 591 | ut_assert_console_end(); |
| 592 | ut_assertnonnull(dev); |
| 593 | ut_asserteq_str("scsi.id0lun0.bootdev", dev->name); |
| 594 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS, mflags); |
| 595 | |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 596 | /* SCSI is 7th in the list, so bit 6 */ |
| 597 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 598 | |
| 599 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 600 | ut_assert_console_end(); |
| 601 | ut_assertnonnull(dev); |
| 602 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 603 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_DHCP_ONLY, |
| 604 | mflags); |
| 605 | |
| 606 | /* dhcp: Ethernet is first so bit 0 */ |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 607 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 608 | |
| 609 | ut_assertok(bootdev_next_label(&iter, &dev, &mflags)); |
| 610 | ut_assert_console_end(); |
| 611 | ut_assertnonnull(dev); |
| 612 | ut_asserteq_str("eth@10002000.bootdev", dev->name); |
| 613 | ut_asserteq(BOOTFLOW_METHF_SINGLE_UCLASS | BOOTFLOW_METHF_PXE_ONLY, |
| 614 | mflags); |
| 615 | |
| 616 | /* pxe: Ethernet is first so bit 0 */ |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 617 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 618 | |
| 619 | mflags = 123; |
| 620 | ut_asserteq(-ENODEV, bootdev_next_label(&iter, &dev, &mflags)); |
| 621 | ut_asserteq(123, mflags); |
| 622 | ut_assert_console_end(); |
| 623 | |
| 624 | /* no change */ |
Simon Glass | deffa69 | 2023-01-28 15:00:28 -0700 | [diff] [blame] | 625 | ut_asserteq(BIT(MMC_HUNTER) | BIT(6) | BIT(0), std->hunters_used); |
Simon Glass | ac06b26a | 2023-01-17 10:48:10 -0700 | [diff] [blame] | 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | BOOTSTD_TEST(bootdev_test_next_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 630 | UT_TESTF_ETH_BOOTDEV | UT_TESTF_SF_BOOTDEV); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 631 | |
| 632 | |
| 633 | /* Check iterating to the next prioirty in a list */ |
| 634 | static int bootdev_test_next_prio(struct unit_test_state *uts) |
| 635 | { |
| 636 | struct bootflow_iter iter; |
| 637 | struct bootstd_priv *std; |
| 638 | struct bootflow bflow; |
| 639 | struct udevice *dev; |
| 640 | int ret; |
| 641 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 642 | test_set_eth_enable(false); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 643 | test_set_skip_delays(true); |
| 644 | |
| 645 | /* get access to the used hunters */ |
| 646 | ut_assertok(bootstd_get_priv(&std)); |
| 647 | |
| 648 | memset(&iter, '\0', sizeof(iter)); |
| 649 | memset(&bflow, '\0', sizeof(bflow)); |
| 650 | iter.part = 0; |
| 651 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 652 | iter.cur_prio = 0; |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 653 | iter.flags = BOOTFLOWIF_SHOW; |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 654 | |
| 655 | dev = NULL; |
| 656 | console_record_reset_enable(); |
| 657 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 658 | ut_assertnonnull(dev); |
| 659 | ut_asserteq_str("mmc2.bootdev", dev->name); |
| 660 | |
| 661 | /* hunt flag not set, so this should not use any hunters */ |
| 662 | ut_asserteq(0, std->hunters_used); |
| 663 | ut_assert_console_end(); |
| 664 | |
| 665 | /* now try again with hunting enabled */ |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 666 | iter.flags = BOOTFLOWIF_SHOW | BOOTFLOWIF_HUNT; |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 667 | iter.cur_prio = 0; |
| 668 | iter.part = 0; |
| 669 | |
| 670 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 671 | ut_asserteq_str("mmc2.bootdev", dev->name); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 672 | ut_assert_nextline("Hunting with: simple_bus"); |
| 673 | ut_assert_nextline("Found 2 extension board(s)."); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 674 | ut_assert_nextline("Hunting with: mmc"); |
| 675 | ut_assert_console_end(); |
| 676 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 677 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 678 | |
| 679 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 680 | ut_asserteq_str("mmc1.bootdev", dev->name); |
| 681 | |
| 682 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 683 | ut_asserteq_str("mmc0.bootdev", dev->name); |
| 684 | ut_assert_console_end(); |
| 685 | |
| 686 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 687 | ut_asserteq_str("spi.bin@0.bootdev", dev->name); |
| 688 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 689 | |
| 690 | /* |
| 691 | * this scans all bootdevs of priority BOOTDEVP_4_SCAN_FAST before it |
| 692 | * starts looking at the devices, so we se virtio as well |
| 693 | */ |
| 694 | ut_assert_nextline("Hunting with: virtio"); |
| 695 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 696 | |
| 697 | ut_assertok(bootdev_next_prio(&iter, &dev)); |
| 698 | ut_asserteq_str("spi.bin@1.bootdev", dev->name); |
| 699 | ut_assert_nextlinen("SF: Detected m25p16"); |
| 700 | ut_assert_console_end(); |
| 701 | |
| 702 | /* keep going until there are no more bootdevs */ |
| 703 | do { |
| 704 | ret = bootdev_next_prio(&iter, &dev); |
| 705 | } while (!ret); |
| 706 | ut_asserteq(-ENODEV, ret); |
| 707 | ut_assertnull(dev); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 708 | ut_asserteq(GENMASK(MAX_HUNTER, 0), std->hunters_used); |
Simon Glass | 660a995 | 2023-01-17 10:48:11 -0700 | [diff] [blame] | 709 | |
| 710 | ut_assert_skip_to_line("Hunting with: ethernet"); |
| 711 | ut_assert_console_end(); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | BOOTSTD_TEST(bootdev_test_next_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 716 | UT_TESTF_SF_BOOTDEV); |