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> |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 14 | #include <cli.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 15 | #include <dm.h> |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame^] | 16 | #include <expo.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 17 | #ifdef CONFIG_SANDBOX |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 18 | #include <asm/test.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 19 | #endif |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 20 | #include <dm/device-internal.h> |
Simon Glass | b255efc | 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 | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame^] | 25 | #include "../../boot/bootflow_internal.h" |
| 26 | #include "../../boot/scene_internal.h" |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 27 | |
Simon Glass | d2bc33ed | 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 | 49ad1d8 | 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 | b255efc | 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(); |
| 54 | ut_assertok(run_command("bootflow scan -l", 0)); |
| 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("---"); |
| 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 | ut_assertok(run_command("bootflow list", 0)); |
| 64 | ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'"); |
| 65 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 66 | ut_assert_nextlinen("---"); |
| 67 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 68 | ut_assert_nextlinen("---"); |
| 69 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 70 | ut_assert_console_end(); |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 75 | |
| 76 | /* Check 'bootflow scan' with a name / label / seq */ |
| 77 | static int bootflow_cmd_label(struct unit_test_state *uts) |
| 78 | { |
| 79 | console_record_reset_enable(); |
| 80 | ut_assertok(run_command("bootflow scan -l mmc1", 0)); |
| 81 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 82 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 83 | ut_assert_console_end(); |
| 84 | |
| 85 | ut_assertok(run_command("bootflow scan -l mmc0.bootdev", 0)); |
| 86 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc0.bootdev'"); |
| 87 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 88 | ut_assert_console_end(); |
| 89 | |
| 90 | ut_assertok(run_command("bootflow scan -l 0", 0)); |
| 91 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc2.bootdev'"); |
| 92 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 93 | ut_assert_console_end(); |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 98 | |
| 99 | /* Check 'bootflow scan/list' commands using all bootdevs */ |
| 100 | static int bootflow_cmd_glob(struct unit_test_state *uts) |
| 101 | { |
| 102 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 103 | |
| 104 | console_record_reset_enable(); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 105 | ut_assertok(run_command("bootflow scan -lG", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 106 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 107 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 108 | ut_assert_nextlinen("---"); |
| 109 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 110 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 111 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 112 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 113 | ut_assert_nextline("No more bootdevs"); |
| 114 | ut_assert_nextlinen("---"); |
| 115 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 116 | ut_assert_console_end(); |
| 117 | |
| 118 | ut_assertok(run_command("bootflow list", 0)); |
| 119 | ut_assert_nextline("Showing all bootflows"); |
| 120 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 121 | ut_assert_nextlinen("---"); |
| 122 | ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 123 | ut_assert_nextlinen("---"); |
| 124 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 125 | ut_assert_console_end(); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 130 | |
| 131 | /* Check 'bootflow scan -e' */ |
| 132 | static int bootflow_cmd_scan_e(struct unit_test_state *uts) |
| 133 | { |
| 134 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 135 | |
| 136 | console_record_reset_enable(); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 137 | ut_assertok(run_command("bootflow scan -aleG", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 138 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 139 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 140 | ut_assert_nextlinen("---"); |
| 141 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 142 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 143 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 144 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 145 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 146 | |
| 147 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 148 | ut_assert_nextline(" 2 syslinux media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 149 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 150 | ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole <NULL>"); |
| 151 | ut_assert_nextline(" ** No partition found, err=-2"); |
| 152 | ut_assert_nextline(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 153 | ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 efi/boot/bootsbox.efi"); |
| 154 | |
| 155 | ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); |
| 156 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 157 | ut_assert_nextline(" ** No partition found, err=-93"); |
| 158 | ut_assert_nextline("No more bootdevs"); |
| 159 | ut_assert_nextlinen("---"); |
| 160 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 161 | ut_assert_console_end(); |
| 162 | |
| 163 | ut_assertok(run_command("bootflow list", 0)); |
| 164 | ut_assert_nextline("Showing all bootflows"); |
| 165 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 166 | ut_assert_nextlinen("---"); |
| 167 | ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 168 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>"); |
| 169 | ut_assert_skip_to_line(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 170 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>"); |
| 171 | ut_assert_nextlinen("---"); |
| 172 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 173 | ut_assert_console_end(); |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 178 | |
| 179 | /* Check 'bootflow info' */ |
| 180 | static int bootflow_cmd_info(struct unit_test_state *uts) |
| 181 | { |
| 182 | console_record_reset_enable(); |
| 183 | ut_assertok(run_command("bootdev select 1", 0)); |
| 184 | ut_assert_console_end(); |
| 185 | ut_assertok(run_command("bootflow scan", 0)); |
| 186 | ut_assert_console_end(); |
| 187 | ut_assertok(run_command("bootflow select 0", 0)); |
| 188 | ut_assert_console_end(); |
| 189 | ut_assertok(run_command("bootflow info", 0)); |
| 190 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 191 | ut_assert_nextline("Device: mmc1.bootdev"); |
| 192 | ut_assert_nextline("Block dev: mmc1.blk"); |
| 193 | ut_assert_nextline("Method: syslinux"); |
| 194 | ut_assert_nextline("State: ready"); |
| 195 | ut_assert_nextline("Partition: 1"); |
| 196 | ut_assert_nextline("Subdir: (none)"); |
| 197 | ut_assert_nextline("Filename: /extlinux/extlinux.conf"); |
| 198 | ut_assert_nextlinen("Buffer: "); |
| 199 | ut_assert_nextline("Size: 253 (595 bytes)"); |
Simon Glass | 72b7b19 | 2023-01-06 08:52:33 -0600 | [diff] [blame] | 200 | ut_assert_nextline("OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)"); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 201 | ut_assert_nextline("Logo: (none)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 202 | ut_assert_nextline("Error: 0"); |
| 203 | ut_assert_console_end(); |
| 204 | |
| 205 | ut_assertok(run_command("bootflow info -d", 0)); |
| 206 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 207 | ut_assert_skip_to_line("Error: 0"); |
| 208 | ut_assert_nextline("Contents:"); |
| 209 | ut_assert_nextline("%s", ""); |
| 210 | ut_assert_nextline("# extlinux.conf generated by appliance-creator"); |
| 211 | ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img"); |
| 212 | ut_assert_console_end(); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 217 | |
| 218 | /* Check 'bootflow scan -b' to boot the first available bootdev */ |
| 219 | static int bootflow_scan_boot(struct unit_test_state *uts) |
| 220 | { |
| 221 | console_record_reset_enable(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 222 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 223 | ut_assertok(run_command("bootflow scan -b", 0)); |
| 224 | ut_assert_nextline( |
| 225 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 226 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 227 | |
| 228 | /* |
| 229 | * We expect it to get through to boot although sandbox always returns |
| 230 | * -EFAULT as it cannot actually boot the kernel |
| 231 | */ |
| 232 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 233 | ut_assert_nextline("Boot failed (err=-14)"); |
| 234 | ut_assert_console_end(); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 239 | |
| 240 | /* Check iterating through available bootflows */ |
| 241 | static int bootflow_iter(struct unit_test_state *uts) |
| 242 | { |
| 243 | struct bootflow_iter iter; |
| 244 | struct bootflow bflow; |
| 245 | |
| 246 | bootstd_clear_glob(); |
| 247 | |
| 248 | /* The first device is mmc2.bootdev which has no media */ |
| 249 | ut_asserteq(-EPROTONOSUPPORT, |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 250 | bootflow_scan_first(&iter, BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 251 | ut_asserteq(2, iter.num_methods); |
| 252 | ut_asserteq(0, iter.cur_method); |
| 253 | ut_asserteq(0, iter.part); |
| 254 | ut_asserteq(0, iter.max_part); |
| 255 | ut_asserteq_str("syslinux", iter.method->name); |
| 256 | ut_asserteq(0, bflow.err); |
| 257 | |
| 258 | /* |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 259 | * This shows MEDIA even though there is none, since in |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 260 | * bootdev_find_in_blk() we call part_get_info() which returns |
| 261 | * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would |
| 262 | * know. |
| 263 | */ |
| 264 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 265 | |
| 266 | ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow)); |
| 267 | ut_asserteq(2, iter.num_methods); |
| 268 | ut_asserteq(1, iter.cur_method); |
| 269 | ut_asserteq(0, iter.part); |
| 270 | ut_asserteq(0, iter.max_part); |
| 271 | ut_asserteq_str("efi", iter.method->name); |
| 272 | ut_asserteq(0, bflow.err); |
| 273 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 274 | bootflow_free(&bflow); |
| 275 | |
| 276 | /* The next device is mmc1.bootdev - at first we use the whole device */ |
| 277 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 278 | ut_asserteq(2, iter.num_methods); |
| 279 | ut_asserteq(0, iter.cur_method); |
| 280 | ut_asserteq(0, iter.part); |
| 281 | ut_asserteq(0x1e, iter.max_part); |
| 282 | ut_asserteq_str("syslinux", iter.method->name); |
| 283 | ut_asserteq(0, bflow.err); |
| 284 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 285 | bootflow_free(&bflow); |
| 286 | |
| 287 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 288 | ut_asserteq(2, iter.num_methods); |
| 289 | ut_asserteq(1, iter.cur_method); |
| 290 | ut_asserteq(0, iter.part); |
| 291 | ut_asserteq(0x1e, iter.max_part); |
| 292 | ut_asserteq_str("efi", iter.method->name); |
| 293 | ut_asserteq(0, bflow.err); |
| 294 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 295 | bootflow_free(&bflow); |
| 296 | |
| 297 | /* Then more to partition 1 where we find something */ |
| 298 | ut_assertok(bootflow_scan_next(&iter, &bflow)); |
| 299 | ut_asserteq(2, iter.num_methods); |
| 300 | ut_asserteq(0, iter.cur_method); |
| 301 | ut_asserteq(1, iter.part); |
| 302 | ut_asserteq(0x1e, iter.max_part); |
| 303 | ut_asserteq_str("syslinux", iter.method->name); |
| 304 | ut_asserteq(0, bflow.err); |
| 305 | ut_asserteq(BOOTFLOWST_READY, bflow.state); |
| 306 | bootflow_free(&bflow); |
| 307 | |
| 308 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 309 | ut_asserteq(2, iter.num_methods); |
| 310 | ut_asserteq(1, iter.cur_method); |
| 311 | ut_asserteq(1, iter.part); |
| 312 | ut_asserteq(0x1e, iter.max_part); |
| 313 | ut_asserteq_str("efi", iter.method->name); |
| 314 | ut_asserteq(0, bflow.err); |
| 315 | ut_asserteq(BOOTFLOWST_FS, bflow.state); |
| 316 | bootflow_free(&bflow); |
| 317 | |
| 318 | /* Then more to partition 2 which doesn't exist */ |
| 319 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 320 | ut_asserteq(2, iter.num_methods); |
| 321 | ut_asserteq(0, iter.cur_method); |
| 322 | ut_asserteq(2, iter.part); |
| 323 | ut_asserteq(0x1e, iter.max_part); |
| 324 | ut_asserteq_str("syslinux", iter.method->name); |
| 325 | ut_asserteq(0, bflow.err); |
| 326 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 327 | bootflow_free(&bflow); |
| 328 | |
| 329 | bootflow_iter_uninit(&iter); |
| 330 | |
| 331 | ut_assert_console_end(); |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 336 | |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 337 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 338 | /* Check using the system bootdev */ |
| 339 | static int bootflow_system(struct unit_test_state *uts) |
| 340 | { |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 341 | struct udevice *dev; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 342 | |
Simon Glass | 49efb06 | 2022-10-11 09:47:20 -0600 | [diff] [blame] | 343 | if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 344 | return -EAGAIN; |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 345 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTMETH, "efi_mgr", |
| 346 | &dev)); |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 347 | sandbox_set_fake_efi_mgr_dev(dev, true); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 348 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 349 | /* We should get a single 'bootmgr' method right at the end */ |
| 350 | bootstd_clear_glob(); |
| 351 | console_record_reset_enable(); |
| 352 | ut_assertok(run_command("bootflow scan -l", 0)); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 353 | ut_assert_skip_to_line( |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 354 | " 0 efi_mgr ready (none) 0 <NULL> <NULL>"); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 355 | ut_assert_skip_to_line("No more bootdevs"); |
Simon Glass | 9f4440d | 2022-07-30 15:52:29 -0600 | [diff] [blame] | 356 | ut_assert_skip_to_line("(5 bootflows, 5 valid)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 357 | ut_assert_console_end(); |
| 358 | |
| 359 | return 0; |
| 360 | } |
Simon Glass | 771a244 | 2022-07-30 15:52:28 -0600 | [diff] [blame] | 361 | BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA | |
| 362 | UT_TESTF_SCAN_FDT); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 363 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 364 | |
| 365 | /* Check disabling a bootmethod if it requests it */ |
| 366 | static int bootflow_iter_disable(struct unit_test_state *uts) |
| 367 | { |
| 368 | struct udevice *bootstd, *dev; |
| 369 | struct bootflow_iter iter; |
| 370 | struct bootflow bflow; |
| 371 | int i; |
| 372 | |
| 373 | /* Add the EFI bootmgr driver */ |
| 374 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 375 | ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox", |
| 376 | &dev)); |
| 377 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 378 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 379 | |
| 380 | bootstd_clear_glob(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 381 | console_record_reset_enable(); |
| 382 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 383 | ut_assertok(run_command("bootflow scan -lb", 0)); |
| 384 | |
| 385 | /* Try to boot the bootmgr flow, which will fail */ |
| 386 | console_record_reset_enable(); |
| 387 | ut_assertok(bootflow_scan_first(&iter, 0, &bflow)); |
| 388 | ut_asserteq(3, iter.num_methods); |
| 389 | ut_asserteq_str("sandbox", iter.method->name); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 390 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 391 | ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); |
| 392 | |
| 393 | ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried"); |
| 394 | ut_assert_console_end(); |
| 395 | |
| 396 | /* Check that the sandbox bootmeth has been removed */ |
| 397 | ut_asserteq(2, iter.num_methods); |
| 398 | for (i = 0; i < iter.num_methods; i++) |
| 399 | ut_assert(strcmp("sandbox", iter.method_order[i]->name)); |
| 400 | |
| 401 | return 0; |
| 402 | } |
| 403 | BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 404 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 405 | /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */ |
| 406 | static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts) |
| 407 | { |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 408 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 409 | return -EAGAIN; |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 410 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 411 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 412 | |
| 413 | /* |
| 414 | * Make sure that the -G flag makes the scan fail, since this is not |
| 415 | * supported when an ordering is provided |
| 416 | */ |
| 417 | console_record_reset_enable(); |
| 418 | ut_assertok(bootmeth_set_order("efi firmware0")); |
| 419 | ut_assertok(run_command("bootflow scan -lG", 0)); |
| 420 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 421 | ut_assert_nextline( |
| 422 | "Seq Method State Uclass Part Name Filename"); |
| 423 | ut_assert_nextlinen("---"); |
| 424 | ut_assert_nextlinen("---"); |
| 425 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 426 | ut_assert_console_end(); |
| 427 | |
| 428 | ut_assertok(run_command("bootflow scan -l", 0)); |
| 429 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 430 | ut_assert_nextline( |
| 431 | "Seq Method State Uclass Part Name Filename"); |
| 432 | ut_assert_nextlinen("---"); |
| 433 | ut_assert_nextline("Scanning global bootmeth 'firmware0':"); |
| 434 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 435 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 436 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 437 | ut_assert_nextline("No more bootdevs"); |
| 438 | ut_assert_nextlinen("---"); |
| 439 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 440 | ut_assert_console_end(); |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
| 445 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 446 | /* Check 'bootflow boot' to boot a selected bootflow */ |
| 447 | static int bootflow_cmd_boot(struct unit_test_state *uts) |
| 448 | { |
| 449 | console_record_reset_enable(); |
| 450 | ut_assertok(run_command("bootdev select 1", 0)); |
| 451 | ut_assert_console_end(); |
| 452 | ut_assertok(run_command("bootflow scan", 0)); |
| 453 | ut_assert_console_end(); |
| 454 | ut_assertok(run_command("bootflow select 0", 0)); |
| 455 | ut_assert_console_end(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 456 | |
| 457 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 458 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 459 | ut_assert_nextline( |
| 460 | "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux"); |
| 461 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 462 | |
| 463 | /* |
| 464 | * We expect it to get through to boot although sandbox always returns |
| 465 | * -EFAULT as it cannot actually boot the kernel |
| 466 | */ |
| 467 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 468 | ut_assert_nextline("Boot failed (err=-14)"); |
| 469 | ut_assert_console_end(); |
| 470 | |
| 471 | return 0; |
| 472 | } |
| 473 | BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 474 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame^] | 475 | /** |
| 476 | * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian |
| 477 | * |
| 478 | * @uts: Unit test state |
| 479 | * Returns 0 on success, -ve on failure |
| 480 | */ |
| 481 | static int prep_mmc4_bootdev(struct unit_test_state *uts) |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 482 | { |
| 483 | static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL}; |
| 484 | struct udevice *dev, *bootstd; |
| 485 | struct bootstd_priv *std; |
| 486 | const char **old_order; |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 487 | ofnode node; |
| 488 | |
| 489 | /* Enable the mmc4 node since we need a second bootflow */ |
| 490 | node = ofnode_path("/mmc4"); |
| 491 | ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false)); |
| 492 | |
| 493 | /* Enable the script bootmeth too */ |
| 494 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 495 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script), |
| 496 | "bootmeth_script", 0, ofnode_null(), &dev)); |
| 497 | |
| 498 | /* Change the order to include mmc4 */ |
| 499 | std = dev_get_priv(bootstd); |
| 500 | old_order = std->bootdev_order; |
| 501 | std->bootdev_order = order; |
| 502 | |
| 503 | console_record_reset_enable(); |
| 504 | ut_assertok(run_command("bootflow scan", 0)); |
| 505 | ut_assert_console_end(); |
| 506 | |
| 507 | /* Restore the order used by the device tree */ |
| 508 | std->bootdev_order = old_order; |
| 509 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame^] | 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | /* Check 'bootflow menu' to select a bootflow */ |
| 514 | static int bootflow_cmd_menu(struct unit_test_state *uts) |
| 515 | { |
| 516 | char prev[3]; |
| 517 | |
| 518 | ut_assertok(prep_mmc4_bootdev(uts)); |
| 519 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 520 | /* Add keypresses to move to and select the second one in the list */ |
| 521 | prev[0] = CTL_CH('n'); |
| 522 | prev[1] = '\r'; |
| 523 | prev[2] = '\0'; |
| 524 | ut_asserteq(2, console_in_puts(prev)); |
| 525 | |
| 526 | ut_assertok(run_command("bootflow menu", 0)); |
| 527 | ut_assert_nextline("Selected: Armbian"); |
| 528 | ut_assert_console_end(); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame^] | 533 | |
| 534 | /** |
| 535 | * check_font() - Check that the font size for an item matches expectations |
| 536 | * |
| 537 | * @uts: Unit test state |
| 538 | * @scn: Scene containing the text object |
| 539 | * @id: ID of the text object |
| 540 | * Returns 0 on success, -ve on failure |
| 541 | */ |
| 542 | static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, |
| 543 | int font_size) |
| 544 | { |
| 545 | struct scene_obj_txt *txt; |
| 546 | |
| 547 | txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); |
| 548 | ut_assertnonnull(txt); |
| 549 | |
| 550 | ut_asserteq(font_size, txt->font_size); |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /* Check themes work with a bootflow menu */ |
| 556 | static int bootflow_menu_theme(struct unit_test_state *uts) |
| 557 | { |
| 558 | const int font_size = 30; |
| 559 | struct scene *scn; |
| 560 | struct expo *exp; |
| 561 | ofnode node; |
| 562 | int i; |
| 563 | |
| 564 | ut_assertok(prep_mmc4_bootdev(uts)); |
| 565 | |
| 566 | ut_assertok(bootflow_menu_new(&exp)); |
| 567 | node = ofnode_path("/bootstd/theme"); |
| 568 | ut_assert(ofnode_valid(node)); |
| 569 | ut_assertok(bootflow_menu_apply_theme(exp, node)); |
| 570 | |
| 571 | scn = expo_lookup_scene_id(exp, MAIN); |
| 572 | ut_assertnonnull(scn); |
| 573 | |
| 574 | /* |
| 575 | * Check that the txt objects have the correct font size from the |
| 576 | * device tree node: bootstd/theme |
| 577 | * |
| 578 | * Check both menu items, since there are two bootflows |
| 579 | */ |
| 580 | ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); |
| 581 | ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); |
| 582 | for (i = 0; i < 2; i++) { |
| 583 | ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); |
| 584 | ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); |
| 585 | ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size)); |
| 586 | } |
| 587 | |
| 588 | expo_destroy(exp); |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |