Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for bootdev functions. All start with 'bootdev' |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootdev.h> |
| 11 | #include <bootflow.h> |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 12 | #include <bootmeth.h> |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 13 | #include <bootstd.h> |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 14 | #include <cli.h> |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 16 | #include <expo.h> |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 17 | #ifdef CONFIG_SANDBOX |
Simon Glass | 2662b54 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 18 | #include <asm/test.h> |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 19 | #endif |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 20 | #include <dm/device-internal.h> |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 21 | #include <dm/lists.h> |
| 22 | #include <test/suites.h> |
| 23 | #include <test/ut.h> |
| 24 | #include "bootstd_common.h" |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 25 | #include "../../boot/bootflow_internal.h" |
| 26 | #include "../../boot/scene_internal.h" |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 27 | |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | extern U_BOOT_DRIVER(bootmeth_script); |
| 31 | |
Simon Glass | f25f575 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 32 | static int inject_response(struct unit_test_state *uts) |
| 33 | { |
| 34 | /* |
| 35 | * The image being booted presents a menu of options: |
| 36 | * |
| 37 | * Fedora-Workstation-armhfp-31-1.9 Boot Options. |
| 38 | * 1: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) |
| 39 | * Enter choice: |
| 40 | * |
| 41 | * Provide input for this, to avoid waiting two seconds for a timeout. |
| 42 | */ |
| 43 | ut_asserteq(2, console_in_puts("1\n")); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 48 | /* Check 'bootflow scan/list' commands */ |
| 49 | static int bootflow_cmd(struct unit_test_state *uts) |
| 50 | { |
| 51 | console_record_reset_enable(); |
| 52 | ut_assertok(run_command("bootdev select 1", 0)); |
| 53 | ut_assert_console_end(); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 54 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 55 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 56 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 57 | ut_assert_nextlinen("---"); |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 58 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 59 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 60 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 61 | ut_assert_nextline("No more bootdevs"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 62 | ut_assert_nextlinen("---"); |
| 63 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 64 | ut_assert_console_end(); |
| 65 | |
| 66 | ut_assertok(run_command("bootflow list", 0)); |
| 67 | ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'"); |
| 68 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 69 | ut_assert_nextlinen("---"); |
| 70 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 71 | ut_assert_nextlinen("---"); |
| 72 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 73 | ut_assert_console_end(); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 78 | |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 79 | /* Check 'bootflow scan' with a label / seq */ |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 80 | static int bootflow_cmd_label(struct unit_test_state *uts) |
| 81 | { |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 82 | test_set_eth_enable(false); |
| 83 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 84 | console_record_reset_enable(); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 85 | ut_assertok(run_command("bootflow scan -lH mmc1", 0)); |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 86 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 87 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 88 | ut_assert_console_end(); |
| 89 | |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 90 | ut_assertok(run_command("bootflow scan -lH 0", 0)); |
| 91 | ut_assert_nextline("Scanning for bootflows with label '0'"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 92 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 93 | ut_assert_console_end(); |
| 94 | |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 95 | /* |
| 96 | * with ethernet enabled we have 8 devices ahead of the mmc ones: |
| 97 | * |
| 98 | * ut_assertok(run_command("bootdev list", 0)); |
| 99 | * Seq Probed Status Uclass Name |
| 100 | * --- ------ ------ -------- ------------------ |
| 101 | * 0 [ + ] OK ethernet eth@10002000.bootdev |
| 102 | * 1 [ ] OK ethernet eth@10003000.bootdev |
| 103 | * 2 [ ] OK ethernet sbe5.bootdev |
| 104 | * 3 [ ] OK ethernet eth@10004000.bootdev |
| 105 | * 4 [ ] OK ethernet phy-test-eth.bootdev |
| 106 | * 5 [ ] OK ethernet dsa-test-eth.bootdev |
| 107 | * 6 [ ] OK ethernet dsa-test@0.bootdev |
| 108 | * 7 [ ] OK ethernet dsa-test@1.bootdev |
| 109 | * 8 [ ] OK mmc mmc2.bootdev |
| 110 | * 9 [ + ] OK mmc mmc1.bootdev |
| 111 | * a [ ] OK mmc mmc0.bootdev |
| 112 | */ |
| 113 | ut_assertok(run_command("bootflow scan -lH 9", 0)); |
| 114 | ut_assert_nextline("Scanning for bootflows with label '9'"); |
| 115 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 116 | |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 117 | ut_assertok(run_command("bootflow scan -lH 0", 0)); |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 118 | ut_assert_nextline("Scanning for bootflows with label '0'"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 119 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 120 | ut_assert_console_end(); |
| 121 | |
| 122 | return 0; |
| 123 | } |
Simon Glass | 47aedc2 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 124 | BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT | |
| 125 | UT_TESTF_ETH_BOOTDEV); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 126 | |
| 127 | /* Check 'bootflow scan/list' commands using all bootdevs */ |
| 128 | static int bootflow_cmd_glob(struct unit_test_state *uts) |
| 129 | { |
| 130 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 131 | |
| 132 | console_record_reset_enable(); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 133 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 134 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 135 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 136 | ut_assert_nextlinen("---"); |
| 137 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 138 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 139 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 140 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 141 | ut_assert_nextline("No more bootdevs"); |
| 142 | ut_assert_nextlinen("---"); |
| 143 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 144 | ut_assert_console_end(); |
| 145 | |
| 146 | ut_assertok(run_command("bootflow list", 0)); |
| 147 | ut_assert_nextline("Showing all bootflows"); |
| 148 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 149 | ut_assert_nextlinen("---"); |
| 150 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 151 | ut_assert_nextlinen("---"); |
| 152 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 153 | ut_assert_console_end(); |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 158 | |
| 159 | /* Check 'bootflow scan -e' */ |
| 160 | static int bootflow_cmd_scan_e(struct unit_test_state *uts) |
| 161 | { |
| 162 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 163 | |
| 164 | console_record_reset_enable(); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 165 | ut_assertok(run_command("bootflow scan -aleGH", 0)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 166 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 167 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 168 | ut_assert_nextlinen("---"); |
| 169 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 170 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 171 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 172 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 173 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 174 | |
| 175 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 176 | ut_assert_nextline(" 2 syslinux media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 177 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 178 | ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 179 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 180 | ut_assert_nextline(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 181 | ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 efi/boot/bootsbox.efi"); |
| 182 | |
| 183 | ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); |
| 184 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 185 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 186 | ut_assert_nextline("No more bootdevs"); |
| 187 | ut_assert_nextlinen("---"); |
| 188 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 189 | ut_assert_console_end(); |
| 190 | |
| 191 | ut_assertok(run_command("bootflow list", 0)); |
| 192 | ut_assert_nextline("Showing all bootflows"); |
| 193 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 194 | ut_assert_nextlinen("---"); |
| 195 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 196 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 197 | ut_assert_skip_to_line(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 198 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 199 | ut_assert_nextlinen("---"); |
| 200 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 201 | ut_assert_console_end(); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 206 | |
| 207 | /* Check 'bootflow info' */ |
| 208 | static int bootflow_cmd_info(struct unit_test_state *uts) |
| 209 | { |
| 210 | console_record_reset_enable(); |
| 211 | ut_assertok(run_command("bootdev select 1", 0)); |
| 212 | ut_assert_console_end(); |
| 213 | ut_assertok(run_command("bootflow scan", 0)); |
| 214 | ut_assert_console_end(); |
| 215 | ut_assertok(run_command("bootflow select 0", 0)); |
| 216 | ut_assert_console_end(); |
| 217 | ut_assertok(run_command("bootflow info", 0)); |
| 218 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 219 | ut_assert_nextline("Device: mmc1.bootdev"); |
| 220 | ut_assert_nextline("Block dev: mmc1.blk"); |
| 221 | ut_assert_nextline("Method: syslinux"); |
| 222 | ut_assert_nextline("State: ready"); |
| 223 | ut_assert_nextline("Partition: 1"); |
| 224 | ut_assert_nextline("Subdir: (none)"); |
| 225 | ut_assert_nextline("Filename: /extlinux/extlinux.conf"); |
| 226 | ut_assert_nextlinen("Buffer: "); |
| 227 | ut_assert_nextline("Size: 253 (595 bytes)"); |
Simon Glass | 2175e76 | 2023-01-06 08:52:33 -0600 | [diff] [blame] | 228 | ut_assert_nextline("OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)"); |
Simon Glass | 24d8e1b | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 229 | ut_assert_nextline("Logo: (none)"); |
Simon Glass | 7638c85 | 2023-01-17 10:47:56 -0700 | [diff] [blame] | 230 | ut_assert_nextline("FDT: <NULL>"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 231 | ut_assert_nextline("Error: 0"); |
| 232 | ut_assert_console_end(); |
| 233 | |
| 234 | ut_assertok(run_command("bootflow info -d", 0)); |
| 235 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 236 | ut_assert_skip_to_line("Error: 0"); |
| 237 | ut_assert_nextline("Contents:"); |
| 238 | ut_assert_nextline("%s", ""); |
| 239 | ut_assert_nextline("# extlinux.conf generated by appliance-creator"); |
| 240 | ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img"); |
| 241 | ut_assert_console_end(); |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 246 | |
| 247 | /* Check 'bootflow scan -b' to boot the first available bootdev */ |
| 248 | static int bootflow_scan_boot(struct unit_test_state *uts) |
| 249 | { |
| 250 | console_record_reset_enable(); |
Simon Glass | f25f575 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 251 | ut_assertok(inject_response(uts)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 252 | ut_assertok(run_command("bootflow scan -b", 0)); |
| 253 | ut_assert_nextline( |
| 254 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 255 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 256 | |
| 257 | /* |
| 258 | * We expect it to get through to boot although sandbox always returns |
| 259 | * -EFAULT as it cannot actually boot the kernel |
| 260 | */ |
| 261 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 262 | ut_assert_nextline("Boot failed (err=-14)"); |
| 263 | ut_assert_console_end(); |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 268 | |
| 269 | /* Check iterating through available bootflows */ |
| 270 | static int bootflow_iter(struct unit_test_state *uts) |
| 271 | { |
| 272 | struct bootflow_iter iter; |
| 273 | struct bootflow bflow; |
| 274 | |
| 275 | bootstd_clear_glob(); |
| 276 | |
| 277 | /* The first device is mmc2.bootdev which has no media */ |
| 278 | ut_asserteq(-EPROTONOSUPPORT, |
Simon Glass | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 279 | bootflow_scan_first(NULL, NULL, &iter, |
Simon Glass | 4f806f3 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 280 | BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 281 | ut_asserteq(2, iter.num_methods); |
| 282 | ut_asserteq(0, iter.cur_method); |
| 283 | ut_asserteq(0, iter.part); |
| 284 | ut_asserteq(0, iter.max_part); |
| 285 | ut_asserteq_str("syslinux", iter.method->name); |
| 286 | ut_asserteq(0, bflow.err); |
| 287 | |
| 288 | /* |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 289 | * This shows MEDIA even though there is none, since in |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 290 | * bootdev_find_in_blk() we call part_get_info() which returns |
| 291 | * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would |
| 292 | * know. |
| 293 | */ |
| 294 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 295 | |
| 296 | ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); |
| 297 | ut_asserteq(2, iter.num_methods); |
| 298 | ut_asserteq(1, iter.cur_method); |
| 299 | ut_asserteq(0, iter.part); |
| 300 | ut_asserteq(0, iter.max_part); |
| 301 | ut_asserteq_str("efi", iter.method->name); |
| 302 | ut_asserteq(0, bflow.err); |
| 303 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 304 | bootflow_free(&bflow); |
| 305 | |
| 306 | /* The next device is mmc1.bootdev - at first we use the whole device */ |
| 307 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 308 | ut_asserteq(2, iter.num_methods); |
| 309 | ut_asserteq(0, iter.cur_method); |
| 310 | ut_asserteq(0, iter.part); |
| 311 | ut_asserteq(0x1e, iter.max_part); |
| 312 | ut_asserteq_str("syslinux", iter.method->name); |
| 313 | ut_asserteq(0, bflow.err); |
| 314 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 315 | bootflow_free(&bflow); |
| 316 | |
| 317 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 318 | ut_asserteq(2, iter.num_methods); |
| 319 | ut_asserteq(1, iter.cur_method); |
| 320 | ut_asserteq(0, iter.part); |
| 321 | ut_asserteq(0x1e, iter.max_part); |
| 322 | ut_asserteq_str("efi", iter.method->name); |
| 323 | ut_asserteq(0, bflow.err); |
| 324 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 325 | bootflow_free(&bflow); |
| 326 | |
| 327 | /* Then more to partition 1 where we find something */ |
| 328 | ut_assertok(bootflow_scan_next(&iter, &bflow)); |
| 329 | ut_asserteq(2, iter.num_methods); |
| 330 | ut_asserteq(0, iter.cur_method); |
| 331 | ut_asserteq(1, iter.part); |
| 332 | ut_asserteq(0x1e, iter.max_part); |
| 333 | ut_asserteq_str("syslinux", iter.method->name); |
| 334 | ut_asserteq(0, bflow.err); |
| 335 | ut_asserteq(BOOTFLOWST_READY, bflow.state); |
| 336 | bootflow_free(&bflow); |
| 337 | |
| 338 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 339 | ut_asserteq(2, iter.num_methods); |
| 340 | ut_asserteq(1, iter.cur_method); |
| 341 | ut_asserteq(1, iter.part); |
| 342 | ut_asserteq(0x1e, iter.max_part); |
| 343 | ut_asserteq_str("efi", iter.method->name); |
| 344 | ut_asserteq(0, bflow.err); |
| 345 | ut_asserteq(BOOTFLOWST_FS, bflow.state); |
| 346 | bootflow_free(&bflow); |
| 347 | |
Simon Glass | dcffa44 | 2023-01-17 10:47:41 -0700 | [diff] [blame] | 348 | /* Then more to partition 2 which exists but is not bootable */ |
Simon Glass | f0e358f | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 349 | ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 350 | ut_asserteq(2, iter.num_methods); |
| 351 | ut_asserteq(0, iter.cur_method); |
| 352 | ut_asserteq(2, iter.part); |
| 353 | ut_asserteq(0x1e, iter.max_part); |
| 354 | ut_asserteq_str("syslinux", iter.method->name); |
| 355 | ut_asserteq(0, bflow.err); |
Simon Glass | f0e358f | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 356 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 357 | bootflow_free(&bflow); |
| 358 | |
| 359 | bootflow_iter_uninit(&iter); |
| 360 | |
| 361 | ut_assert_console_end(); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 366 | |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 367 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 368 | /* Check using the system bootdev */ |
| 369 | static int bootflow_system(struct unit_test_state *uts) |
| 370 | { |
Simon Glass | ecb274c | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 371 | struct udevice *bootstd, *dev; |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 372 | |
Simon Glass | ae0bf22 | 2022-10-11 09:47:20 -0600 | [diff] [blame] | 373 | if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) |
Simon Glass | c43635b | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 374 | return -EAGAIN; |
Simon Glass | ecb274c | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 375 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 376 | ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_efi_mgr), |
| 377 | "efi_mgr", 0, ofnode_null(), &dev)); |
| 378 | ut_assertok(device_probe(dev)); |
Simon Glass | 2662b54 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 379 | sandbox_set_fake_efi_mgr_dev(dev, true); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 380 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 381 | /* We should get a single 'bootmgr' method right at the end */ |
| 382 | bootstd_clear_glob(); |
| 383 | console_record_reset_enable(); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 384 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | c627cfc | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 385 | ut_assert_skip_to_line( |
Simon Glass | bd18b69 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 386 | " 0 efi_mgr ready (none) 0 <NULL> <NULL>"); |
Simon Glass | c627cfc | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 387 | ut_assert_skip_to_line("No more bootdevs"); |
Simon Glass | ecb274c | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 388 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 389 | ut_assert_console_end(); |
| 390 | |
| 391 | return 0; |
| 392 | } |
Simon Glass | bd18b69 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 393 | BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA | |
| 394 | UT_TESTF_SCAN_FDT); |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 395 | #endif |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 396 | |
| 397 | /* Check disabling a bootmethod if it requests it */ |
| 398 | static int bootflow_iter_disable(struct unit_test_state *uts) |
| 399 | { |
| 400 | struct udevice *bootstd, *dev; |
| 401 | struct bootflow_iter iter; |
| 402 | struct bootflow bflow; |
| 403 | int i; |
| 404 | |
| 405 | /* Add the EFI bootmgr driver */ |
| 406 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 407 | ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox", |
| 408 | &dev)); |
| 409 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 410 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 411 | |
| 412 | bootstd_clear_glob(); |
Simon Glass | f25f575 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 413 | console_record_reset_enable(); |
| 414 | ut_assertok(inject_response(uts)); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 415 | ut_assertok(run_command("bootflow scan -lbH", 0)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 416 | |
| 417 | /* Try to boot the bootmgr flow, which will fail */ |
| 418 | console_record_reset_enable(); |
Simon Glass | 4b7cb05 | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 419 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 420 | ut_asserteq(3, iter.num_methods); |
| 421 | ut_asserteq_str("sandbox", iter.method->name); |
Simon Glass | f25f575 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 422 | ut_assertok(inject_response(uts)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 423 | ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); |
| 424 | |
| 425 | ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried"); |
| 426 | ut_assert_console_end(); |
| 427 | |
| 428 | /* Check that the sandbox bootmeth has been removed */ |
| 429 | ut_asserteq(2, iter.num_methods); |
| 430 | for (i = 0; i < iter.num_methods; i++) |
| 431 | ut_assert(strcmp("sandbox", iter.method_order[i]->name)); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 436 | |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 437 | /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */ |
| 438 | static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts) |
| 439 | { |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 440 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c43635b | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 441 | return -EAGAIN; |
Simon Glass | 11361c5 | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 442 | |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 443 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 444 | |
| 445 | /* |
| 446 | * Make sure that the -G flag makes the scan fail, since this is not |
| 447 | * supported when an ordering is provided |
| 448 | */ |
| 449 | console_record_reset_enable(); |
| 450 | ut_assertok(bootmeth_set_order("efi firmware0")); |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 451 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 452 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 453 | ut_assert_nextline( |
| 454 | "Seq Method State Uclass Part Name Filename"); |
| 455 | ut_assert_nextlinen("---"); |
| 456 | ut_assert_nextlinen("---"); |
| 457 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 458 | ut_assert_console_end(); |
| 459 | |
Simon Glass | 18552d2 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 460 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | 0917f77 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 461 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 462 | ut_assert_nextline( |
| 463 | "Seq Method State Uclass Part Name Filename"); |
| 464 | ut_assert_nextlinen("---"); |
| 465 | ut_assert_nextline("Scanning global bootmeth 'firmware0':"); |
| 466 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 467 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 468 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 469 | ut_assert_nextline("No more bootdevs"); |
| 470 | ut_assert_nextlinen("---"); |
| 471 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 472 | ut_assert_console_end(); |
| 473 | |
| 474 | return 0; |
| 475 | } |
| 476 | BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 477 | |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 478 | /* Check 'bootflow boot' to boot a selected bootflow */ |
| 479 | static int bootflow_cmd_boot(struct unit_test_state *uts) |
| 480 | { |
| 481 | console_record_reset_enable(); |
| 482 | ut_assertok(run_command("bootdev select 1", 0)); |
| 483 | ut_assert_console_end(); |
| 484 | ut_assertok(run_command("bootflow scan", 0)); |
| 485 | ut_assert_console_end(); |
| 486 | ut_assertok(run_command("bootflow select 0", 0)); |
| 487 | ut_assert_console_end(); |
Simon Glass | f25f575 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 488 | |
| 489 | ut_assertok(inject_response(uts)); |
Simon Glass | fb1451b | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 490 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 491 | ut_assert_nextline( |
| 492 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 493 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 494 | |
| 495 | /* |
| 496 | * We expect it to get through to boot although sandbox always returns |
| 497 | * -EFAULT as it cannot actually boot the kernel |
| 498 | */ |
| 499 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 500 | ut_assert_nextline("Boot failed (err=-14)"); |
| 501 | ut_assert_console_end(); |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 506 | |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 507 | /** |
| 508 | * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian |
| 509 | * |
| 510 | * @uts: Unit test state |
| 511 | * Returns 0 on success, -ve on failure |
| 512 | */ |
| 513 | static int prep_mmc4_bootdev(struct unit_test_state *uts) |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 514 | { |
| 515 | static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL}; |
| 516 | struct udevice *dev, *bootstd; |
| 517 | struct bootstd_priv *std; |
| 518 | const char **old_order; |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 519 | ofnode node; |
| 520 | |
| 521 | /* Enable the mmc4 node since we need a second bootflow */ |
| 522 | node = ofnode_path("/mmc4"); |
| 523 | ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false)); |
| 524 | |
| 525 | /* Enable the script bootmeth too */ |
| 526 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 527 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script), |
| 528 | "bootmeth_script", 0, ofnode_null(), &dev)); |
| 529 | |
| 530 | /* Change the order to include mmc4 */ |
| 531 | std = dev_get_priv(bootstd); |
| 532 | old_order = std->bootdev_order; |
| 533 | std->bootdev_order = order; |
| 534 | |
| 535 | console_record_reset_enable(); |
| 536 | ut_assertok(run_command("bootflow scan", 0)); |
| 537 | ut_assert_console_end(); |
| 538 | |
| 539 | /* Restore the order used by the device tree */ |
| 540 | std->bootdev_order = old_order; |
| 541 | |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | /* Check 'bootflow menu' to select a bootflow */ |
| 546 | static int bootflow_cmd_menu(struct unit_test_state *uts) |
| 547 | { |
| 548 | char prev[3]; |
| 549 | |
| 550 | ut_assertok(prep_mmc4_bootdev(uts)); |
| 551 | |
Simon Glass | d985f1d | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 552 | /* Add keypresses to move to and select the second one in the list */ |
| 553 | prev[0] = CTL_CH('n'); |
| 554 | prev[1] = '\r'; |
| 555 | prev[2] = '\0'; |
| 556 | ut_asserteq(2, console_in_puts(prev)); |
| 557 | |
| 558 | ut_assertok(run_command("bootflow menu", 0)); |
| 559 | ut_assert_nextline("Selected: Armbian"); |
| 560 | ut_assert_console_end(); |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 565 | |
Simon Glass | 91943ff | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 566 | /* Check searching for a single bootdev using the hunters */ |
| 567 | static int bootflow_cmd_hunt_single(struct unit_test_state *uts) |
| 568 | { |
| 569 | struct bootstd_priv *std; |
| 570 | |
| 571 | /* get access to the used hunters */ |
| 572 | ut_assertok(bootstd_get_priv(&std)); |
| 573 | |
| 574 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 575 | |
| 576 | console_record_reset_enable(); |
| 577 | ut_assertok(run_command("bootflow scan -l mmc1", 0)); |
| 578 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
| 579 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 580 | ut_assert_console_end(); |
| 581 | |
| 582 | /* check that the hunter was used */ |
| 583 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 584 | |
| 585 | return 0; |
| 586 | } |
| 587 | BOOTSTD_TEST(bootflow_cmd_hunt_single, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 588 | |
| 589 | /* Check searching for a uclass label using the hunters */ |
| 590 | static int bootflow_cmd_hunt_label(struct unit_test_state *uts) |
| 591 | { |
| 592 | struct bootstd_priv *std; |
| 593 | |
| 594 | /* get access to the used hunters */ |
| 595 | ut_assertok(bootstd_get_priv(&std)); |
| 596 | |
| 597 | test_set_skip_delays(true); |
| 598 | test_set_eth_enable(false); |
| 599 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 600 | |
| 601 | console_record_reset_enable(); |
| 602 | ut_assertok(run_command("bootflow scan -l mmc", 0)); |
| 603 | |
| 604 | /* check that the hunter was used */ |
| 605 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 606 | |
| 607 | /* check that we got the mmc1 bootflow */ |
| 608 | ut_assert_nextline("Scanning for bootflows with label 'mmc'"); |
| 609 | ut_assert_nextlinen("Seq"); |
| 610 | ut_assert_nextlinen("---"); |
| 611 | ut_assert_nextline("Hunting with: simple_bus"); |
| 612 | ut_assert_nextline("Found 2 extension board(s)."); |
| 613 | ut_assert_nextline("Hunting with: mmc"); |
| 614 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 615 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 616 | ut_assert_nextline( |
| 617 | " 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 618 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 619 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 620 | ut_assert_console_end(); |
| 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | BOOTSTD_TEST(bootflow_cmd_hunt_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 625 | |
Simon Glass | e64c295 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 626 | /** |
| 627 | * check_font() - Check that the font size for an item matches expectations |
| 628 | * |
| 629 | * @uts: Unit test state |
| 630 | * @scn: Scene containing the text object |
| 631 | * @id: ID of the text object |
| 632 | * Returns 0 on success, -ve on failure |
| 633 | */ |
| 634 | static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, |
| 635 | int font_size) |
| 636 | { |
| 637 | struct scene_obj_txt *txt; |
| 638 | |
| 639 | txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); |
| 640 | ut_assertnonnull(txt); |
| 641 | |
| 642 | ut_asserteq(font_size, txt->font_size); |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | /* Check themes work with a bootflow menu */ |
| 648 | static int bootflow_menu_theme(struct unit_test_state *uts) |
| 649 | { |
| 650 | const int font_size = 30; |
| 651 | struct scene *scn; |
| 652 | struct expo *exp; |
| 653 | ofnode node; |
| 654 | int i; |
| 655 | |
| 656 | ut_assertok(prep_mmc4_bootdev(uts)); |
| 657 | |
| 658 | ut_assertok(bootflow_menu_new(&exp)); |
| 659 | node = ofnode_path("/bootstd/theme"); |
| 660 | ut_assert(ofnode_valid(node)); |
| 661 | ut_assertok(bootflow_menu_apply_theme(exp, node)); |
| 662 | |
| 663 | scn = expo_lookup_scene_id(exp, MAIN); |
| 664 | ut_assertnonnull(scn); |
| 665 | |
| 666 | /* |
| 667 | * Check that the txt objects have the correct font size from the |
| 668 | * device tree node: bootstd/theme |
| 669 | * |
| 670 | * Check both menu items, since there are two bootflows |
| 671 | */ |
| 672 | ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); |
| 673 | ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); |
| 674 | for (i = 0; i < 2; i++) { |
| 675 | ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); |
| 676 | ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); |
| 677 | ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size)); |
| 678 | } |
| 679 | |
| 680 | expo_destroy(exp); |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |