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