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 <bootdev.h> |
| 11 | #include <bootflow.h> |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 12 | #include <bootmeth.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 13 | #include <bootstd.h> |
| 14 | #include <dm.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 15 | #ifdef CONFIG_SANDBOX |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 16 | #include <asm/test.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 17 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 18 | #include <dm/lists.h> |
| 19 | #include <test/suites.h> |
| 20 | #include <test/ut.h> |
| 21 | #include "bootstd_common.h" |
| 22 | |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 23 | static int inject_response(struct unit_test_state *uts) |
| 24 | { |
| 25 | /* |
| 26 | * The image being booted presents a menu of options: |
| 27 | * |
| 28 | * Fedora-Workstation-armhfp-31-1.9 Boot Options. |
| 29 | * 1: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) |
| 30 | * Enter choice: |
| 31 | * |
| 32 | * Provide input for this, to avoid waiting two seconds for a timeout. |
| 33 | */ |
| 34 | ut_asserteq(2, console_in_puts("1\n")); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 39 | /* Check 'bootflow scan/list' commands */ |
| 40 | static int bootflow_cmd(struct unit_test_state *uts) |
| 41 | { |
| 42 | console_record_reset_enable(); |
| 43 | ut_assertok(run_command("bootdev select 1", 0)); |
| 44 | ut_assert_console_end(); |
| 45 | ut_assertok(run_command("bootflow scan -l", 0)); |
| 46 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 47 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 48 | ut_assert_nextlinen("---"); |
| 49 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 50 | ut_assert_nextlinen("---"); |
| 51 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 52 | ut_assert_console_end(); |
| 53 | |
| 54 | ut_assertok(run_command("bootflow list", 0)); |
| 55 | ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'"); |
| 56 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 57 | ut_assert_nextlinen("---"); |
| 58 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 59 | ut_assert_nextlinen("---"); |
| 60 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 61 | ut_assert_console_end(); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 66 | |
| 67 | /* Check 'bootflow scan' with a name / label / seq */ |
| 68 | static int bootflow_cmd_label(struct unit_test_state *uts) |
| 69 | { |
| 70 | console_record_reset_enable(); |
| 71 | ut_assertok(run_command("bootflow scan -l mmc1", 0)); |
| 72 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 73 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 74 | ut_assert_console_end(); |
| 75 | |
| 76 | ut_assertok(run_command("bootflow scan -l mmc0.bootdev", 0)); |
| 77 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc0.bootdev'"); |
| 78 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 79 | ut_assert_console_end(); |
| 80 | |
| 81 | ut_assertok(run_command("bootflow scan -l 0", 0)); |
| 82 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc2.bootdev'"); |
| 83 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 84 | ut_assert_console_end(); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 89 | |
| 90 | /* Check 'bootflow scan/list' commands using all bootdevs */ |
| 91 | static int bootflow_cmd_glob(struct unit_test_state *uts) |
| 92 | { |
| 93 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 94 | |
| 95 | console_record_reset_enable(); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 96 | ut_assertok(run_command("bootflow scan -lG", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 97 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 98 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 99 | ut_assert_nextlinen("---"); |
| 100 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 101 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 102 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 103 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 104 | ut_assert_nextline("No more bootdevs"); |
| 105 | ut_assert_nextlinen("---"); |
| 106 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 107 | ut_assert_console_end(); |
| 108 | |
| 109 | ut_assertok(run_command("bootflow list", 0)); |
| 110 | ut_assert_nextline("Showing all bootflows"); |
| 111 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 112 | ut_assert_nextlinen("---"); |
| 113 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 114 | ut_assert_nextlinen("---"); |
| 115 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 116 | ut_assert_console_end(); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 121 | |
| 122 | /* Check 'bootflow scan -e' */ |
| 123 | static int bootflow_cmd_scan_e(struct unit_test_state *uts) |
| 124 | { |
| 125 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 126 | |
| 127 | console_record_reset_enable(); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 128 | ut_assertok(run_command("bootflow scan -aleG", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 129 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 130 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 131 | ut_assert_nextlinen("---"); |
| 132 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 133 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 134 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 135 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 136 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 137 | |
| 138 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 139 | ut_assert_nextline(" 2 syslinux media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 140 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 141 | ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 142 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 143 | ut_assert_nextline(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 144 | ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 efi/boot/bootsbox.efi"); |
| 145 | |
| 146 | ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); |
| 147 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 148 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 149 | ut_assert_nextline("No more bootdevs"); |
| 150 | ut_assert_nextlinen("---"); |
| 151 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 152 | ut_assert_console_end(); |
| 153 | |
| 154 | ut_assertok(run_command("bootflow list", 0)); |
| 155 | ut_assert_nextline("Showing all bootflows"); |
| 156 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 157 | ut_assert_nextlinen("---"); |
| 158 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 159 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 160 | ut_assert_skip_to_line(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 161 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 162 | ut_assert_nextlinen("---"); |
| 163 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 164 | ut_assert_console_end(); |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 169 | |
| 170 | /* Check 'bootflow info' */ |
| 171 | static int bootflow_cmd_info(struct unit_test_state *uts) |
| 172 | { |
| 173 | console_record_reset_enable(); |
| 174 | ut_assertok(run_command("bootdev select 1", 0)); |
| 175 | ut_assert_console_end(); |
| 176 | ut_assertok(run_command("bootflow scan", 0)); |
| 177 | ut_assert_console_end(); |
| 178 | ut_assertok(run_command("bootflow select 0", 0)); |
| 179 | ut_assert_console_end(); |
| 180 | ut_assertok(run_command("bootflow info", 0)); |
| 181 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 182 | ut_assert_nextline("Device: mmc1.bootdev"); |
| 183 | ut_assert_nextline("Block dev: mmc1.blk"); |
| 184 | ut_assert_nextline("Method: syslinux"); |
| 185 | ut_assert_nextline("State: ready"); |
| 186 | ut_assert_nextline("Partition: 1"); |
| 187 | ut_assert_nextline("Subdir: (none)"); |
| 188 | ut_assert_nextline("Filename: /extlinux/extlinux.conf"); |
| 189 | ut_assert_nextlinen("Buffer: "); |
| 190 | ut_assert_nextline("Size: 253 (595 bytes)"); |
| 191 | ut_assert_nextline("Error: 0"); |
| 192 | ut_assert_console_end(); |
| 193 | |
| 194 | ut_assertok(run_command("bootflow info -d", 0)); |
| 195 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 196 | ut_assert_skip_to_line("Error: 0"); |
| 197 | ut_assert_nextline("Contents:"); |
| 198 | ut_assert_nextline("%s", ""); |
| 199 | ut_assert_nextline("# extlinux.conf generated by appliance-creator"); |
| 200 | ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img"); |
| 201 | ut_assert_console_end(); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 206 | |
| 207 | /* Check 'bootflow scan -b' to boot the first available bootdev */ |
| 208 | static int bootflow_scan_boot(struct unit_test_state *uts) |
| 209 | { |
| 210 | console_record_reset_enable(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 211 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 212 | ut_assertok(run_command("bootflow scan -b", 0)); |
| 213 | ut_assert_nextline( |
| 214 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 215 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 216 | |
| 217 | /* |
| 218 | * We expect it to get through to boot although sandbox always returns |
| 219 | * -EFAULT as it cannot actually boot the kernel |
| 220 | */ |
| 221 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 222 | ut_assert_nextline("Boot failed (err=-14)"); |
| 223 | ut_assert_console_end(); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 228 | |
| 229 | /* Check iterating through available bootflows */ |
| 230 | static int bootflow_iter(struct unit_test_state *uts) |
| 231 | { |
| 232 | struct bootflow_iter iter; |
| 233 | struct bootflow bflow; |
| 234 | |
| 235 | bootstd_clear_glob(); |
| 236 | |
| 237 | /* The first device is mmc2.bootdev which has no media */ |
| 238 | ut_asserteq(-EPROTONOSUPPORT, |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 239 | bootflow_scan_first(&iter, BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 240 | ut_asserteq(2, iter.num_methods); |
| 241 | ut_asserteq(0, iter.cur_method); |
| 242 | ut_asserteq(0, iter.part); |
| 243 | ut_asserteq(0, iter.max_part); |
| 244 | ut_asserteq_str("syslinux", iter.method->name); |
| 245 | ut_asserteq(0, bflow.err); |
| 246 | |
| 247 | /* |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 248 | * This shows MEDIA even though there is none, since in |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 249 | * bootdev_find_in_blk() we call part_get_info() which returns |
| 250 | * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would |
| 251 | * know. |
| 252 | */ |
| 253 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 254 | |
| 255 | ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); |
| 256 | ut_asserteq(2, iter.num_methods); |
| 257 | ut_asserteq(1, iter.cur_method); |
| 258 | ut_asserteq(0, iter.part); |
| 259 | ut_asserteq(0, iter.max_part); |
| 260 | ut_asserteq_str("efi", iter.method->name); |
| 261 | ut_asserteq(0, bflow.err); |
| 262 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 263 | bootflow_free(&bflow); |
| 264 | |
| 265 | /* The next device is mmc1.bootdev - at first we use the whole device */ |
| 266 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 267 | ut_asserteq(2, iter.num_methods); |
| 268 | ut_asserteq(0, iter.cur_method); |
| 269 | ut_asserteq(0, iter.part); |
| 270 | ut_asserteq(0x1e, iter.max_part); |
| 271 | ut_asserteq_str("syslinux", iter.method->name); |
| 272 | ut_asserteq(0, bflow.err); |
| 273 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 274 | bootflow_free(&bflow); |
| 275 | |
| 276 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 277 | ut_asserteq(2, iter.num_methods); |
| 278 | ut_asserteq(1, iter.cur_method); |
| 279 | ut_asserteq(0, iter.part); |
| 280 | ut_asserteq(0x1e, iter.max_part); |
| 281 | ut_asserteq_str("efi", iter.method->name); |
| 282 | ut_asserteq(0, bflow.err); |
| 283 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 284 | bootflow_free(&bflow); |
| 285 | |
| 286 | /* Then more to partition 1 where we find something */ |
| 287 | ut_assertok(bootflow_scan_next(&iter, &bflow)); |
| 288 | ut_asserteq(2, iter.num_methods); |
| 289 | ut_asserteq(0, iter.cur_method); |
| 290 | ut_asserteq(1, iter.part); |
| 291 | ut_asserteq(0x1e, iter.max_part); |
| 292 | ut_asserteq_str("syslinux", iter.method->name); |
| 293 | ut_asserteq(0, bflow.err); |
| 294 | ut_asserteq(BOOTFLOWST_READY, bflow.state); |
| 295 | bootflow_free(&bflow); |
| 296 | |
| 297 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 298 | ut_asserteq(2, iter.num_methods); |
| 299 | ut_asserteq(1, iter.cur_method); |
| 300 | ut_asserteq(1, iter.part); |
| 301 | ut_asserteq(0x1e, iter.max_part); |
| 302 | ut_asserteq_str("efi", iter.method->name); |
| 303 | ut_asserteq(0, bflow.err); |
| 304 | ut_asserteq(BOOTFLOWST_FS, bflow.state); |
| 305 | bootflow_free(&bflow); |
| 306 | |
| 307 | /* Then more to partition 2 which doesn't exist */ |
| 308 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 309 | ut_asserteq(2, iter.num_methods); |
| 310 | ut_asserteq(0, iter.cur_method); |
| 311 | ut_asserteq(2, iter.part); |
| 312 | ut_asserteq(0x1e, iter.max_part); |
| 313 | ut_asserteq_str("syslinux", iter.method->name); |
| 314 | ut_asserteq(0, bflow.err); |
| 315 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 316 | bootflow_free(&bflow); |
| 317 | |
| 318 | bootflow_iter_uninit(&iter); |
| 319 | |
| 320 | ut_assert_console_end(); |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 325 | |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 326 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 327 | /* Check using the system bootdev */ |
| 328 | static int bootflow_system(struct unit_test_state *uts) |
| 329 | { |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 330 | struct udevice *dev; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 331 | |
Simon Glass | 49efb06 | 2022-10-11 09:47:20 -0600 | [diff] [blame] | 332 | if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 333 | return -EAGAIN; |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 334 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr", |
| 335 | &dev)); |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 336 | sandbox_set_fake_efi_mgr_dev(dev, true); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 337 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 338 | /* We should get a single 'bootmgr' method right at the end */ |
| 339 | bootstd_clear_glob(); |
| 340 | console_record_reset_enable(); |
| 341 | ut_assertok(run_command("bootflow scan -l", 0)); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 342 | ut_assert_skip_to_line( |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 343 | " 0 efi_mgr ready (none) 0 <NULL> <NULL>"); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 344 | ut_assert_skip_to_line("No more bootdevs"); |
Simon Glass | 9f4440d | 2022-07-30 15:52:29 -0600 | [diff] [blame] | 345 | ut_assert_skip_to_line("(5 bootflows, 5 valid)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 346 | ut_assert_console_end(); |
| 347 | |
| 348 | return 0; |
| 349 | } |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 350 | BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA | |
| 351 | UT_TESTF_SCAN_FDT); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 352 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 353 | |
| 354 | /* Check disabling a bootmethod if it requests it */ |
| 355 | static int bootflow_iter_disable(struct unit_test_state *uts) |
| 356 | { |
| 357 | struct udevice *bootstd, *dev; |
| 358 | struct bootflow_iter iter; |
| 359 | struct bootflow bflow; |
| 360 | int i; |
| 361 | |
| 362 | /* Add the EFI bootmgr driver */ |
| 363 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 364 | ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox", |
| 365 | &dev)); |
| 366 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 367 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 368 | |
| 369 | bootstd_clear_glob(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 370 | console_record_reset_enable(); |
| 371 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 372 | ut_assertok(run_command("bootflow scan -lb", 0)); |
| 373 | |
| 374 | /* Try to boot the bootmgr flow, which will fail */ |
| 375 | console_record_reset_enable(); |
| 376 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 377 | ut_asserteq(3, iter.num_methods); |
| 378 | ut_asserteq_str("sandbox", iter.method->name); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 379 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 380 | ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); |
| 381 | |
| 382 | ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried"); |
| 383 | ut_assert_console_end(); |
| 384 | |
| 385 | /* Check that the sandbox bootmeth has been removed */ |
| 386 | ut_asserteq(2, iter.num_methods); |
| 387 | for (i = 0; i < iter.num_methods; i++) |
| 388 | ut_assert(strcmp("sandbox", iter.method_order[i]->name)); |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 393 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 394 | /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */ |
| 395 | static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts) |
| 396 | { |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 397 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 398 | return -EAGAIN; |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 399 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 400 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 401 | |
| 402 | /* |
| 403 | * Make sure that the -G flag makes the scan fail, since this is not |
| 404 | * supported when an ordering is provided |
| 405 | */ |
| 406 | console_record_reset_enable(); |
| 407 | ut_assertok(bootmeth_set_order("efi firmware0")); |
| 408 | ut_assertok(run_command("bootflow scan -lG", 0)); |
| 409 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 410 | ut_assert_nextline( |
| 411 | "Seq Method State Uclass Part Name Filename"); |
| 412 | ut_assert_nextlinen("---"); |
| 413 | ut_assert_nextlinen("---"); |
| 414 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 415 | ut_assert_console_end(); |
| 416 | |
| 417 | ut_assertok(run_command("bootflow scan -l", 0)); |
| 418 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 419 | ut_assert_nextline( |
| 420 | "Seq Method State Uclass Part Name Filename"); |
| 421 | ut_assert_nextlinen("---"); |
| 422 | ut_assert_nextline("Scanning global bootmeth 'firmware0':"); |
| 423 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 424 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 425 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 426 | ut_assert_nextline("No more bootdevs"); |
| 427 | ut_assert_nextlinen("---"); |
| 428 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 429 | ut_assert_console_end(); |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 434 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 435 | /* Check 'bootflow boot' to boot a selected bootflow */ |
| 436 | static int bootflow_cmd_boot(struct unit_test_state *uts) |
| 437 | { |
| 438 | console_record_reset_enable(); |
| 439 | ut_assertok(run_command("bootdev select 1", 0)); |
| 440 | ut_assert_console_end(); |
| 441 | ut_assertok(run_command("bootflow scan", 0)); |
| 442 | ut_assert_console_end(); |
| 443 | ut_assertok(run_command("bootflow select 0", 0)); |
| 444 | ut_assert_console_end(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 445 | |
| 446 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 447 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 448 | ut_assert_nextline( |
| 449 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 450 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 451 | |
| 452 | /* |
| 453 | * We expect it to get through to boot although sandbox always returns |
| 454 | * -EFAULT as it cannot actually boot the kernel |
| 455 | */ |
| 456 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 457 | ut_assert_nextline("Boot failed (err=-14)"); |
| 458 | ut_assert_console_end(); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |