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 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 9 | #include <bootdev.h> |
| 10 | #include <bootflow.h> |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 11 | #include <bootmeth.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 12 | #include <bootstd.h> |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 13 | #include <cli.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 14 | #include <dm.h> |
Heinrich Schuchardt | 4226d9d | 2024-04-03 23:39:48 +0200 | [diff] [blame] | 15 | #include <efi_default_filename.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 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 30 | extern U_BOOT_DRIVER(bootmeth_android); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 31 | extern U_BOOT_DRIVER(bootmeth_cros); |
Simon Glass | 2f27e47 | 2023-08-19 16:49:35 -0600 | [diff] [blame] | 32 | extern U_BOOT_DRIVER(bootmeth_2script); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 33 | |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 34 | static int inject_response(struct unit_test_state *uts) |
| 35 | { |
| 36 | /* |
| 37 | * The image being booted presents a menu of options: |
| 38 | * |
| 39 | * Fedora-Workstation-armhfp-31-1.9 Boot Options. |
| 40 | * 1: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) |
| 41 | * Enter choice: |
| 42 | * |
| 43 | * Provide input for this, to avoid waiting two seconds for a timeout. |
| 44 | */ |
| 45 | ut_asserteq(2, console_in_puts("1\n")); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 50 | /* Check 'bootflow scan/list' commands */ |
| 51 | static int bootflow_cmd(struct unit_test_state *uts) |
| 52 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 53 | ut_assertok(run_command("bootdev select 1", 0)); |
| 54 | ut_assert_console_end(); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 55 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 56 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 57 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 58 | ut_assert_nextlinen("---"); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 59 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 60 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 61 | ut_assert_nextline(" 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 62 | ut_assert_nextline("No more bootdevs"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 63 | ut_assert_nextlinen("---"); |
| 64 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 65 | ut_assert_console_end(); |
| 66 | |
| 67 | ut_assertok(run_command("bootflow list", 0)); |
| 68 | ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'"); |
| 69 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 70 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 71 | ut_assert_nextline(" 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 72 | ut_assert_nextlinen("---"); |
| 73 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 74 | ut_assert_console_end(); |
| 75 | |
| 76 | return 0; |
| 77 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 78 | BOOTSTD_TEST(bootflow_cmd, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 79 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 80 | /* Check 'bootflow scan' with a label / seq */ |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 81 | static int bootflow_cmd_label(struct unit_test_state *uts) |
| 82 | { |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 83 | test_set_eth_enable(false); |
| 84 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 85 | ut_assertok(run_command("bootflow scan -lH mmc1", 0)); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 86 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
Simon Glass | b255efc | 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 | 484e407 | 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 | b255efc | 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 | 484e407 | 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 | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 117 | ut_assertok(run_command("bootflow scan -lH 0", 0)); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 118 | ut_assert_nextline("Scanning for bootflows with label '0'"); |
Simon Glass | b255efc | 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 | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 124 | BOOTSTD_TEST(bootflow_cmd_label, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV | |
| 125 | UTF_CONSOLE); |
Simon Glass | b255efc | 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 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 132 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 133 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 134 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 135 | ut_assert_nextlinen("---"); |
| 136 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 137 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 138 | ut_assert_nextline(" 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 139 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 140 | ut_assert_nextline("No more bootdevs"); |
| 141 | ut_assert_nextlinen("---"); |
| 142 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 143 | ut_assert_console_end(); |
| 144 | |
| 145 | ut_assertok(run_command("bootflow list", 0)); |
| 146 | ut_assert_nextline("Showing all bootflows"); |
| 147 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 148 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 149 | ut_assert_nextline(" 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 150 | ut_assert_nextlinen("---"); |
| 151 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 152 | ut_assert_console_end(); |
| 153 | |
| 154 | return 0; |
| 155 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 156 | BOOTSTD_TEST(bootflow_cmd_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 157 | |
| 158 | /* Check 'bootflow scan -e' */ |
| 159 | static int bootflow_cmd_scan_e(struct unit_test_state *uts) |
| 160 | { |
| 161 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 162 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 163 | ut_assertok(run_command("bootflow scan -aleGH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 164 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 165 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 166 | ut_assert_nextlinen("---"); |
| 167 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 168 | ut_assert_nextline(" 0 extlinux media mmc 0 mmc2.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 169 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 170 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 171 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 172 | |
| 173 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 174 | ut_assert_nextline(" 2 extlinux media mmc 0 mmc1.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 175 | ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 176 | ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 177 | ut_assert_nextline(" ** No partition found, err=-2: No such file or directory"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 178 | ut_assert_nextline(" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Heinrich Schuchardt | 4226d9d | 2024-04-03 23:39:48 +0200 | [diff] [blame] | 179 | ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/" |
| 180 | BOOTEFI_NAME); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 181 | |
| 182 | ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 183 | ut_assert_skip_to_line( |
| 184 | " 3f efi media mmc 0 mmc0.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 185 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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("---"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 195 | ut_assert_nextline(" 0 extlinux media mmc 0 mmc2.bootdev.whole "); |
| 196 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); |
| 197 | ut_assert_skip_to_line( |
| 198 | " 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 199 | ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole "); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 200 | ut_assert_nextlinen("---"); |
| 201 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 202 | ut_assert_console_end(); |
| 203 | |
| 204 | return 0; |
| 205 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 206 | BOOTSTD_TEST(bootflow_cmd_scan_e, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 207 | |
| 208 | /* Check 'bootflow info' */ |
| 209 | static int bootflow_cmd_info(struct unit_test_state *uts) |
| 210 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 221 | ut_assert_nextline("Method: extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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 | 72b7b19 | 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 | 3392752 | 2023-07-12 09:04:34 -0600 | [diff] [blame] | 229 | ut_assert_nextline("Cmdline: (none)"); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 230 | ut_assert_nextline("Logo: (none)"); |
Simon Glass | 7b8c634 | 2023-01-17 10:47:56 -0700 | [diff] [blame] | 231 | ut_assert_nextline("FDT: <NULL>"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 232 | ut_assert_nextline("Error: 0"); |
| 233 | ut_assert_console_end(); |
| 234 | |
| 235 | ut_assertok(run_command("bootflow info -d", 0)); |
| 236 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 237 | ut_assert_skip_to_line("Error: 0"); |
| 238 | ut_assert_nextline("Contents:"); |
| 239 | ut_assert_nextline("%s", ""); |
| 240 | ut_assert_nextline("# extlinux.conf generated by appliance-creator"); |
| 241 | ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img"); |
| 242 | ut_assert_console_end(); |
| 243 | |
| 244 | return 0; |
| 245 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 246 | BOOTSTD_TEST(bootflow_cmd_info, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 247 | |
| 248 | /* Check 'bootflow scan -b' to boot the first available bootdev */ |
| 249 | static int bootflow_scan_boot(struct unit_test_state *uts) |
| 250 | { |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 251 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 252 | ut_assertok(run_command("bootflow scan -b", 0)); |
| 253 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 254 | "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 267 | BOOTSTD_TEST(bootflow_scan_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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 | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 279 | bootflow_scan_first(NULL, NULL, &iter, |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 280 | BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); |
Simon Glass | b255efc | 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); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 285 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 286 | ut_asserteq(0, bflow.err); |
| 287 | |
| 288 | /* |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 289 | * This shows MEDIA even though there is none, since in |
Simon Glass | b255efc | 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); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 312 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 333 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 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 | f5e2df0 | 2023-01-17 10:47:41 -0700 | [diff] [blame] | 348 | /* Then more to partition 2 which exists but is not bootable */ |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 349 | ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | b255efc | 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); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 354 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 355 | ut_asserteq(0, bflow.err); |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 356 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
Simon Glass | b255efc | 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 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 365 | BOOTSTD_TEST(bootflow_iter, UTF_DM | UTF_SCAN_FDT); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 366 | |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 367 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) |
Simon Glass | b255efc | 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 | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 371 | struct udevice *bootstd, *dev; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 372 | |
AKASHI Takahiro | e3e542d | 2024-01-17 13:39:42 +0900 | [diff] [blame] | 373 | if (!IS_ENABLED(CONFIG_EFI_BOOTMGR)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 374 | return -EAGAIN; |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 375 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
Heinrich Schuchardt | dc1f006 | 2024-04-03 20:34:15 +0200 | [diff] [blame] | 376 | ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_3efi_mgr), |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 377 | "efi_mgr", 0, ofnode_null(), &dev)); |
| 378 | ut_assertok(device_probe(dev)); |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 379 | sandbox_set_fake_efi_mgr_dev(dev, true); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 380 | |
Simon Glass | b255efc | 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(); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 383 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 384 | ut_assert_skip_to_line( |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 385 | " 0 efi_mgr ready (none) 0 <NULL> "); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 386 | ut_assert_skip_to_line("No more bootdevs"); |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 387 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 388 | ut_assert_console_end(); |
| 389 | |
| 390 | return 0; |
| 391 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 392 | BOOTSTD_TEST(bootflow_system, UTF_DM | UTF_SCAN_PDATA | UTF_SCAN_FDT | |
| 393 | UTF_CONSOLE); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 394 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 395 | |
| 396 | /* Check disabling a bootmethod if it requests it */ |
| 397 | static int bootflow_iter_disable(struct unit_test_state *uts) |
| 398 | { |
| 399 | struct udevice *bootstd, *dev; |
| 400 | struct bootflow_iter iter; |
| 401 | struct bootflow bflow; |
| 402 | int i; |
| 403 | |
| 404 | /* Add the EFI bootmgr driver */ |
| 405 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 406 | ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox", |
| 407 | &dev)); |
| 408 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 409 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 410 | |
| 411 | bootstd_clear_glob(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 412 | ut_assertok(inject_response(uts)); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 413 | ut_assertok(run_command("bootflow scan -lbH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 414 | |
| 415 | /* Try to boot the bootmgr flow, which will fail */ |
| 416 | console_record_reset_enable(); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 417 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 418 | ut_asserteq(3, iter.num_methods); |
| 419 | ut_asserteq_str("sandbox", iter.method->name); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 420 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 421 | ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); |
| 422 | |
| 423 | ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried"); |
| 424 | ut_assert_console_end(); |
| 425 | |
| 426 | /* Check that the sandbox bootmeth has been removed */ |
| 427 | ut_asserteq(2, iter.num_methods); |
| 428 | for (i = 0; i < iter.num_methods; i++) |
| 429 | ut_assert(strcmp("sandbox", iter.method_order[i]->name)); |
| 430 | |
| 431 | return 0; |
| 432 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 433 | BOOTSTD_TEST(bootflow_iter_disable, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 434 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 435 | /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */ |
| 436 | static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts) |
| 437 | { |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 438 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 439 | return -EAGAIN; |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 440 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 441 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 442 | |
| 443 | /* |
| 444 | * Make sure that the -G flag makes the scan fail, since this is not |
| 445 | * supported when an ordering is provided |
| 446 | */ |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 447 | ut_assertok(bootmeth_set_order("efi firmware0")); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 448 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 449 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 450 | ut_assert_nextline( |
| 451 | "Seq Method State Uclass Part Name Filename"); |
| 452 | ut_assert_nextlinen("---"); |
| 453 | ut_assert_nextlinen("---"); |
| 454 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 455 | ut_assert_console_end(); |
| 456 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 457 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 458 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 459 | ut_assert_nextline( |
| 460 | "Seq Method State Uclass Part Name Filename"); |
| 461 | ut_assert_nextlinen("---"); |
| 462 | ut_assert_nextline("Scanning global bootmeth 'firmware0':"); |
| 463 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 464 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 465 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 466 | ut_assert_nextline("No more bootdevs"); |
| 467 | ut_assert_nextlinen("---"); |
| 468 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 469 | ut_assert_console_end(); |
| 470 | |
| 471 | return 0; |
| 472 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 473 | BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UTF_DM | UTF_SCAN_FDT | |
| 474 | UTF_CONSOLE); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 475 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 476 | /* Check 'bootflow boot' to boot a selected bootflow */ |
| 477 | static int bootflow_cmd_boot(struct unit_test_state *uts) |
| 478 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 479 | ut_assertok(run_command("bootdev select 1", 0)); |
| 480 | ut_assert_console_end(); |
| 481 | ut_assertok(run_command("bootflow scan", 0)); |
| 482 | ut_assert_console_end(); |
| 483 | ut_assertok(run_command("bootflow select 0", 0)); |
| 484 | ut_assert_console_end(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 485 | |
| 486 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 487 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 488 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 489 | "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 490 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 491 | |
| 492 | /* |
| 493 | * We expect it to get through to boot although sandbox always returns |
| 494 | * -EFAULT as it cannot actually boot the kernel |
| 495 | */ |
| 496 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 497 | ut_assert_nextline("Boot failed (err=-14)"); |
| 498 | ut_assert_console_end(); |
| 499 | |
| 500 | return 0; |
| 501 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 502 | BOOTSTD_TEST(bootflow_cmd_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 503 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 504 | /** |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 505 | * prep_mmc_bootdev() - Set up an mmc bootdev so we can access other distros |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 506 | * |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 507 | * After calling this function, set std->bootdev_order to *@old_orderp to |
| 508 | * restore normal operation of bootstd (i.e. with the original bootdev order) |
| 509 | * |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 510 | * @uts: Unit test state |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 511 | * @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid |
| 512 | * in the caller until |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 513 | * @bind_cros: true to bind the ChromiumOS and Android bootmeths |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 514 | * @old_orderp: Returns the original bootdev order, which must be restored |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 515 | * Returns 0 on success, -ve on failure |
| 516 | */ |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 517 | static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev, |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 518 | bool bind_cros_android, const char ***old_orderp) |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 519 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 520 | static const char *order[] = {"mmc2", "mmc1", NULL, NULL}; |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 521 | struct udevice *dev, *bootstd; |
| 522 | struct bootstd_priv *std; |
| 523 | const char **old_order; |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 524 | ofnode root, node; |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 525 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 526 | order[2] = mmc_dev; |
| 527 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 528 | /* Enable the mmc4 node since we need a second bootflow */ |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 529 | root = oftree_root(oftree_default()); |
| 530 | node = ofnode_find_subnode(root, mmc_dev); |
| 531 | ut_assert(ofnode_valid(node)); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 532 | ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false)); |
| 533 | |
| 534 | /* Enable the script bootmeth too */ |
| 535 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
Simon Glass | 2f27e47 | 2023-08-19 16:49:35 -0600 | [diff] [blame] | 536 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_2script), |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 537 | "bootmeth_script", 0, ofnode_null(), &dev)); |
| 538 | |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 539 | /* Enable the cros bootmeth if needed */ |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 540 | if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) { |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 541 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 542 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros), |
| 543 | "cros", 0, ofnode_null(), &dev)); |
| 544 | } |
| 545 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 546 | /* Enable the android bootmeths if needed */ |
| 547 | if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) { |
| 548 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 549 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_android), |
| 550 | "android", 0, ofnode_null(), &dev)); |
| 551 | } |
| 552 | |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 553 | /* Change the order to include the device */ |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 554 | std = dev_get_priv(bootstd); |
| 555 | old_order = std->bootdev_order; |
| 556 | std->bootdev_order = order; |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 557 | *old_orderp = old_order; |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * scan_mmc_bootdev() - Set up an mmc bootdev so we can access other distros |
| 564 | * |
| 565 | * @uts: Unit test state |
| 566 | * @mmc_dev: MMC device to use, e.g. "mmc4" |
| 567 | * @bind_cros: true to bind the ChromiumOS bootmeth |
| 568 | * Returns 0 on success, -ve on failure |
| 569 | */ |
| 570 | static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev, |
| 571 | bool bind_cros) |
| 572 | { |
| 573 | struct bootstd_priv *std; |
| 574 | struct udevice *bootstd; |
| 575 | const char **old_order; |
| 576 | |
| 577 | ut_assertok(prep_mmc_bootdev(uts, mmc_dev, bind_cros, &old_order)); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 578 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 579 | ut_assertok(run_command("bootflow scan", 0)); |
| 580 | ut_assert_console_end(); |
| 581 | |
| 582 | /* Restore the order used by the device tree */ |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 583 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 584 | std = dev_get_priv(bootstd); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 585 | std->bootdev_order = old_order; |
| 586 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 587 | return 0; |
| 588 | } |
| 589 | |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 590 | /** |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 591 | * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other |
| 592 | * distros. Android bootflow might print "ANDROID:*" while scanning |
| 593 | * |
| 594 | * @uts: Unit test state |
| 595 | * @mmc_dev: MMC device to use, e.g. "mmc4" |
| 596 | * Returns 0 on success, -ve on failure |
| 597 | */ |
| 598 | static int scan_mmc_android_bootdev(struct unit_test_state *uts, const char *mmc_dev) |
| 599 | { |
| 600 | struct bootstd_priv *std; |
| 601 | struct udevice *bootstd; |
| 602 | const char **old_order; |
| 603 | |
| 604 | ut_assertok(prep_mmc_bootdev(uts, mmc_dev, true, &old_order)); |
| 605 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 606 | ut_assertok(run_command("bootflow scan", 0)); |
| 607 | /* Android bootflow might print one or two 'ANDROID:*' logs */ |
| 608 | ut_check_skipline(uts); |
| 609 | ut_check_skipline(uts); |
| 610 | ut_assert_console_end(); |
| 611 | |
| 612 | /* Restore the order used by the device tree */ |
| 613 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 614 | std = dev_get_priv(bootstd); |
| 615 | std->bootdev_order = old_order; |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | /** |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 621 | * scan_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 622 | * |
| 623 | * @uts: Unit test state |
| 624 | * Returns 0 on success, -ve on failure |
| 625 | */ |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 626 | static int scan_mmc4_bootdev(struct unit_test_state *uts) |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 627 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 628 | ut_assertok(scan_mmc_bootdev(uts, "mmc4", false)); |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 633 | /* Check 'bootflow menu' to select a bootflow */ |
| 634 | static int bootflow_cmd_menu(struct unit_test_state *uts) |
| 635 | { |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 636 | struct bootstd_priv *std; |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 637 | char prev[3]; |
| 638 | |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 639 | /* get access to the current bootflow */ |
| 640 | ut_assertok(bootstd_get_priv(&std)); |
| 641 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 642 | ut_assertok(scan_mmc4_bootdev(uts)); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 643 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 644 | /* Add keypresses to move to and select the second one in the list */ |
| 645 | prev[0] = CTL_CH('n'); |
| 646 | prev[1] = '\r'; |
| 647 | prev[2] = '\0'; |
| 648 | ut_asserteq(2, console_in_puts(prev)); |
| 649 | |
| 650 | ut_assertok(run_command("bootflow menu", 0)); |
| 651 | ut_assert_nextline("Selected: Armbian"); |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 652 | ut_assertnonnull(std->cur_bootflow); |
| 653 | ut_assert_console_end(); |
| 654 | |
| 655 | /* Check not selecting anything */ |
| 656 | prev[0] = '\e'; |
| 657 | prev[1] = '\0'; |
| 658 | ut_asserteq(1, console_in_puts(prev)); |
| 659 | |
| 660 | ut_asserteq(1, run_command("bootflow menu", 0)); |
| 661 | ut_assertnull(std->cur_bootflow); |
| 662 | ut_assert_nextline("Nothing chosen"); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 663 | ut_assert_console_end(); |
| 664 | |
| 665 | return 0; |
| 666 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 667 | BOOTSTD_TEST(bootflow_cmd_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 668 | |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 669 | /* Check 'bootflow scan -m' to select a bootflow using a menu */ |
| 670 | static int bootflow_scan_menu(struct unit_test_state *uts) |
| 671 | { |
| 672 | struct bootstd_priv *std; |
| 673 | const char **old_order, **new_order; |
| 674 | char prev[3]; |
| 675 | |
| 676 | /* get access to the current bootflow */ |
| 677 | ut_assertok(bootstd_get_priv(&std)); |
| 678 | |
| 679 | ut_assertok(prep_mmc_bootdev(uts, "mmc4", false, &old_order)); |
| 680 | |
| 681 | /* Add keypresses to move to and select the second one in the list */ |
| 682 | prev[0] = CTL_CH('n'); |
| 683 | prev[1] = '\r'; |
| 684 | prev[2] = '\0'; |
| 685 | ut_asserteq(2, console_in_puts(prev)); |
| 686 | |
| 687 | ut_assertok(run_command("bootflow scan -lm", 0)); |
| 688 | new_order = std->bootdev_order; |
| 689 | std->bootdev_order = old_order; |
| 690 | |
| 691 | ut_assert_skip_to_line("No more bootdevs"); |
| 692 | ut_assert_nextlinen("--"); |
| 693 | ut_assert_nextline("(2 bootflows, 2 valid)"); |
| 694 | |
| 695 | ut_assert_nextline("Selected: Armbian"); |
| 696 | ut_assertnonnull(std->cur_bootflow); |
| 697 | ut_assert_console_end(); |
| 698 | |
| 699 | /* Check not selecting anything */ |
| 700 | prev[0] = '\e'; |
| 701 | prev[1] = '\0'; |
| 702 | ut_asserteq(1, console_in_puts(prev)); |
| 703 | |
| 704 | std->bootdev_order = new_order; /* Blue Monday */ |
| 705 | ut_assertok(run_command("bootflow scan -lm", 0)); |
| 706 | std->bootdev_order = old_order; |
| 707 | |
| 708 | ut_assertnull(std->cur_bootflow); |
| 709 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 710 | ut_assert_nextline("Nothing chosen"); |
| 711 | ut_assert_console_end(); |
| 712 | |
| 713 | return 0; |
| 714 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 715 | BOOTSTD_TEST(bootflow_scan_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 716 | |
| 717 | /* Check 'bootflow scan -mb' to select and boot a bootflow using a menu */ |
| 718 | static int bootflow_scan_menu_boot(struct unit_test_state *uts) |
| 719 | { |
| 720 | struct bootstd_priv *std; |
| 721 | const char **old_order; |
| 722 | char prev[3]; |
| 723 | |
| 724 | /* get access to the current bootflow */ |
| 725 | ut_assertok(bootstd_get_priv(&std)); |
| 726 | |
| 727 | ut_assertok(prep_mmc_bootdev(uts, "mmc4", false, &old_order)); |
| 728 | |
| 729 | /* Add keypresses to move to and select the second one in the list */ |
| 730 | prev[0] = CTL_CH('n'); |
| 731 | prev[1] = '\r'; |
| 732 | prev[2] = '\0'; |
| 733 | ut_asserteq(2, console_in_puts(prev)); |
| 734 | |
| 735 | ut_assertok(run_command("bootflow scan -lmb", 0)); |
| 736 | std->bootdev_order = old_order; |
| 737 | |
| 738 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 739 | |
| 740 | ut_assert_nextline("Selected: Armbian"); |
Francis Laniel | 5b64c45 | 2023-12-22 22:02:35 +0100 | [diff] [blame] | 741 | |
| 742 | if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { |
| 743 | /* |
| 744 | * With old hush, despite booti failing to boot, i.e. returning |
| 745 | * CMD_RET_FAILURE, run_command() returns 0 which leads bootflow_boot(), as |
| 746 | * we are using bootmeth_script here, to return -EFAULT. |
| 747 | */ |
| 748 | ut_assert_skip_to_line("Boot failed (err=-14)"); |
| 749 | } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { |
| 750 | /* |
| 751 | * While with modern one, run_command() propagates CMD_RET_FAILURE returned |
| 752 | * by booti, so we get 1 here. |
| 753 | */ |
| 754 | ut_assert_skip_to_line("Boot failed (err=1)"); |
| 755 | } |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 756 | ut_assertnonnull(std->cur_bootflow); |
| 757 | ut_assert_console_end(); |
| 758 | |
| 759 | return 0; |
| 760 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 761 | BOOTSTD_TEST(bootflow_scan_menu_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 762 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 763 | /* Check searching for a single bootdev using the hunters */ |
| 764 | static int bootflow_cmd_hunt_single(struct unit_test_state *uts) |
| 765 | { |
| 766 | struct bootstd_priv *std; |
| 767 | |
| 768 | /* get access to the used hunters */ |
| 769 | ut_assertok(bootstd_get_priv(&std)); |
| 770 | |
| 771 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 772 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 773 | ut_assertok(run_command("bootflow scan -l mmc1", 0)); |
| 774 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
| 775 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 776 | ut_assert_console_end(); |
| 777 | |
| 778 | /* check that the hunter was used */ |
| 779 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 780 | |
| 781 | return 0; |
| 782 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 783 | BOOTSTD_TEST(bootflow_cmd_hunt_single, UTF_DM | UTF_SCAN_FDT | |
| 784 | UTF_CONSOLE); |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 785 | |
| 786 | /* Check searching for a uclass label using the hunters */ |
| 787 | static int bootflow_cmd_hunt_label(struct unit_test_state *uts) |
| 788 | { |
| 789 | struct bootstd_priv *std; |
| 790 | |
| 791 | /* get access to the used hunters */ |
| 792 | ut_assertok(bootstd_get_priv(&std)); |
| 793 | |
| 794 | test_set_skip_delays(true); |
| 795 | test_set_eth_enable(false); |
| 796 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 797 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 798 | ut_assertok(run_command("bootflow scan -l mmc", 0)); |
| 799 | |
| 800 | /* check that the hunter was used */ |
| 801 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 802 | |
| 803 | /* check that we got the mmc1 bootflow */ |
| 804 | ut_assert_nextline("Scanning for bootflows with label 'mmc'"); |
| 805 | ut_assert_nextlinen("Seq"); |
| 806 | ut_assert_nextlinen("---"); |
| 807 | ut_assert_nextline("Hunting with: simple_bus"); |
| 808 | ut_assert_nextline("Found 2 extension board(s)."); |
| 809 | ut_assert_nextline("Hunting with: mmc"); |
| 810 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 811 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 812 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 813 | " 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 814 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 815 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 816 | ut_assert_console_end(); |
| 817 | |
| 818 | return 0; |
| 819 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 820 | BOOTSTD_TEST(bootflow_cmd_hunt_label, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 821 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 822 | /** |
| 823 | * check_font() - Check that the font size for an item matches expectations |
| 824 | * |
| 825 | * @uts: Unit test state |
| 826 | * @scn: Scene containing the text object |
| 827 | * @id: ID of the text object |
| 828 | * Returns 0 on success, -ve on failure |
| 829 | */ |
| 830 | static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, |
| 831 | int font_size) |
| 832 | { |
| 833 | struct scene_obj_txt *txt; |
| 834 | |
| 835 | txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); |
| 836 | ut_assertnonnull(txt); |
| 837 | |
| 838 | ut_asserteq(font_size, txt->font_size); |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | /* Check themes work with a bootflow menu */ |
| 844 | static int bootflow_menu_theme(struct unit_test_state *uts) |
| 845 | { |
| 846 | const int font_size = 30; |
| 847 | struct scene *scn; |
| 848 | struct expo *exp; |
| 849 | ofnode node; |
| 850 | int i; |
| 851 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 852 | ut_assertok(scan_mmc4_bootdev(uts)); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 853 | |
| 854 | ut_assertok(bootflow_menu_new(&exp)); |
| 855 | node = ofnode_path("/bootstd/theme"); |
| 856 | ut_assert(ofnode_valid(node)); |
| 857 | ut_assertok(bootflow_menu_apply_theme(exp, node)); |
| 858 | |
| 859 | scn = expo_lookup_scene_id(exp, MAIN); |
| 860 | ut_assertnonnull(scn); |
| 861 | |
| 862 | /* |
| 863 | * Check that the txt objects have the correct font size from the |
| 864 | * device tree node: bootstd/theme |
| 865 | * |
| 866 | * Check both menu items, since there are two bootflows |
| 867 | */ |
| 868 | ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); |
| 869 | ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); |
| 870 | for (i = 0; i < 2; i++) { |
| 871 | ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); |
| 872 | ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); |
| 873 | ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size)); |
| 874 | } |
| 875 | |
| 876 | expo_destroy(exp); |
| 877 | |
| 878 | return 0; |
| 879 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 880 | BOOTSTD_TEST(bootflow_menu_theme, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | a08adca | 2023-07-12 09:04:38 -0600 | [diff] [blame] | 881 | |
| 882 | /** |
| 883 | * check_arg() - Check both the normal case and the buffer-overflow case |
| 884 | * |
| 885 | * @uts: Unit-test state |
| 886 | * @expect_ret: Expected return value (i.e. buffer length) |
| 887 | * @expect_str: String expected to be returned |
| 888 | * @buf: Buffer to use |
| 889 | * @from: Original cmdline to update |
| 890 | * @arg: Argument to update (e.g. "console") |
| 891 | * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present, |
| 892 | * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add |
| 893 | * it without any value ("initrd") |
| 894 | */ |
| 895 | static int check_arg(struct unit_test_state *uts, int expect_ret, |
| 896 | const char *expect_str, char *buf, const char *from, |
| 897 | const char *arg, const char *val) |
| 898 | { |
| 899 | /* check for writing outside the reported bounds */ |
| 900 | buf[expect_ret] = '['; |
| 901 | ut_asserteq(expect_ret, |
| 902 | cmdline_set_arg(buf, expect_ret, from, arg, val, NULL)); |
| 903 | ut_asserteq_str(expect_str, buf); |
| 904 | ut_asserteq('[', buf[expect_ret]); |
| 905 | |
| 906 | /* do the test again but with one less byte in the buffer */ |
| 907 | ut_asserteq(-E2BIG, cmdline_set_arg(buf, expect_ret - 1, from, arg, |
| 908 | val, NULL)); |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | /* Test of bootflow_cmdline_set_arg() */ |
| 914 | static int test_bootflow_cmdline_set(struct unit_test_state *uts) |
| 915 | { |
| 916 | char buf[50]; |
| 917 | const int size = sizeof(buf); |
| 918 | |
| 919 | /* |
| 920 | * note that buffer-overflow tests are immediately each test case, just |
| 921 | * top keep the code together |
| 922 | */ |
| 923 | |
| 924 | /* add an arg that doesn't already exist, starting from empty */ |
| 925 | ut_asserteq(-ENOENT, cmdline_set_arg(buf, size, NULL, "me", NULL, |
| 926 | NULL)); |
| 927 | |
| 928 | ut_assertok(check_arg(uts, 3, "me", buf, NULL, "me", BOOTFLOWCL_EMPTY)); |
| 929 | ut_assertok(check_arg(uts, 4, "me=", buf, NULL, "me", "")); |
| 930 | ut_assertok(check_arg(uts, 8, "me=fred", buf, NULL, "me", "fred")); |
| 931 | |
| 932 | /* add an arg that doesn't already exist, starting from non-empty */ |
| 933 | ut_assertok(check_arg(uts, 11, "arg=123 me", buf, "arg=123", "me", |
| 934 | BOOTFLOWCL_EMPTY)); |
| 935 | ut_assertok(check_arg(uts, 12, "arg=123 me=", buf, "arg=123", "me", |
| 936 | "")); |
| 937 | ut_assertok(check_arg(uts, 16, "arg=123 me=fred", buf, "arg=123", "me", |
| 938 | "fred")); |
| 939 | |
| 940 | /* update an arg at the start */ |
| 941 | ut_assertok(check_arg(uts, 1, "", buf, "arg=123", "arg", NULL)); |
| 942 | ut_assertok(check_arg(uts, 4, "arg", buf, "arg=123", "arg", |
| 943 | BOOTFLOWCL_EMPTY)); |
| 944 | ut_assertok(check_arg(uts, 5, "arg=", buf, "arg=123", "arg", "")); |
| 945 | ut_assertok(check_arg(uts, 6, "arg=1", buf, "arg=123", "arg", "1")); |
| 946 | ut_assertok(check_arg(uts, 9, "arg=1234", buf, "arg=123", "arg", |
| 947 | "1234")); |
| 948 | |
| 949 | /* update an arg at the end */ |
| 950 | ut_assertok(check_arg(uts, 5, "mary", buf, "mary arg=123", "arg", |
| 951 | NULL)); |
| 952 | ut_assertok(check_arg(uts, 9, "mary arg", buf, "mary arg=123", "arg", |
| 953 | BOOTFLOWCL_EMPTY)); |
| 954 | ut_assertok(check_arg(uts, 10, "mary arg=", buf, "mary arg=123", "arg", |
| 955 | "")); |
| 956 | ut_assertok(check_arg(uts, 11, "mary arg=1", buf, "mary arg=123", "arg", |
| 957 | "1")); |
| 958 | ut_assertok(check_arg(uts, 14, "mary arg=1234", buf, "mary arg=123", |
| 959 | "arg", "1234")); |
| 960 | |
| 961 | /* update an arg in the middle */ |
| 962 | ut_assertok(check_arg(uts, 16, "mary=abc john=2", buf, |
| 963 | "mary=abc arg=123 john=2", "arg", NULL)); |
| 964 | ut_assertok(check_arg(uts, 20, "mary=abc arg john=2", buf, |
| 965 | "mary=abc arg=123 john=2", "arg", |
| 966 | BOOTFLOWCL_EMPTY)); |
| 967 | ut_assertok(check_arg(uts, 21, "mary=abc arg= john=2", buf, |
| 968 | "mary=abc arg=123 john=2", "arg", "")); |
| 969 | ut_assertok(check_arg(uts, 22, "mary=abc arg=1 john=2", buf, |
| 970 | "mary=abc arg=123 john=2", "arg", "1")); |
| 971 | ut_assertok(check_arg(uts, 25, "mary=abc arg=1234 john=2", buf, |
| 972 | "mary=abc arg=123 john=2", "arg", "1234")); |
| 973 | |
| 974 | /* handle existing args with quotes */ |
| 975 | ut_assertok(check_arg(uts, 16, "mary=\"abc\" john", buf, |
| 976 | "mary=\"abc\" arg=123 john", "arg", NULL)); |
| 977 | |
| 978 | /* handle existing args with quoted spaces */ |
| 979 | ut_assertok(check_arg(uts, 20, "mary=\"abc def\" john", buf, |
| 980 | "mary=\"abc def\" arg=123 john", "arg", NULL)); |
| 981 | |
| 982 | ut_assertok(check_arg(uts, 34, "mary=\"abc def\" arg=123 john def=4", |
| 983 | buf, "mary=\"abc def\" arg=123 john", "def", |
| 984 | "4")); |
| 985 | |
| 986 | /* quote at the start */ |
| 987 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 988 | "mary=\"abc def\" arg=\"123 456\"", |
| 989 | "arg", "\"4 5 6", NULL)); |
| 990 | |
| 991 | /* quote at the end */ |
| 992 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 993 | "mary=\"abc def\" arg=\"123 456\"", |
| 994 | "arg", "4 5 6\"", NULL)); |
| 995 | |
| 996 | /* quote in the middle */ |
| 997 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 998 | "mary=\"abc def\" arg=\"123 456\"", |
| 999 | "arg", "\"4 \"5 6\"", NULL)); |
| 1000 | |
| 1001 | /* handle updating a quoted arg */ |
| 1002 | ut_assertok(check_arg(uts, 27, "mary=\"abc def\" arg=\"4 5 6\"", buf, |
| 1003 | "mary=\"abc def\" arg=\"123 456\"", "arg", |
| 1004 | "4 5 6")); |
| 1005 | |
| 1006 | /* changing a quoted arg to a non-quoted arg */ |
| 1007 | ut_assertok(check_arg(uts, 23, "mary=\"abc def\" arg=789", buf, |
| 1008 | "mary=\"abc def\" arg=\"123 456\"", "arg", |
| 1009 | "789")); |
| 1010 | |
| 1011 | /* changing a non-quoted arg to a quoted arg */ |
| 1012 | ut_assertok(check_arg(uts, 29, "mary=\"abc def\" arg=\"456 789\"", buf, |
| 1013 | "mary=\"abc def\" arg=123", "arg", "456 789")); |
| 1014 | |
| 1015 | /* handling of spaces */ |
| 1016 | ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123")); |
| 1017 | ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123")); |
| 1018 | ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john ", "arg", |
| 1019 | "123")); |
| 1020 | ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john arg=123 ", |
| 1021 | "arg", "123")); |
| 1022 | ut_assertok(check_arg(uts, 18, "john arg=123 mary", buf, |
| 1023 | " john arg=123 mary ", "arg", "123")); |
| 1024 | |
| 1025 | /* unchanged arg */ |
| 1026 | ut_assertok(check_arg(uts, 3, "me", buf, "me", "me", BOOTFLOWCL_EMPTY)); |
| 1027 | |
| 1028 | /* arg which starts with the same name */ |
| 1029 | ut_assertok(check_arg(uts, 28, "mary=abc johnathon=2 john=3", buf, |
| 1030 | "mary=abc johnathon=2 john=1", "john", "3")); |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | BOOTSTD_TEST(test_bootflow_cmdline_set, 0); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1035 | |
| 1036 | /* Test of bootflow_cmdline_set_arg() */ |
| 1037 | static int bootflow_set_arg(struct unit_test_state *uts) |
| 1038 | { |
| 1039 | struct bootflow s_bflow, *bflow = &s_bflow; |
| 1040 | ulong mem_start; |
| 1041 | |
| 1042 | ut_assertok(env_set("bootargs", NULL)); |
| 1043 | |
| 1044 | mem_start = ut_check_delta(0); |
| 1045 | |
| 1046 | /* Do a simple sanity check. Rely on bootflow_cmdline() for the rest */ |
| 1047 | bflow->cmdline = NULL; |
| 1048 | ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", "123", false)); |
| 1049 | ut_asserteq_str(bflow->cmdline, "fred=123"); |
| 1050 | |
| 1051 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "and here", false)); |
| 1052 | ut_asserteq_str(bflow->cmdline, "fred=123 mary=\"and here\""); |
| 1053 | |
| 1054 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", NULL, false)); |
| 1055 | ut_asserteq_str(bflow->cmdline, "fred=123"); |
| 1056 | ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", NULL, false)); |
| 1057 | ut_asserteq_ptr(bflow->cmdline, NULL); |
| 1058 | |
| 1059 | ut_asserteq(0, ut_check_delta(mem_start)); |
| 1060 | |
| 1061 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "here", true)); |
| 1062 | ut_asserteq_str("mary=here", env_get("bootargs")); |
| 1063 | ut_assertok(env_set("bootargs", NULL)); |
| 1064 | |
| 1065 | return 0; |
| 1066 | } |
| 1067 | BOOTSTD_TEST(bootflow_set_arg, 0); |
| 1068 | |
| 1069 | /* Test of bootflow_cmdline_get_arg() */ |
| 1070 | static int bootflow_cmdline_get(struct unit_test_state *uts) |
| 1071 | { |
| 1072 | int pos; |
| 1073 | |
| 1074 | /* empty string */ |
| 1075 | ut_asserteq(-ENOENT, cmdline_get_arg("", "fred", &pos)); |
| 1076 | |
| 1077 | /* arg with empty value */ |
| 1078 | ut_asserteq(0, cmdline_get_arg("fred= mary", "fred", &pos)); |
| 1079 | ut_asserteq(5, pos); |
| 1080 | |
| 1081 | /* arg with a value */ |
| 1082 | ut_asserteq(2, cmdline_get_arg("fred=23", "fred", &pos)); |
| 1083 | ut_asserteq(5, pos); |
| 1084 | |
| 1085 | /* arg with a value */ |
| 1086 | ut_asserteq(3, cmdline_get_arg("mary=1 fred=234", "fred", &pos)); |
| 1087 | ut_asserteq(12, pos); |
| 1088 | |
| 1089 | /* arg with a value, after quoted arg */ |
| 1090 | ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=234", "fred", &pos)); |
| 1091 | ut_asserteq(16, pos); |
| 1092 | |
| 1093 | /* arg in the middle */ |
| 1094 | ut_asserteq(0, cmdline_get_arg("mary=\"1 2\" fred john=23", "fred", |
| 1095 | &pos)); |
| 1096 | ut_asserteq(15, pos); |
| 1097 | |
| 1098 | /* quoted arg */ |
| 1099 | ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=\"3 4\" john=23", |
| 1100 | "fred", &pos)); |
| 1101 | ut_asserteq(17, pos); |
| 1102 | |
| 1103 | /* args starting with the same prefix */ |
| 1104 | ut_asserteq(1, cmdline_get_arg("mary=abc johnathon=3 john=1", "john", |
| 1105 | &pos)); |
| 1106 | ut_asserteq(26, pos); |
| 1107 | |
| 1108 | return 0; |
| 1109 | } |
| 1110 | BOOTSTD_TEST(bootflow_cmdline_get, 0); |
| 1111 | |
| 1112 | static int bootflow_cmdline(struct unit_test_state *uts) |
| 1113 | { |
| 1114 | ut_assertok(run_command("bootflow scan mmc", 0)); |
| 1115 | ut_assertok(run_command("bootflow sel 0", 0)); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1116 | |
| 1117 | ut_asserteq(1, run_command("bootflow cmdline get fred", 0)); |
| 1118 | ut_assert_nextline("Argument not found"); |
| 1119 | ut_assert_console_end(); |
| 1120 | |
| 1121 | ut_asserteq(0, run_command("bootflow cmdline set fred 123", 0)); |
| 1122 | ut_asserteq(0, run_command("bootflow cmdline get fred", 0)); |
| 1123 | ut_assert_nextline("123"); |
| 1124 | |
| 1125 | ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0)); |
| 1126 | ut_asserteq(0, run_command("bootflow cmdline get mary", 0)); |
| 1127 | ut_assert_nextline("abc"); |
| 1128 | |
| 1129 | ut_asserteq(0, run_command("bootflow cmdline delete fred", 0)); |
| 1130 | ut_asserteq(1, run_command("bootflow cmdline get fred", 0)); |
| 1131 | ut_assert_nextline("Argument not found"); |
| 1132 | |
| 1133 | ut_asserteq(0, run_command("bootflow cmdline clear mary", 0)); |
| 1134 | ut_asserteq(0, run_command("bootflow cmdline get mary", 0)); |
| 1135 | ut_assert_nextline_empty(); |
| 1136 | |
Simon Glass | 7a164f8 | 2023-11-29 10:31:19 -0700 | [diff] [blame] | 1137 | ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0)); |
| 1138 | ut_asserteq(0, run_command("bootflow cmdline set mary", 0)); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1139 | ut_assert_console_end(); |
| 1140 | |
| 1141 | return 0; |
| 1142 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 1143 | BOOTSTD_TEST(bootflow_cmdline, UTF_CONSOLE); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1144 | |
Simon Glass | a61057f | 2023-10-25 07:17:36 +1300 | [diff] [blame] | 1145 | /* test a few special changes to a long command line */ |
| 1146 | static int bootflow_cmdline_special(struct unit_test_state *uts) |
| 1147 | { |
| 1148 | char buf[500]; |
| 1149 | int pos; |
| 1150 | |
| 1151 | /* |
| 1152 | * check handling of an argument which has an embedded '=', as well as |
| 1153 | * handling of a argument which partially matches ("ro" and "root") |
| 1154 | */ |
| 1155 | ut_asserteq(32, cmdline_set_arg( |
| 1156 | buf, sizeof(buf), |
| 1157 | "loglevel=7 root=PARTUUID=d68352e3 rootwait ro noinitrd", |
| 1158 | "root", NULL, &pos)); |
| 1159 | ut_asserteq_str("loglevel=7 rootwait ro noinitrd", buf); |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | BOOTSTD_TEST(bootflow_cmdline_special, 0); |
| 1164 | |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1165 | /* Test ChromiumOS bootmeth */ |
| 1166 | static int bootflow_cros(struct unit_test_state *uts) |
| 1167 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 1168 | ut_assertok(scan_mmc_bootdev(uts, "mmc5", true)); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1169 | ut_assertok(run_command("bootflow list", 0)); |
| 1170 | |
| 1171 | ut_assert_nextlinen("Showing all"); |
| 1172 | ut_assert_nextlinen("Seq"); |
| 1173 | ut_assert_nextlinen("---"); |
| 1174 | ut_assert_nextlinen(" 0 extlinux"); |
Simon Glass | d7d3a97 | 2023-08-24 13:55:45 -0600 | [diff] [blame] | 1175 | ut_assert_nextlinen(" 1 cros ready mmc 2 mmc5.bootdev.part_2 "); |
| 1176 | ut_assert_nextlinen(" 2 cros ready mmc 4 mmc5.bootdev.part_4 "); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1177 | ut_assert_nextlinen("---"); |
Simon Glass | d7d3a97 | 2023-08-24 13:55:45 -0600 | [diff] [blame] | 1178 | ut_assert_skip_to_line("(3 bootflows, 3 valid)"); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1179 | |
| 1180 | ut_assert_console_end(); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 1184 | BOOTSTD_TEST(bootflow_cros, UTF_CONSOLE); |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 1185 | |
| 1186 | /* Test Android bootmeth */ |
| 1187 | static int bootflow_android(struct unit_test_state *uts) |
| 1188 | { |
| 1189 | if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID)) |
| 1190 | return -EAGAIN; |
| 1191 | |
| 1192 | ut_assertok(scan_mmc_android_bootdev(uts, "mmc7")); |
| 1193 | ut_assertok(run_command("bootflow list", 0)); |
| 1194 | |
| 1195 | ut_assert_nextlinen("Showing all"); |
| 1196 | ut_assert_nextlinen("Seq"); |
| 1197 | ut_assert_nextlinen("---"); |
| 1198 | ut_assert_nextlinen(" 0 extlinux"); |
| 1199 | ut_assert_nextlinen(" 1 android ready mmc 0 mmc7.bootdev.whole "); |
| 1200 | ut_assert_nextlinen("---"); |
| 1201 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 1202 | |
| 1203 | ut_assert_console_end(); |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 1207 | BOOTSTD_TEST(bootflow_android, UTF_CONSOLE); |