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 */ |
| 21 | extern char usb_started; |
| 22 | |
| 23 | /* Check 'bootdev list' command */ |
| 24 | static int bootdev_test_cmd_list(struct unit_test_state *uts) |
| 25 | { |
| 26 | int probed; |
| 27 | |
| 28 | console_record_reset_enable(); |
| 29 | for (probed = 0; probed < 2; probed++) { |
| 30 | int probe_ch = probed ? '+' : ' '; |
| 31 | |
| 32 | ut_assertok(run_command(probed ? "bootdev list -p" : |
| 33 | "bootdev list", 0)); |
| 34 | ut_assert_nextline("Seq Probed Status Uclass Name"); |
| 35 | ut_assert_nextlinen("---"); |
| 36 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 0, probe_ch, "OK", |
| 37 | "mmc", "mmc2.bootdev"); |
| 38 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 1, probe_ch, "OK", |
| 39 | "mmc", "mmc1.bootdev"); |
| 40 | ut_assert_nextline("%3x [ %c ] %6s %-8s %s", 2, probe_ch, "OK", |
| 41 | "mmc", "mmc0.bootdev"); |
| 42 | ut_assert_nextlinen("---"); |
| 43 | ut_assert_nextline("(3 bootdevs)"); |
| 44 | ut_assert_console_end(); |
| 45 | } |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | BOOTSTD_TEST(bootdev_test_cmd_list, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 50 | |
| 51 | /* Check 'bootdev select' and 'info' commands */ |
| 52 | static int bootdev_test_cmd_select(struct unit_test_state *uts) |
| 53 | { |
| 54 | struct bootstd_priv *std; |
| 55 | |
| 56 | /* get access to the CLI's cur_bootdev */ |
| 57 | ut_assertok(bootstd_get_priv(&std)); |
| 58 | |
| 59 | console_record_reset_enable(); |
| 60 | ut_asserteq(1, run_command("bootdev info", 0)); |
| 61 | ut_assert_nextlinen("Please use"); |
| 62 | ut_assert_console_end(); |
| 63 | |
| 64 | /* select by sequence */ |
| 65 | ut_assertok(run_command("bootdev select 0", 0)); |
| 66 | ut_assert_console_end(); |
| 67 | |
| 68 | ut_assertok(run_command("bootdev info", 0)); |
| 69 | ut_assert_nextline("Name: mmc2.bootdev"); |
| 70 | ut_assert_nextline("Sequence: 0"); |
| 71 | ut_assert_nextline("Status: Probed"); |
| 72 | ut_assert_nextline("Uclass: mmc"); |
| 73 | ut_assert_nextline("Bootflows: 0 (0 valid)"); |
| 74 | ut_assert_console_end(); |
| 75 | |
| 76 | /* select by bootdev name */ |
| 77 | ut_assertok(run_command("bootdev select mmc1.bootdev", 0)); |
| 78 | ut_assert_console_end(); |
| 79 | ut_assertnonnull(std->cur_bootdev); |
| 80 | ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name); |
| 81 | |
| 82 | /* select by bootdev label*/ |
| 83 | ut_assertok(run_command("bootdev select mmc1", 0)); |
| 84 | ut_assert_console_end(); |
| 85 | ut_assertnonnull(std->cur_bootdev); |
| 86 | ut_asserteq_str("mmc1.bootdev", std->cur_bootdev->name); |
| 87 | |
| 88 | /* deselect */ |
| 89 | ut_assertok(run_command("bootdev select", 0)); |
| 90 | ut_assert_console_end(); |
| 91 | ut_assertnull(std->cur_bootdev); |
| 92 | |
| 93 | ut_asserteq(1, run_command("bootdev info", 0)); |
| 94 | ut_assert_nextlinen("Please use"); |
| 95 | ut_assert_console_end(); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | BOOTSTD_TEST(bootdev_test_cmd_select, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 100 | |
| 101 | /* Check bootdev labels */ |
| 102 | static int bootdev_test_labels(struct unit_test_state *uts) |
| 103 | { |
| 104 | struct udevice *dev, *media; |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 105 | int mflags = 0; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 106 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 107 | ut_assertok(bootdev_find_by_label("mmc2", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 108 | ut_asserteq(UCLASS_BOOTDEV, device_get_uclass_id(dev)); |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 109 | ut_asserteq(0, mflags); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 110 | media = dev_get_parent(dev); |
| 111 | ut_asserteq(UCLASS_MMC, device_get_uclass_id(media)); |
| 112 | ut_asserteq_str("mmc2", media->name); |
| 113 | |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 114 | /* Check method flags */ |
| 115 | ut_assertok(bootdev_find_by_label("pxe", &dev, &mflags)); |
| 116 | ut_asserteq(BOOTFLOW_METHF_PXE_ONLY, mflags); |
| 117 | ut_assertok(bootdev_find_by_label("dhcp", &dev, &mflags)); |
| 118 | ut_asserteq(BOOTFLOW_METHF_DHCP_ONLY, mflags); |
| 119 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 120 | /* Check invalid uclass */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 121 | ut_asserteq(-EINVAL, bootdev_find_by_label("fred0", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 122 | |
| 123 | /* Check unknown sequence number */ |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 124 | ut_asserteq(-ENOENT, bootdev_find_by_label("mmc6", &dev, &mflags)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 125 | |
| 126 | return 0; |
| 127 | } |
Simon Glass | e22fe92 | 2023-01-17 10:48:05 -0700 | [diff] [blame] | 128 | BOOTSTD_TEST(bootdev_test_labels, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 129 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 130 | |
| 131 | /* Check bootdev ordering with the bootdev-order property */ |
| 132 | static int bootdev_test_order(struct unit_test_state *uts) |
| 133 | { |
| 134 | struct bootflow_iter iter; |
| 135 | struct bootflow bflow; |
| 136 | |
| 137 | /* |
| 138 | * First try the order set by the bootdev-order property |
| 139 | * Like all sandbox unit tests this relies on the devicetree setting up |
| 140 | * the required devices: |
| 141 | * |
| 142 | * mmc0 - nothing connected |
| 143 | * mmc1 - connected to mmc1.img file |
| 144 | * mmc2 - nothing connected |
| 145 | */ |
| 146 | ut_assertok(env_set("boot_targets", NULL)); |
| 147 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 148 | ut_asserteq(2, iter.num_devs); |
| 149 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); |
| 150 | ut_asserteq_str("mmc1.bootdev", iter.dev_order[1]->name); |
| 151 | bootflow_iter_uninit(&iter); |
| 152 | |
| 153 | /* Use the environment variable to override it */ |
| 154 | ut_assertok(env_set("boot_targets", "mmc1 mmc2")); |
| 155 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 156 | ut_asserteq(2, iter.num_devs); |
| 157 | ut_asserteq_str("mmc1.bootdev", iter.dev_order[0]->name); |
| 158 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[1]->name); |
| 159 | bootflow_iter_uninit(&iter); |
| 160 | |
| 161 | /* |
| 162 | * Now drop both orderings, to check the default (prioriy/sequence) |
| 163 | * ordering |
| 164 | */ |
| 165 | ut_assertok(env_set("boot_targets", NULL)); |
| 166 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 167 | |
| 168 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 169 | ut_asserteq(3, iter.num_devs); |
| 170 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); |
| 171 | ut_asserteq_str("mmc1.bootdev", iter.dev_order[1]->name); |
| 172 | ut_asserteq_str("mmc0.bootdev", iter.dev_order[2]->name); |
| 173 | |
| 174 | /* |
| 175 | * Check that adding aliases for the bootdevs works. We just fake it by |
| 176 | * setting the sequence numbers directly. |
| 177 | */ |
| 178 | iter.dev_order[0]->seq_ = 0; |
| 179 | iter.dev_order[1]->seq_ = 3; |
| 180 | iter.dev_order[2]->seq_ = 2; |
| 181 | bootflow_iter_uninit(&iter); |
| 182 | |
| 183 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 184 | ut_asserteq(3, iter.num_devs); |
| 185 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); |
| 186 | ut_asserteq_str("mmc0.bootdev", iter.dev_order[1]->name); |
| 187 | ut_asserteq_str("mmc1.bootdev", iter.dev_order[2]->name); |
| 188 | bootflow_iter_uninit(&iter); |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | BOOTSTD_TEST(bootdev_test_order, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 193 | |
| 194 | /* Check bootdev ordering with the uclass priority */ |
| 195 | static int bootdev_test_prio(struct unit_test_state *uts) |
| 196 | { |
| 197 | struct bootdev_uc_plat *ucp; |
| 198 | struct bootflow_iter iter; |
| 199 | struct bootflow bflow; |
| 200 | struct udevice *blk; |
| 201 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 202 | test_set_skip_delays(true); |
| 203 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 204 | /* Start up USB which gives us three additional bootdevs */ |
| 205 | usb_started = false; |
| 206 | ut_assertok(run_command("usb start", 0)); |
| 207 | |
| 208 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 209 | |
| 210 | /* 3 MMC and 3 USB bootdevs: MMC should come before USB */ |
| 211 | console_record_reset_enable(); |
| 212 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 213 | ut_asserteq(6, iter.num_devs); |
| 214 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[0]->name); |
| 215 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
| 216 | iter.dev_order[3]->name); |
| 217 | |
| 218 | ut_assertok(bootdev_get_sibling_blk(iter.dev_order[3], &blk)); |
| 219 | ut_asserteq_str("usb_mass_storage.lun0", blk->name); |
| 220 | |
| 221 | /* adjust the priority of the first USB bootdev to the highest */ |
| 222 | ucp = dev_get_uclass_plat(iter.dev_order[3]); |
| 223 | ucp->prio = 1; |
| 224 | |
| 225 | bootflow_iter_uninit(&iter); |
| 226 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 227 | ut_asserteq(6, iter.num_devs); |
| 228 | ut_asserteq_str("usb_mass_storage.lun0.bootdev", |
| 229 | iter.dev_order[0]->name); |
| 230 | ut_asserteq_str("mmc2.bootdev", iter.dev_order[1]->name); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | BOOTSTD_TEST(bootdev_test_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 235 | |
| 236 | /* Check listing hunters */ |
| 237 | static int bootdev_test_hunter(struct unit_test_state *uts) |
| 238 | { |
| 239 | struct bootstd_priv *std; |
| 240 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 241 | test_set_skip_delays(true); |
| 242 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 243 | /* get access to the used hunters */ |
| 244 | ut_assertok(bootstd_get_priv(&std)); |
| 245 | |
| 246 | console_record_reset_enable(); |
| 247 | bootdev_list_hunters(std); |
| 248 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 249 | ut_assert_nextlinen("----"); |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 250 | ut_assert_nextline(" 50 ethernet eth_bootdev"); |
Simon Glass | be7c666 | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 251 | ut_assert_nextline(" 40 ide ide_bootdev"); |
Simon Glass | df71f26 | 2023-01-17 10:47:38 -0700 | [diff] [blame] | 252 | ut_assert_nextline(" 10 mmc mmc_bootdev"); |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 253 | ut_assert_nextline(" 30 nvme nvme_bootdev"); |
Simon Glass | 9985e9c | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 254 | ut_assert_nextline(" 30 scsi scsi_bootdev"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 255 | ut_assert_nextline(" 30 spi_flash sf_bootdev"); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 256 | ut_assert_nextline(" 40 usb usb_bootdev"); |
Simon Glass | a4bf8f6 | 2023-01-17 10:47:52 -0700 | [diff] [blame] | 257 | ut_assert_nextline(" 30 virtio virtio_bootdev"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 258 | ut_assert_nextline("(total hunters: 8)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 259 | ut_assert_console_end(); |
| 260 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 261 | ut_assertok(bootdev_hunt("usb1", false)); |
| 262 | ut_assert_nextline( |
| 263 | "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] | 264 | ut_assert_console_end(); |
| 265 | |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 266 | /* USB is fifth in the list, so bit 6 */ |
| 267 | ut_asserteq(BIT(6), std->hunters_used); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 268 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | BOOTSTD_TEST(bootdev_test_hunter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 272 | |
| 273 | /* Check 'bootdev hunt' command */ |
| 274 | static int bootdev_test_cmd_hunt(struct unit_test_state *uts) |
| 275 | { |
| 276 | struct bootstd_priv *std; |
| 277 | |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 278 | test_set_skip_delays(true); |
| 279 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 280 | /* get access to the used hunters */ |
| 281 | ut_assertok(bootstd_get_priv(&std)); |
| 282 | |
| 283 | console_record_reset_enable(); |
| 284 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 285 | ut_assert_nextline("Prio Used Uclass Hunter"); |
| 286 | ut_assert_nextlinen("----"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 287 | ut_assert_skip_to_line("(total hunters: 8)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 288 | ut_assert_console_end(); |
| 289 | |
| 290 | /* Scan all hunters */ |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 291 | sandbox_set_eth_enable(false); |
| 292 | |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 293 | ut_assertok(run_command("bootdev hunt", 0)); |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 294 | ut_assert_nextline("Hunting with: ethernet"); |
Simon Glass | be7c666 | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 295 | ut_assert_nextline("Hunting with: ide"); |
| 296 | ut_assert_nextline("Bus 0: not available "); |
Simon Glass | df71f26 | 2023-01-17 10:47:38 -0700 | [diff] [blame] | 297 | ut_assert_nextline("Hunting with: mmc"); |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 298 | ut_assert_nextline("Hunting with: nvme"); |
Simon Glass | 9985e9c | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 299 | ut_assert_nextline("Hunting with: scsi"); |
| 300 | ut_assert_nextline("scanning bus for devices..."); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 301 | ut_assert_skip_to_line("Hunting with: spi_flash"); |
| 302 | ut_assert_nextline("Hunting with: usb"); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 303 | ut_assert_nextline( |
| 304 | "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] | 305 | ut_assert_nextline("Hunting with: virtio"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 306 | ut_assert_console_end(); |
| 307 | |
| 308 | /* List available hunters */ |
| 309 | ut_assertok(run_command("bootdev hunt -l", 0)); |
| 310 | ut_assert_nextlinen("Prio"); |
| 311 | ut_assert_nextlinen("----"); |
Simon Glass | 5ea0a8d | 2023-01-17 10:47:40 -0700 | [diff] [blame] | 312 | ut_assert_nextline(" 50 * ethernet eth_bootdev"); |
Simon Glass | be7c666 | 2023-01-17 10:47:46 -0700 | [diff] [blame] | 313 | ut_assert_nextline(" 40 * ide ide_bootdev"); |
Simon Glass | df71f26 | 2023-01-17 10:47:38 -0700 | [diff] [blame] | 314 | ut_assert_nextline(" 10 * mmc mmc_bootdev"); |
Simon Glass | 0838287 | 2023-01-17 10:47:47 -0700 | [diff] [blame] | 315 | ut_assert_nextline(" 30 * nvme nvme_bootdev"); |
Simon Glass | 9985e9c | 2023-01-17 10:47:45 -0700 | [diff] [blame] | 316 | ut_assert_nextline(" 30 * scsi scsi_bootdev"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 317 | ut_assert_nextline(" 30 * spi_flash sf_bootdev"); |
Simon Glass | f3cb89f | 2023-01-17 10:47:37 -0700 | [diff] [blame] | 318 | ut_assert_nextline(" 40 * usb usb_bootdev"); |
Simon Glass | a4bf8f6 | 2023-01-17 10:47:52 -0700 | [diff] [blame] | 319 | ut_assert_nextline(" 30 * virtio virtio_bootdev"); |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 320 | ut_assert_nextline("(total hunters: 8)"); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 321 | ut_assert_console_end(); |
| 322 | |
Simon Glass | 215be68 | 2023-01-17 10:48:03 -0700 | [diff] [blame] | 323 | ut_asserteq(GENMASK(7, 0), std->hunters_used); |
Simon Glass | 5acb97a | 2023-01-17 10:47:33 -0700 | [diff] [blame] | 324 | |
| 325 | return 0; |
| 326 | } |
| 327 | BOOTSTD_TEST(bootdev_test_cmd_hunt, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 328 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 329 | |
| 330 | /* Check that only bootable partitions are processed */ |
| 331 | static int bootdev_test_bootable(struct unit_test_state *uts) |
| 332 | { |
| 333 | struct bootflow_iter iter; |
| 334 | struct bootflow bflow; |
| 335 | struct udevice *blk; |
| 336 | |
| 337 | memset(&iter, '\0', sizeof(iter)); |
| 338 | memset(&bflow, '\0', sizeof(bflow)); |
| 339 | iter.part = 0; |
| 340 | ut_assertok(uclass_get_device_by_name(UCLASS_BLK, "mmc1.blk", &blk)); |
| 341 | iter.dev = blk; |
| 342 | ut_assertok(device_find_next_child(&iter.dev)); |
| 343 | uclass_first_device(UCLASS_BOOTMETH, &bflow.method); |
| 344 | |
| 345 | /* |
| 346 | * initially we don't have any knowledge of which partitions are |
| 347 | * bootable, but mmc1 has two partitions, with the first one being |
| 348 | * bootable |
| 349 | */ |
| 350 | iter.part = 2; |
| 351 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 352 | ut_asserteq(0, iter.first_bootable); |
| 353 | |
| 354 | /* scan with part == 0 to get the partition info */ |
| 355 | iter.part = 0; |
| 356 | ut_asserteq(-ENOENT, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 357 | ut_asserteq(1, iter.first_bootable); |
| 358 | |
| 359 | /* now it will refuse to use non-bootable partitions */ |
| 360 | iter.part = 2; |
| 361 | ut_asserteq(-EINVAL, bootdev_find_in_blk(iter.dev, blk, &iter, &bflow)); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | BOOTSTD_TEST(bootdev_test_bootable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | 3e9f6be | 2023-01-17 10:48:07 -0700 | [diff] [blame^] | 366 | |
| 367 | /* Check hunting for bootdev of a particular priority */ |
| 368 | static int bootdev_test_hunt_prio(struct unit_test_state *uts) |
| 369 | { |
| 370 | test_set_skip_delays(true); |
| 371 | |
| 372 | console_record_reset_enable(); |
| 373 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_2_SCAN_FAST, false)); |
| 374 | ut_assert_nextline("scanning bus for devices..."); |
| 375 | ut_assert_skip_to_line(" Type: Hard Disk"); |
| 376 | ut_assert_nextlinen(" Capacity:"); |
| 377 | ut_assert_console_end(); |
| 378 | |
| 379 | /* now try a different priority, verbosely */ |
| 380 | ut_assertok(bootdev_hunt_prio(BOOTDEVP_3_SCAN_SLOW, true)); |
| 381 | ut_assert_nextline("Hunting with: ide"); |
| 382 | ut_assert_nextline("Bus 0: not available "); |
| 383 | ut_assert_nextline("Hunting with: usb"); |
| 384 | ut_assert_nextline( |
| 385 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
| 386 | ut_assert_console_end(); |
| 387 | |
| 388 | return 0; |
| 389 | } |
| 390 | BOOTSTD_TEST(bootdev_test_hunt_prio, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |