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> |
Simon Glass | 3b1e60b | 2024-11-07 14:31:43 -0700 | [diff] [blame] | 15 | #include <efi.h> |
Simon Glass | 4f378de | 2024-11-07 14:31:50 -0700 | [diff] [blame] | 16 | #include <efi_loader.h> |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 17 | #include <expo.h> |
Simon Glass | c6a52e7 | 2024-11-15 16:19:23 -0700 | [diff] [blame] | 18 | #include <mapmem.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 19 | #ifdef CONFIG_SANDBOX |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 20 | #include <asm/test.h> |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 21 | #endif |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 22 | #include <dm/device-internal.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 23 | #include <dm/lists.h> |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 24 | #include <test/ut.h> |
| 25 | #include "bootstd_common.h" |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 26 | #include "../../boot/bootflow_internal.h" |
| 27 | #include "../../boot/scene_internal.h" |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 28 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 31 | extern U_BOOT_DRIVER(bootmeth_android); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 32 | extern U_BOOT_DRIVER(bootmeth_cros); |
Simon Glass | 2f27e47 | 2023-08-19 16:49:35 -0600 | [diff] [blame] | 33 | extern U_BOOT_DRIVER(bootmeth_2script); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 34 | |
Simon Glass | 4f378de | 2024-11-07 14:31:50 -0700 | [diff] [blame] | 35 | /* Use this as the vendor for EFI to tell the app to exit boot services */ |
| 36 | static u16 __efi_runtime_data test_vendor[] = u"U-Boot testing"; |
| 37 | |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 38 | static int inject_response(struct unit_test_state *uts) |
| 39 | { |
| 40 | /* |
| 41 | * The image being booted presents a menu of options: |
| 42 | * |
| 43 | * Fedora-Workstation-armhfp-31-1.9 Boot Options. |
| 44 | * 1: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl) |
| 45 | * Enter choice: |
| 46 | * |
| 47 | * Provide input for this, to avoid waiting two seconds for a timeout. |
| 48 | */ |
| 49 | ut_asserteq(2, console_in_puts("1\n")); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 54 | /* Check 'bootflow scan/list' commands */ |
| 55 | static int bootflow_cmd(struct unit_test_state *uts) |
| 56 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 57 | ut_assertok(run_command("bootdev select 1", 0)); |
| 58 | ut_assert_console_end(); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 59 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 60 | ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'"); |
| 61 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 62 | ut_assert_nextlinen("---"); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 63 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 64 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 65 | 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] | 66 | ut_assert_nextline("No more bootdevs"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 67 | ut_assert_nextlinen("---"); |
| 68 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 69 | ut_assert_console_end(); |
| 70 | |
| 71 | ut_assertok(run_command("bootflow list", 0)); |
| 72 | ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'"); |
| 73 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 74 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 75 | 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] | 76 | ut_assert_nextlinen("---"); |
| 77 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 78 | ut_assert_console_end(); |
| 79 | |
Simon Glass | c6a52e7 | 2024-11-15 16:19:23 -0700 | [diff] [blame] | 80 | ut_assertok(run_command("bootstd images", 0)); |
| 81 | ut_assert_nextlinen("Seq"); |
| 82 | ut_assert_nextlinen("---"); |
| 83 | ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg"); |
| 84 | ut_assert_nextlinen("---"); |
| 85 | ut_assert_nextline("(1 image)"); |
| 86 | ut_assert_console_end(); |
| 87 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 90 | BOOTSTD_TEST(bootflow_cmd, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 91 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 92 | /* Check 'bootflow scan' with a label / seq */ |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 93 | static int bootflow_cmd_label(struct unit_test_state *uts) |
| 94 | { |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 95 | test_set_eth_enable(false); |
| 96 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 97 | ut_assertok(run_command("bootflow scan -lH mmc1", 0)); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 98 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 99 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 100 | ut_assert_console_end(); |
| 101 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 102 | ut_assertok(run_command("bootflow scan -lH 0", 0)); |
| 103 | ut_assert_nextline("Scanning for bootflows with label '0'"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 104 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 105 | ut_assert_console_end(); |
| 106 | |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 107 | /* |
| 108 | * with ethernet enabled we have 8 devices ahead of the mmc ones: |
| 109 | * |
| 110 | * ut_assertok(run_command("bootdev list", 0)); |
| 111 | * Seq Probed Status Uclass Name |
| 112 | * --- ------ ------ -------- ------------------ |
| 113 | * 0 [ + ] OK ethernet eth@10002000.bootdev |
| 114 | * 1 [ ] OK ethernet eth@10003000.bootdev |
| 115 | * 2 [ ] OK ethernet sbe5.bootdev |
| 116 | * 3 [ ] OK ethernet eth@10004000.bootdev |
| 117 | * 4 [ ] OK ethernet phy-test-eth.bootdev |
| 118 | * 5 [ ] OK ethernet dsa-test-eth.bootdev |
| 119 | * 6 [ ] OK ethernet dsa-test@0.bootdev |
| 120 | * 7 [ ] OK ethernet dsa-test@1.bootdev |
| 121 | * 8 [ ] OK mmc mmc2.bootdev |
| 122 | * 9 [ + ] OK mmc mmc1.bootdev |
| 123 | * a [ ] OK mmc mmc0.bootdev |
Jerome Forissier | 253d598 | 2024-10-16 11:56:26 +0200 | [diff] [blame] | 124 | * |
| 125 | * However with CONFIG_DSA_SANDBOX=n we have two fewer (dsa-test@0 and |
| 126 | * dsa-test@1). |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 127 | */ |
Jerome Forissier | 253d598 | 2024-10-16 11:56:26 +0200 | [diff] [blame] | 128 | if (CONFIG_IS_ENABLED(DSA_SANDBOX)) { |
| 129 | ut_assertok(run_command("bootflow scan -lH 9", 0)); |
| 130 | ut_assert_nextline("Scanning for bootflows with label '9'"); |
| 131 | } else { |
| 132 | ut_assertok(run_command("bootflow scan -lH 7", 0)); |
| 133 | ut_assert_nextline("Scanning for bootflows with label '7'"); |
| 134 | } |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 135 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 136 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 137 | ut_assertok(run_command("bootflow scan -lH 0", 0)); |
Simon Glass | 484e407 | 2023-01-17 10:48:14 -0700 | [diff] [blame] | 138 | ut_assert_nextline("Scanning for bootflows with label '0'"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 139 | ut_assert_skip_to_line("(0 bootflows, 0 valid)"); |
| 140 | ut_assert_console_end(); |
| 141 | |
| 142 | return 0; |
| 143 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 144 | BOOTSTD_TEST(bootflow_cmd_label, UTF_DM | UTF_SCAN_FDT | UTF_ETH_BOOTDEV | |
| 145 | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 146 | |
| 147 | /* Check 'bootflow scan/list' commands using all bootdevs */ |
| 148 | static int bootflow_cmd_glob(struct unit_test_state *uts) |
| 149 | { |
| 150 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 151 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 152 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 153 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 154 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 155 | ut_assert_nextlinen("---"); |
| 156 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 157 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 158 | 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] | 159 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 160 | ut_assert_nextline("No more bootdevs"); |
| 161 | ut_assert_nextlinen("---"); |
| 162 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 163 | ut_assert_console_end(); |
| 164 | |
| 165 | ut_assertok(run_command("bootflow list", 0)); |
| 166 | ut_assert_nextline("Showing all bootflows"); |
| 167 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 168 | ut_assert_nextlinen("---"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 169 | 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] | 170 | ut_assert_nextlinen("---"); |
| 171 | ut_assert_nextline("(1 bootflow, 1 valid)"); |
| 172 | ut_assert_console_end(); |
| 173 | |
| 174 | return 0; |
| 175 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 176 | BOOTSTD_TEST(bootflow_cmd_glob, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 177 | |
| 178 | /* Check 'bootflow scan -e' */ |
| 179 | static int bootflow_cmd_scan_e(struct unit_test_state *uts) |
| 180 | { |
| 181 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 182 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 183 | ut_assertok(run_command("bootflow scan -aleGH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 184 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 185 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 186 | ut_assert_nextlinen("---"); |
| 187 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 188 | ut_assert_nextline(" 0 extlinux media mmc 0 mmc2.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 189 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 190 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 191 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 192 | |
| 193 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 194 | ut_assert_nextline(" 2 extlinux media mmc 0 mmc1.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 195 | 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] | 196 | ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 197 | 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] | 198 | ut_assert_nextline(" 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | 3b1e60b | 2024-11-07 14:31:43 -0700 | [diff] [blame] | 199 | ut_assert_nextline( |
| 200 | " 5 efi fs mmc 1 mmc1.bootdev.part_1 /EFI/BOOT/%s", |
| 201 | efi_get_basename()); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 202 | |
| 203 | ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 204 | ut_assert_skip_to_line( |
| 205 | " 3f efi media mmc 0 mmc0.bootdev.whole "); |
Simon Glass | 9482fdf | 2023-05-10 16:34:26 -0600 | [diff] [blame] | 206 | ut_assert_nextline(" ** No partition found, err=-93: Protocol not supported"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 207 | ut_assert_nextline("No more bootdevs"); |
| 208 | ut_assert_nextlinen("---"); |
| 209 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 210 | ut_assert_console_end(); |
| 211 | |
| 212 | ut_assertok(run_command("bootflow list", 0)); |
| 213 | ut_assert_nextline("Showing all bootflows"); |
| 214 | ut_assert_nextline("Seq Method State Uclass Part Name Filename"); |
| 215 | ut_assert_nextlinen("---"); |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 216 | ut_assert_nextline(" 0 extlinux media mmc 0 mmc2.bootdev.whole "); |
| 217 | ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole "); |
| 218 | ut_assert_skip_to_line( |
| 219 | " 4 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
| 220 | 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] | 221 | ut_assert_nextlinen("---"); |
| 222 | ut_assert_nextline("(64 bootflows, 1 valid)"); |
| 223 | ut_assert_console_end(); |
| 224 | |
| 225 | return 0; |
| 226 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 227 | 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] | 228 | |
| 229 | /* Check 'bootflow info' */ |
| 230 | static int bootflow_cmd_info(struct unit_test_state *uts) |
| 231 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 232 | ut_assertok(run_command("bootdev select 1", 0)); |
| 233 | ut_assert_console_end(); |
| 234 | ut_assertok(run_command("bootflow scan", 0)); |
| 235 | ut_assert_console_end(); |
| 236 | ut_assertok(run_command("bootflow select 0", 0)); |
| 237 | ut_assert_console_end(); |
| 238 | ut_assertok(run_command("bootflow info", 0)); |
| 239 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 240 | ut_assert_nextline("Device: mmc1.bootdev"); |
| 241 | ut_assert_nextline("Block dev: mmc1.blk"); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 242 | ut_assert_nextline("Method: extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 243 | ut_assert_nextline("State: ready"); |
| 244 | ut_assert_nextline("Partition: 1"); |
| 245 | ut_assert_nextline("Subdir: (none)"); |
| 246 | ut_assert_nextline("Filename: /extlinux/extlinux.conf"); |
| 247 | ut_assert_nextlinen("Buffer: "); |
| 248 | ut_assert_nextline("Size: 253 (595 bytes)"); |
Simon Glass | 72b7b19 | 2023-01-06 08:52:33 -0600 | [diff] [blame] | 249 | 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] | 250 | ut_assert_nextline("Cmdline: (none)"); |
Simon Glass | 612b9cc | 2023-01-06 08:52:34 -0600 | [diff] [blame] | 251 | ut_assert_nextline("Logo: (none)"); |
Simon Glass | 7b8c634 | 2023-01-17 10:47:56 -0700 | [diff] [blame] | 252 | ut_assert_nextline("FDT: <NULL>"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 253 | ut_assert_nextline("Error: 0"); |
| 254 | ut_assert_console_end(); |
| 255 | |
| 256 | ut_assertok(run_command("bootflow info -d", 0)); |
| 257 | ut_assert_nextline("Name: mmc1.bootdev.part_1"); |
| 258 | ut_assert_skip_to_line("Error: 0"); |
| 259 | ut_assert_nextline("Contents:"); |
| 260 | ut_assert_nextline("%s", ""); |
| 261 | ut_assert_nextline("# extlinux.conf generated by appliance-creator"); |
| 262 | ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img"); |
| 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_cmd_info, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 268 | |
| 269 | /* Check 'bootflow scan -b' to boot the first available bootdev */ |
| 270 | static int bootflow_scan_boot(struct unit_test_state *uts) |
| 271 | { |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 272 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 273 | ut_assertok(run_command("bootflow scan -b", 0)); |
| 274 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 275 | "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 276 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 277 | |
| 278 | /* |
| 279 | * We expect it to get through to boot although sandbox always returns |
| 280 | * -EFAULT as it cannot actually boot the kernel |
| 281 | */ |
| 282 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 283 | ut_assert_nextline("Boot failed (err=-14)"); |
| 284 | ut_assert_console_end(); |
| 285 | |
| 286 | return 0; |
| 287 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 288 | BOOTSTD_TEST(bootflow_scan_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 289 | |
| 290 | /* Check iterating through available bootflows */ |
| 291 | static int bootflow_iter(struct unit_test_state *uts) |
| 292 | { |
| 293 | struct bootflow_iter iter; |
| 294 | struct bootflow bflow; |
| 295 | |
| 296 | bootstd_clear_glob(); |
| 297 | |
| 298 | /* The first device is mmc2.bootdev which has no media */ |
| 299 | ut_asserteq(-EPROTONOSUPPORT, |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 300 | bootflow_scan_first(NULL, NULL, &iter, |
Simon Glass | 99e6818 | 2023-02-22 12:17:03 -0700 | [diff] [blame] | 301 | BOOTFLOWIF_ALL | BOOTFLOWIF_SKIP_GLOBAL, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 302 | ut_asserteq(2, iter.num_methods); |
| 303 | ut_asserteq(0, iter.cur_method); |
| 304 | ut_asserteq(0, iter.part); |
| 305 | ut_asserteq(0, iter.max_part); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 306 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 307 | ut_asserteq(0, bflow.err); |
| 308 | |
| 309 | /* |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 310 | * This shows MEDIA even though there is none, since in |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 311 | * bootdev_find_in_blk() we call part_get_info() which returns |
| 312 | * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would |
| 313 | * know. |
| 314 | */ |
| 315 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
| 316 | |
| 317 | ut_asserteq(-EPROTONOSUPPORT, 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(0, 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 | /* The next device is mmc1.bootdev - at first we use the whole device */ |
| 328 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 329 | ut_asserteq(2, iter.num_methods); |
| 330 | ut_asserteq(0, iter.cur_method); |
| 331 | ut_asserteq(0, 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_MEDIA, 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(0, 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_MEDIA, bflow.state); |
| 346 | bootflow_free(&bflow); |
| 347 | |
| 348 | /* Then more to partition 1 where we find something */ |
| 349 | ut_assertok(bootflow_scan_next(&iter, &bflow)); |
| 350 | ut_asserteq(2, iter.num_methods); |
| 351 | ut_asserteq(0, iter.cur_method); |
| 352 | ut_asserteq(1, 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); |
| 356 | ut_asserteq(BOOTFLOWST_READY, bflow.state); |
| 357 | bootflow_free(&bflow); |
| 358 | |
| 359 | ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow)); |
| 360 | ut_asserteq(2, iter.num_methods); |
| 361 | ut_asserteq(1, iter.cur_method); |
| 362 | ut_asserteq(1, iter.part); |
| 363 | ut_asserteq(0x1e, iter.max_part); |
| 364 | ut_asserteq_str("efi", iter.method->name); |
| 365 | ut_asserteq(0, bflow.err); |
| 366 | ut_asserteq(BOOTFLOWST_FS, bflow.state); |
| 367 | bootflow_free(&bflow); |
| 368 | |
Simon Glass | f5e2df0 | 2023-01-17 10:47:41 -0700 | [diff] [blame] | 369 | /* Then more to partition 2 which exists but is not bootable */ |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 370 | ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 371 | ut_asserteq(2, iter.num_methods); |
| 372 | ut_asserteq(0, iter.cur_method); |
| 373 | ut_asserteq(2, iter.part); |
| 374 | ut_asserteq(0x1e, iter.max_part); |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 375 | ut_asserteq_str("extlinux", iter.method->name); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 376 | ut_asserteq(0, bflow.err); |
Simon Glass | 64cbc5c | 2023-01-17 10:47:42 -0700 | [diff] [blame] | 377 | ut_asserteq(BOOTFLOWST_MEDIA, bflow.state); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 378 | bootflow_free(&bflow); |
| 379 | |
| 380 | bootflow_iter_uninit(&iter); |
| 381 | |
| 382 | ut_assert_console_end(); |
| 383 | |
| 384 | return 0; |
| 385 | } |
Simon Glass | 129ba73 | 2024-10-19 09:21:58 -0600 | [diff] [blame] | 386 | BOOTSTD_TEST(bootflow_iter, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 387 | |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 388 | #if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL) |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 389 | /* Check using the system bootdev */ |
| 390 | static int bootflow_system(struct unit_test_state *uts) |
| 391 | { |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 392 | struct udevice *bootstd, *dev; |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 393 | |
AKASHI Takahiro | e3e542d | 2024-01-17 13:39:42 +0900 | [diff] [blame] | 394 | if (!IS_ENABLED(CONFIG_EFI_BOOTMGR)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 395 | return -EAGAIN; |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 396 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
Heinrich Schuchardt | dc1f006 | 2024-04-03 20:34:15 +0200 | [diff] [blame] | 397 | ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_3efi_mgr), |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 398 | "efi_mgr", 0, ofnode_null(), &dev)); |
| 399 | ut_assertok(device_probe(dev)); |
Simon Glass | 161e1e3 | 2022-07-30 15:52:22 -0600 | [diff] [blame] | 400 | sandbox_set_fake_efi_mgr_dev(dev, true); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 401 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 402 | /* We should get a single 'bootmgr' method right at the end */ |
| 403 | bootstd_clear_glob(); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 404 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 405 | ut_assert_skip_to_line( |
Simon Glass | d465ad5 | 2023-08-24 13:55:39 -0600 | [diff] [blame] | 406 | " 0 efi_mgr ready (none) 0 <NULL> "); |
Simon Glass | cc15e14 | 2022-07-30 15:52:27 -0600 | [diff] [blame] | 407 | ut_assert_skip_to_line("No more bootdevs"); |
Simon Glass | b9ff648 | 2023-01-17 10:47:23 -0700 | [diff] [blame] | 408 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 409 | ut_assert_console_end(); |
| 410 | |
| 411 | return 0; |
| 412 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 413 | BOOTSTD_TEST(bootflow_system, UTF_DM | UTF_SCAN_PDATA | UTF_SCAN_FDT | |
| 414 | UTF_CONSOLE); |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 415 | #endif |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 416 | |
| 417 | /* Check disabling a bootmethod if it requests it */ |
| 418 | static int bootflow_iter_disable(struct unit_test_state *uts) |
| 419 | { |
| 420 | struct udevice *bootstd, *dev; |
| 421 | struct bootflow_iter iter; |
| 422 | struct bootflow bflow; |
| 423 | int i; |
| 424 | |
| 425 | /* Add the EFI bootmgr driver */ |
| 426 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 427 | ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox", |
| 428 | &dev)); |
| 429 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 430 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 431 | |
| 432 | bootstd_clear_glob(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 433 | ut_assertok(inject_response(uts)); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 434 | ut_assertok(run_command("bootflow scan -lbH", 0)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 435 | |
| 436 | /* Try to boot the bootmgr flow, which will fail */ |
| 437 | console_record_reset_enable(); |
Simon Glass | 5d3d44f | 2023-01-17 10:48:16 -0700 | [diff] [blame] | 438 | ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 439 | ut_asserteq(3, iter.num_methods); |
| 440 | ut_asserteq_str("sandbox", iter.method->name); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 441 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 442 | ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow)); |
| 443 | |
| 444 | ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried"); |
| 445 | ut_assert_console_end(); |
| 446 | |
| 447 | /* Check that the sandbox bootmeth has been removed */ |
| 448 | ut_asserteq(2, iter.num_methods); |
| 449 | for (i = 0; i < iter.num_methods; i++) |
| 450 | ut_assert(strcmp("sandbox", iter.method_order[i]->name)); |
| 451 | |
| 452 | return 0; |
| 453 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 454 | BOOTSTD_TEST(bootflow_iter_disable, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 455 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 456 | /* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */ |
| 457 | static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts) |
| 458 | { |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 459 | if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL)) |
Simon Glass | c759944 | 2022-10-20 18:22:49 -0600 | [diff] [blame] | 460 | return -EAGAIN; |
Simon Glass | 90b643d | 2022-07-30 15:52:36 -0600 | [diff] [blame] | 461 | |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 462 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 463 | |
| 464 | /* |
| 465 | * Make sure that the -G flag makes the scan fail, since this is not |
| 466 | * supported when an ordering is provided |
| 467 | */ |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 468 | ut_assertok(bootmeth_set_order("efi firmware0")); |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 469 | ut_assertok(run_command("bootflow scan -lGH", 0)); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 470 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 471 | ut_assert_nextline( |
| 472 | "Seq Method State Uclass Part Name Filename"); |
| 473 | ut_assert_nextlinen("---"); |
| 474 | ut_assert_nextlinen("---"); |
| 475 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 476 | ut_assert_console_end(); |
| 477 | |
Simon Glass | e4cf106 | 2023-01-17 10:48:13 -0700 | [diff] [blame] | 478 | ut_assertok(run_command("bootflow scan -lH", 0)); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 479 | ut_assert_nextline("Scanning for bootflows in all bootdevs"); |
| 480 | ut_assert_nextline( |
| 481 | "Seq Method State Uclass Part Name Filename"); |
| 482 | ut_assert_nextlinen("---"); |
| 483 | ut_assert_nextline("Scanning global bootmeth 'firmware0':"); |
| 484 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 485 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 486 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 487 | ut_assert_nextline("No more bootdevs"); |
| 488 | ut_assert_nextlinen("---"); |
| 489 | ut_assert_nextline("(0 bootflows, 0 valid)"); |
| 490 | ut_assert_console_end(); |
| 491 | |
| 492 | return 0; |
| 493 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 494 | BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UTF_DM | UTF_SCAN_FDT | |
| 495 | UTF_CONSOLE); |
Simon Glass | c8d3721 | 2022-07-30 15:52:34 -0600 | [diff] [blame] | 496 | |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 497 | /* Check 'bootflow boot' to boot a selected bootflow */ |
| 498 | static int bootflow_cmd_boot(struct unit_test_state *uts) |
| 499 | { |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 500 | ut_assertok(run_command("bootdev select 1", 0)); |
| 501 | ut_assert_console_end(); |
| 502 | ut_assertok(run_command("bootflow scan", 0)); |
| 503 | ut_assert_console_end(); |
| 504 | ut_assertok(run_command("bootflow select 0", 0)); |
| 505 | ut_assert_console_end(); |
Simon Glass | 49ad1d8 | 2022-07-30 15:52:16 -0600 | [diff] [blame] | 506 | |
| 507 | ut_assertok(inject_response(uts)); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 508 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 509 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 510 | "** Booting bootflow 'mmc1.bootdev.part_1' with extlinux"); |
Simon Glass | b255efc | 2022-04-24 23:31:24 -0600 | [diff] [blame] | 511 | ut_assert_nextline("Ignoring unknown command: ui"); |
| 512 | |
| 513 | /* |
| 514 | * We expect it to get through to boot although sandbox always returns |
| 515 | * -EFAULT as it cannot actually boot the kernel |
| 516 | */ |
| 517 | ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux"); |
| 518 | ut_assert_nextline("Boot failed (err=-14)"); |
| 519 | ut_assert_console_end(); |
| 520 | |
| 521 | return 0; |
| 522 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 523 | BOOTSTD_TEST(bootflow_cmd_boot, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 524 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 525 | /** |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 526 | * 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] | 527 | * |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 528 | * After calling this function, set std->bootdev_order to *@old_orderp to |
| 529 | * restore normal operation of bootstd (i.e. with the original bootdev order) |
| 530 | * |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 531 | * @uts: Unit test state |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 532 | * @mmc_dev: MMC device to use, e.g. "mmc4". Note that this must remain valid |
| 533 | * in the caller until |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 534 | * @bind_cros: true to bind the ChromiumOS and Android bootmeths |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 535 | * @old_orderp: Returns the original bootdev order, which must be restored |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 536 | * Returns 0 on success, -ve on failure |
| 537 | */ |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 538 | 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] | 539 | bool bind_cros_android, const char ***old_orderp) |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 540 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 541 | static const char *order[] = {"mmc2", "mmc1", NULL, NULL}; |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 542 | struct udevice *dev, *bootstd; |
| 543 | struct bootstd_priv *std; |
| 544 | const char **old_order; |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 545 | ofnode root, node; |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 546 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 547 | order[2] = mmc_dev; |
| 548 | |
Simon Glass | 64c6325 | 2024-11-07 14:31:49 -0700 | [diff] [blame] | 549 | /* Enable the requested mmc node since we need a second bootflow */ |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 550 | root = oftree_root(oftree_default()); |
| 551 | node = ofnode_find_subnode(root, mmc_dev); |
| 552 | ut_assert(ofnode_valid(node)); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 553 | ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false)); |
| 554 | |
| 555 | /* Enable the script bootmeth too */ |
| 556 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
Simon Glass | 2f27e47 | 2023-08-19 16:49:35 -0600 | [diff] [blame] | 557 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_2script), |
Simon Glass | a59d6d3 | 2024-10-19 09:21:50 -0600 | [diff] [blame] | 558 | "script", 0, ofnode_null(), &dev)); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 559 | |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 560 | /* Enable the cros bootmeth if needed */ |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 561 | if (IS_ENABLED(CONFIG_BOOTMETH_CROS) && bind_cros_android) { |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 562 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 563 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_cros), |
| 564 | "cros", 0, ofnode_null(), &dev)); |
| 565 | } |
| 566 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 567 | /* Enable the android bootmeths if needed */ |
| 568 | if (IS_ENABLED(CONFIG_BOOTMETH_ANDROID) && bind_cros_android) { |
| 569 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 570 | ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_android), |
| 571 | "android", 0, ofnode_null(), &dev)); |
| 572 | } |
| 573 | |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 574 | /* Change the order to include the device */ |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 575 | std = dev_get_priv(bootstd); |
| 576 | old_order = std->bootdev_order; |
| 577 | std->bootdev_order = order; |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 578 | *old_orderp = old_order; |
| 579 | |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * scan_mmc_bootdev() - Set up an mmc bootdev so we can access other distros |
| 585 | * |
| 586 | * @uts: Unit test state |
| 587 | * @mmc_dev: MMC device to use, e.g. "mmc4" |
| 588 | * @bind_cros: true to bind the ChromiumOS bootmeth |
| 589 | * Returns 0 on success, -ve on failure |
| 590 | */ |
| 591 | static int scan_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev, |
| 592 | bool bind_cros) |
| 593 | { |
| 594 | struct bootstd_priv *std; |
| 595 | struct udevice *bootstd; |
| 596 | const char **old_order; |
| 597 | |
| 598 | ut_assertok(prep_mmc_bootdev(uts, mmc_dev, bind_cros, &old_order)); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 599 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 600 | ut_assertok(run_command("bootflow scan", 0)); |
| 601 | ut_assert_console_end(); |
| 602 | |
| 603 | /* Restore the order used by the device tree */ |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 604 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 605 | std = dev_get_priv(bootstd); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 606 | std->bootdev_order = old_order; |
| 607 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 608 | return 0; |
| 609 | } |
| 610 | |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 611 | /** |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 612 | * scan_mmc_android_bootdev() - Set up an mmc bootdev so we can access other |
| 613 | * distros. Android bootflow might print "ANDROID:*" while scanning |
| 614 | * |
| 615 | * @uts: Unit test state |
| 616 | * @mmc_dev: MMC device to use, e.g. "mmc4" |
| 617 | * Returns 0 on success, -ve on failure |
| 618 | */ |
| 619 | static int scan_mmc_android_bootdev(struct unit_test_state *uts, const char *mmc_dev) |
| 620 | { |
| 621 | struct bootstd_priv *std; |
| 622 | struct udevice *bootstd; |
| 623 | const char **old_order; |
| 624 | |
| 625 | ut_assertok(prep_mmc_bootdev(uts, mmc_dev, true, &old_order)); |
| 626 | |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 627 | ut_assertok(run_command("bootflow scan", 0)); |
| 628 | /* Android bootflow might print one or two 'ANDROID:*' logs */ |
| 629 | ut_check_skipline(uts); |
| 630 | ut_check_skipline(uts); |
| 631 | ut_assert_console_end(); |
| 632 | |
| 633 | /* Restore the order used by the device tree */ |
| 634 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 635 | std = dev_get_priv(bootstd); |
| 636 | std->bootdev_order = old_order; |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | /** |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 642 | * 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] | 643 | * |
| 644 | * @uts: Unit test state |
| 645 | * Returns 0 on success, -ve on failure |
| 646 | */ |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 647 | static int scan_mmc4_bootdev(struct unit_test_state *uts) |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 648 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 649 | ut_assertok(scan_mmc_bootdev(uts, "mmc4", false)); |
Simon Glass | bb76a5c | 2023-08-24 13:55:40 -0600 | [diff] [blame] | 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 654 | /* Check 'bootflow menu' to select a bootflow */ |
| 655 | static int bootflow_cmd_menu(struct unit_test_state *uts) |
| 656 | { |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 657 | struct bootstd_priv *std; |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 658 | char prev[3]; |
| 659 | |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 660 | /* get access to the current bootflow */ |
| 661 | ut_assertok(bootstd_get_priv(&std)); |
| 662 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 663 | ut_assertok(scan_mmc4_bootdev(uts)); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 664 | |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 665 | /* Add keypresses to move to and select the second one in the list */ |
| 666 | prev[0] = CTL_CH('n'); |
| 667 | prev[1] = '\r'; |
| 668 | prev[2] = '\0'; |
| 669 | ut_asserteq(2, console_in_puts(prev)); |
| 670 | |
| 671 | ut_assertok(run_command("bootflow menu", 0)); |
| 672 | ut_assert_nextline("Selected: Armbian"); |
Simon Glass | 6d5083b | 2023-10-01 19:14:38 -0600 | [diff] [blame] | 673 | ut_assertnonnull(std->cur_bootflow); |
| 674 | ut_assert_console_end(); |
| 675 | |
| 676 | /* Check not selecting anything */ |
| 677 | prev[0] = '\e'; |
| 678 | prev[1] = '\0'; |
| 679 | ut_asserteq(1, console_in_puts(prev)); |
| 680 | |
| 681 | ut_asserteq(1, run_command("bootflow menu", 0)); |
| 682 | ut_assertnull(std->cur_bootflow); |
| 683 | ut_assert_nextline("Nothing chosen"); |
Simon Glass | d2bc33ed | 2023-01-06 08:52:41 -0600 | [diff] [blame] | 684 | ut_assert_console_end(); |
| 685 | |
| 686 | return 0; |
| 687 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 688 | BOOTSTD_TEST(bootflow_cmd_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 689 | |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 690 | /* Check 'bootflow scan -m' to select a bootflow using a menu */ |
| 691 | static int bootflow_scan_menu(struct unit_test_state *uts) |
| 692 | { |
| 693 | struct bootstd_priv *std; |
| 694 | const char **old_order, **new_order; |
| 695 | char prev[3]; |
| 696 | |
| 697 | /* get access to the current bootflow */ |
| 698 | ut_assertok(bootstd_get_priv(&std)); |
| 699 | |
| 700 | ut_assertok(prep_mmc_bootdev(uts, "mmc4", false, &old_order)); |
| 701 | |
| 702 | /* Add keypresses to move to and select the second one in the list */ |
| 703 | prev[0] = CTL_CH('n'); |
| 704 | prev[1] = '\r'; |
| 705 | prev[2] = '\0'; |
| 706 | ut_asserteq(2, console_in_puts(prev)); |
| 707 | |
| 708 | ut_assertok(run_command("bootflow scan -lm", 0)); |
| 709 | new_order = std->bootdev_order; |
| 710 | std->bootdev_order = old_order; |
| 711 | |
| 712 | ut_assert_skip_to_line("No more bootdevs"); |
| 713 | ut_assert_nextlinen("--"); |
| 714 | ut_assert_nextline("(2 bootflows, 2 valid)"); |
| 715 | |
| 716 | ut_assert_nextline("Selected: Armbian"); |
| 717 | ut_assertnonnull(std->cur_bootflow); |
| 718 | ut_assert_console_end(); |
| 719 | |
| 720 | /* Check not selecting anything */ |
| 721 | prev[0] = '\e'; |
| 722 | prev[1] = '\0'; |
| 723 | ut_asserteq(1, console_in_puts(prev)); |
| 724 | |
| 725 | std->bootdev_order = new_order; /* Blue Monday */ |
| 726 | ut_assertok(run_command("bootflow scan -lm", 0)); |
| 727 | std->bootdev_order = old_order; |
| 728 | |
| 729 | ut_assertnull(std->cur_bootflow); |
| 730 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 731 | ut_assert_nextline("Nothing chosen"); |
| 732 | ut_assert_console_end(); |
| 733 | |
| 734 | return 0; |
| 735 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 736 | BOOTSTD_TEST(bootflow_scan_menu, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 737 | |
| 738 | /* Check 'bootflow scan -mb' to select and boot a bootflow using a menu */ |
| 739 | static int bootflow_scan_menu_boot(struct unit_test_state *uts) |
| 740 | { |
| 741 | struct bootstd_priv *std; |
| 742 | const char **old_order; |
| 743 | char prev[3]; |
| 744 | |
| 745 | /* get access to the current bootflow */ |
| 746 | ut_assertok(bootstd_get_priv(&std)); |
| 747 | |
| 748 | ut_assertok(prep_mmc_bootdev(uts, "mmc4", false, &old_order)); |
| 749 | |
| 750 | /* Add keypresses to move to and select the second one in the list */ |
| 751 | prev[0] = CTL_CH('n'); |
| 752 | prev[1] = '\r'; |
| 753 | prev[2] = '\0'; |
| 754 | ut_asserteq(2, console_in_puts(prev)); |
| 755 | |
| 756 | ut_assertok(run_command("bootflow scan -lmb", 0)); |
| 757 | std->bootdev_order = old_order; |
| 758 | |
| 759 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 760 | |
| 761 | ut_assert_nextline("Selected: Armbian"); |
Francis Laniel | 5b64c45 | 2023-12-22 22:02:35 +0100 | [diff] [blame] | 762 | |
| 763 | if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { |
| 764 | /* |
| 765 | * With old hush, despite booti failing to boot, i.e. returning |
| 766 | * CMD_RET_FAILURE, run_command() returns 0 which leads bootflow_boot(), as |
| 767 | * we are using bootmeth_script here, to return -EFAULT. |
| 768 | */ |
| 769 | ut_assert_skip_to_line("Boot failed (err=-14)"); |
| 770 | } else if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { |
| 771 | /* |
| 772 | * While with modern one, run_command() propagates CMD_RET_FAILURE returned |
| 773 | * by booti, so we get 1 here. |
| 774 | */ |
| 775 | ut_assert_skip_to_line("Boot failed (err=1)"); |
| 776 | } |
Simon Glass | 9bf2786 | 2023-10-01 19:15:25 -0600 | [diff] [blame] | 777 | ut_assertnonnull(std->cur_bootflow); |
| 778 | ut_assert_console_end(); |
| 779 | |
| 780 | return 0; |
| 781 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 782 | 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] | 783 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 784 | /* Check searching for a single bootdev using the hunters */ |
| 785 | static int bootflow_cmd_hunt_single(struct unit_test_state *uts) |
| 786 | { |
| 787 | struct bootstd_priv *std; |
| 788 | |
| 789 | /* get access to the used hunters */ |
| 790 | ut_assertok(bootstd_get_priv(&std)); |
| 791 | |
| 792 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 793 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 794 | ut_assertok(run_command("bootflow scan -l mmc1", 0)); |
| 795 | ut_assert_nextline("Scanning for bootflows with label 'mmc1'"); |
| 796 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 797 | ut_assert_console_end(); |
| 798 | |
| 799 | /* check that the hunter was used */ |
| 800 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 801 | |
| 802 | return 0; |
| 803 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 804 | BOOTSTD_TEST(bootflow_cmd_hunt_single, UTF_DM | UTF_SCAN_FDT | |
| 805 | UTF_CONSOLE); |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 806 | |
| 807 | /* Check searching for a uclass label using the hunters */ |
| 808 | static int bootflow_cmd_hunt_label(struct unit_test_state *uts) |
| 809 | { |
| 810 | struct bootstd_priv *std; |
| 811 | |
| 812 | /* get access to the used hunters */ |
| 813 | ut_assertok(bootstd_get_priv(&std)); |
| 814 | |
| 815 | test_set_skip_delays(true); |
| 816 | test_set_eth_enable(false); |
| 817 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 818 | |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 819 | ut_assertok(run_command("bootflow scan -l mmc", 0)); |
| 820 | |
| 821 | /* check that the hunter was used */ |
| 822 | ut_asserteq(BIT(MMC_HUNTER) | BIT(1), std->hunters_used); |
| 823 | |
| 824 | /* check that we got the mmc1 bootflow */ |
| 825 | ut_assert_nextline("Scanning for bootflows with label 'mmc'"); |
| 826 | ut_assert_nextlinen("Seq"); |
| 827 | ut_assert_nextlinen("---"); |
| 828 | ut_assert_nextline("Hunting with: simple_bus"); |
| 829 | ut_assert_nextline("Found 2 extension board(s)."); |
| 830 | ut_assert_nextline("Hunting with: mmc"); |
| 831 | ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':"); |
| 832 | ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':"); |
| 833 | ut_assert_nextline( |
Simon Glass | b71d7f7 | 2023-05-10 16:34:46 -0600 | [diff] [blame] | 834 | " 0 extlinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf"); |
Simon Glass | ba3d537 | 2023-01-17 10:48:15 -0700 | [diff] [blame] | 835 | ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':"); |
| 836 | ut_assert_skip_to_line("(1 bootflow, 1 valid)"); |
| 837 | ut_assert_console_end(); |
| 838 | |
| 839 | return 0; |
| 840 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 841 | 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] | 842 | |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 843 | /** |
| 844 | * check_font() - Check that the font size for an item matches expectations |
| 845 | * |
| 846 | * @uts: Unit test state |
| 847 | * @scn: Scene containing the text object |
| 848 | * @id: ID of the text object |
| 849 | * Returns 0 on success, -ve on failure |
| 850 | */ |
| 851 | static int check_font(struct unit_test_state *uts, struct scene *scn, uint id, |
| 852 | int font_size) |
| 853 | { |
| 854 | struct scene_obj_txt *txt; |
| 855 | |
| 856 | txt = scene_obj_find(scn, id, SCENEOBJT_TEXT); |
| 857 | ut_assertnonnull(txt); |
| 858 | |
| 859 | ut_asserteq(font_size, txt->font_size); |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | /* Check themes work with a bootflow menu */ |
| 865 | static int bootflow_menu_theme(struct unit_test_state *uts) |
| 866 | { |
| 867 | const int font_size = 30; |
| 868 | struct scene *scn; |
| 869 | struct expo *exp; |
| 870 | ofnode node; |
| 871 | int i; |
| 872 | |
Marek Vasut | abb772a | 2024-10-20 17:43:12 +0200 | [diff] [blame] | 873 | if (!CONFIG_IS_ENABLED(BOOTSTD_MENU)) |
| 874 | return -EAGAIN; |
| 875 | |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 876 | ut_assertok(scan_mmc4_bootdev(uts)); |
Simon Glass | d92bcc4 | 2023-01-06 08:52:42 -0600 | [diff] [blame] | 877 | |
| 878 | ut_assertok(bootflow_menu_new(&exp)); |
| 879 | node = ofnode_path("/bootstd/theme"); |
| 880 | ut_assert(ofnode_valid(node)); |
| 881 | ut_assertok(bootflow_menu_apply_theme(exp, node)); |
| 882 | |
| 883 | scn = expo_lookup_scene_id(exp, MAIN); |
| 884 | ut_assertnonnull(scn); |
| 885 | |
| 886 | /* |
| 887 | * Check that the txt objects have the correct font size from the |
| 888 | * device tree node: bootstd/theme |
| 889 | * |
| 890 | * Check both menu items, since there are two bootflows |
| 891 | */ |
| 892 | ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size)); |
| 893 | ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size)); |
| 894 | for (i = 0; i < 2; i++) { |
| 895 | ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size)); |
| 896 | ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size)); |
| 897 | ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size)); |
| 898 | } |
| 899 | |
| 900 | expo_destroy(exp); |
| 901 | |
| 902 | return 0; |
| 903 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 904 | BOOTSTD_TEST(bootflow_menu_theme, UTF_DM | UTF_SCAN_FDT | UTF_CONSOLE); |
Simon Glass | a08adca | 2023-07-12 09:04:38 -0600 | [diff] [blame] | 905 | |
| 906 | /** |
| 907 | * check_arg() - Check both the normal case and the buffer-overflow case |
| 908 | * |
| 909 | * @uts: Unit-test state |
| 910 | * @expect_ret: Expected return value (i.e. buffer length) |
| 911 | * @expect_str: String expected to be returned |
| 912 | * @buf: Buffer to use |
| 913 | * @from: Original cmdline to update |
| 914 | * @arg: Argument to update (e.g. "console") |
| 915 | * @val: Value to set (e.g. "ttyS2") or NULL to delete the argument if present, |
| 916 | * "" to set it to an empty value (e.g. "console=") and BOOTFLOWCL_EMPTY to add |
| 917 | * it without any value ("initrd") |
| 918 | */ |
| 919 | static int check_arg(struct unit_test_state *uts, int expect_ret, |
| 920 | const char *expect_str, char *buf, const char *from, |
| 921 | const char *arg, const char *val) |
| 922 | { |
| 923 | /* check for writing outside the reported bounds */ |
| 924 | buf[expect_ret] = '['; |
| 925 | ut_asserteq(expect_ret, |
| 926 | cmdline_set_arg(buf, expect_ret, from, arg, val, NULL)); |
| 927 | ut_asserteq_str(expect_str, buf); |
| 928 | ut_asserteq('[', buf[expect_ret]); |
| 929 | |
| 930 | /* do the test again but with one less byte in the buffer */ |
| 931 | ut_asserteq(-E2BIG, cmdline_set_arg(buf, expect_ret - 1, from, arg, |
| 932 | val, NULL)); |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | /* Test of bootflow_cmdline_set_arg() */ |
| 938 | static int test_bootflow_cmdline_set(struct unit_test_state *uts) |
| 939 | { |
| 940 | char buf[50]; |
| 941 | const int size = sizeof(buf); |
| 942 | |
| 943 | /* |
| 944 | * note that buffer-overflow tests are immediately each test case, just |
| 945 | * top keep the code together |
| 946 | */ |
| 947 | |
| 948 | /* add an arg that doesn't already exist, starting from empty */ |
| 949 | ut_asserteq(-ENOENT, cmdline_set_arg(buf, size, NULL, "me", NULL, |
| 950 | NULL)); |
| 951 | |
| 952 | ut_assertok(check_arg(uts, 3, "me", buf, NULL, "me", BOOTFLOWCL_EMPTY)); |
| 953 | ut_assertok(check_arg(uts, 4, "me=", buf, NULL, "me", "")); |
| 954 | ut_assertok(check_arg(uts, 8, "me=fred", buf, NULL, "me", "fred")); |
| 955 | |
| 956 | /* add an arg that doesn't already exist, starting from non-empty */ |
| 957 | ut_assertok(check_arg(uts, 11, "arg=123 me", buf, "arg=123", "me", |
| 958 | BOOTFLOWCL_EMPTY)); |
| 959 | ut_assertok(check_arg(uts, 12, "arg=123 me=", buf, "arg=123", "me", |
| 960 | "")); |
| 961 | ut_assertok(check_arg(uts, 16, "arg=123 me=fred", buf, "arg=123", "me", |
| 962 | "fred")); |
| 963 | |
| 964 | /* update an arg at the start */ |
| 965 | ut_assertok(check_arg(uts, 1, "", buf, "arg=123", "arg", NULL)); |
| 966 | ut_assertok(check_arg(uts, 4, "arg", buf, "arg=123", "arg", |
| 967 | BOOTFLOWCL_EMPTY)); |
| 968 | ut_assertok(check_arg(uts, 5, "arg=", buf, "arg=123", "arg", "")); |
| 969 | ut_assertok(check_arg(uts, 6, "arg=1", buf, "arg=123", "arg", "1")); |
| 970 | ut_assertok(check_arg(uts, 9, "arg=1234", buf, "arg=123", "arg", |
| 971 | "1234")); |
| 972 | |
| 973 | /* update an arg at the end */ |
| 974 | ut_assertok(check_arg(uts, 5, "mary", buf, "mary arg=123", "arg", |
| 975 | NULL)); |
| 976 | ut_assertok(check_arg(uts, 9, "mary arg", buf, "mary arg=123", "arg", |
| 977 | BOOTFLOWCL_EMPTY)); |
| 978 | ut_assertok(check_arg(uts, 10, "mary arg=", buf, "mary arg=123", "arg", |
| 979 | "")); |
| 980 | ut_assertok(check_arg(uts, 11, "mary arg=1", buf, "mary arg=123", "arg", |
| 981 | "1")); |
| 982 | ut_assertok(check_arg(uts, 14, "mary arg=1234", buf, "mary arg=123", |
| 983 | "arg", "1234")); |
| 984 | |
| 985 | /* update an arg in the middle */ |
| 986 | ut_assertok(check_arg(uts, 16, "mary=abc john=2", buf, |
| 987 | "mary=abc arg=123 john=2", "arg", NULL)); |
| 988 | ut_assertok(check_arg(uts, 20, "mary=abc arg john=2", buf, |
| 989 | "mary=abc arg=123 john=2", "arg", |
| 990 | BOOTFLOWCL_EMPTY)); |
| 991 | ut_assertok(check_arg(uts, 21, "mary=abc arg= john=2", buf, |
| 992 | "mary=abc arg=123 john=2", "arg", "")); |
| 993 | ut_assertok(check_arg(uts, 22, "mary=abc arg=1 john=2", buf, |
| 994 | "mary=abc arg=123 john=2", "arg", "1")); |
| 995 | ut_assertok(check_arg(uts, 25, "mary=abc arg=1234 john=2", buf, |
| 996 | "mary=abc arg=123 john=2", "arg", "1234")); |
| 997 | |
| 998 | /* handle existing args with quotes */ |
| 999 | ut_assertok(check_arg(uts, 16, "mary=\"abc\" john", buf, |
| 1000 | "mary=\"abc\" arg=123 john", "arg", NULL)); |
| 1001 | |
| 1002 | /* handle existing args with quoted spaces */ |
| 1003 | ut_assertok(check_arg(uts, 20, "mary=\"abc def\" john", buf, |
| 1004 | "mary=\"abc def\" arg=123 john", "arg", NULL)); |
| 1005 | |
| 1006 | ut_assertok(check_arg(uts, 34, "mary=\"abc def\" arg=123 john def=4", |
| 1007 | buf, "mary=\"abc def\" arg=123 john", "def", |
| 1008 | "4")); |
| 1009 | |
| 1010 | /* quote at the start */ |
| 1011 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 1012 | "mary=\"abc def\" arg=\"123 456\"", |
| 1013 | "arg", "\"4 5 6", NULL)); |
| 1014 | |
| 1015 | /* quote at the end */ |
| 1016 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 1017 | "mary=\"abc def\" arg=\"123 456\"", |
| 1018 | "arg", "4 5 6\"", NULL)); |
| 1019 | |
| 1020 | /* quote in the middle */ |
| 1021 | ut_asserteq(-EBADF, cmdline_set_arg(buf, size, |
| 1022 | "mary=\"abc def\" arg=\"123 456\"", |
| 1023 | "arg", "\"4 \"5 6\"", NULL)); |
| 1024 | |
| 1025 | /* handle updating a quoted arg */ |
| 1026 | ut_assertok(check_arg(uts, 27, "mary=\"abc def\" arg=\"4 5 6\"", buf, |
| 1027 | "mary=\"abc def\" arg=\"123 456\"", "arg", |
| 1028 | "4 5 6")); |
| 1029 | |
| 1030 | /* changing a quoted arg to a non-quoted arg */ |
| 1031 | ut_assertok(check_arg(uts, 23, "mary=\"abc def\" arg=789", buf, |
| 1032 | "mary=\"abc def\" arg=\"123 456\"", "arg", |
| 1033 | "789")); |
| 1034 | |
| 1035 | /* changing a non-quoted arg to a quoted arg */ |
| 1036 | ut_assertok(check_arg(uts, 29, "mary=\"abc def\" arg=\"456 789\"", buf, |
| 1037 | "mary=\"abc def\" arg=123", "arg", "456 789")); |
| 1038 | |
| 1039 | /* handling of spaces */ |
| 1040 | ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123")); |
| 1041 | ut_assertok(check_arg(uts, 8, "arg=123", buf, " ", "arg", "123")); |
| 1042 | ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john ", "arg", |
| 1043 | "123")); |
| 1044 | ut_assertok(check_arg(uts, 13, "john arg=123", buf, " john arg=123 ", |
| 1045 | "arg", "123")); |
| 1046 | ut_assertok(check_arg(uts, 18, "john arg=123 mary", buf, |
| 1047 | " john arg=123 mary ", "arg", "123")); |
| 1048 | |
| 1049 | /* unchanged arg */ |
| 1050 | ut_assertok(check_arg(uts, 3, "me", buf, "me", "me", BOOTFLOWCL_EMPTY)); |
| 1051 | |
| 1052 | /* arg which starts with the same name */ |
| 1053 | ut_assertok(check_arg(uts, 28, "mary=abc johnathon=2 john=3", buf, |
| 1054 | "mary=abc johnathon=2 john=1", "john", "3")); |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |
| 1058 | BOOTSTD_TEST(test_bootflow_cmdline_set, 0); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1059 | |
| 1060 | /* Test of bootflow_cmdline_set_arg() */ |
| 1061 | static int bootflow_set_arg(struct unit_test_state *uts) |
| 1062 | { |
| 1063 | struct bootflow s_bflow, *bflow = &s_bflow; |
| 1064 | ulong mem_start; |
| 1065 | |
| 1066 | ut_assertok(env_set("bootargs", NULL)); |
| 1067 | |
| 1068 | mem_start = ut_check_delta(0); |
| 1069 | |
| 1070 | /* Do a simple sanity check. Rely on bootflow_cmdline() for the rest */ |
| 1071 | bflow->cmdline = NULL; |
| 1072 | ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", "123", false)); |
| 1073 | ut_asserteq_str(bflow->cmdline, "fred=123"); |
| 1074 | |
| 1075 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "and here", false)); |
| 1076 | ut_asserteq_str(bflow->cmdline, "fred=123 mary=\"and here\""); |
| 1077 | |
| 1078 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", NULL, false)); |
| 1079 | ut_asserteq_str(bflow->cmdline, "fred=123"); |
| 1080 | ut_assertok(bootflow_cmdline_set_arg(bflow, "fred", NULL, false)); |
| 1081 | ut_asserteq_ptr(bflow->cmdline, NULL); |
| 1082 | |
| 1083 | ut_asserteq(0, ut_check_delta(mem_start)); |
| 1084 | |
| 1085 | ut_assertok(bootflow_cmdline_set_arg(bflow, "mary", "here", true)); |
| 1086 | ut_asserteq_str("mary=here", env_get("bootargs")); |
| 1087 | ut_assertok(env_set("bootargs", NULL)); |
| 1088 | |
| 1089 | return 0; |
| 1090 | } |
| 1091 | BOOTSTD_TEST(bootflow_set_arg, 0); |
| 1092 | |
| 1093 | /* Test of bootflow_cmdline_get_arg() */ |
| 1094 | static int bootflow_cmdline_get(struct unit_test_state *uts) |
| 1095 | { |
| 1096 | int pos; |
| 1097 | |
| 1098 | /* empty string */ |
| 1099 | ut_asserteq(-ENOENT, cmdline_get_arg("", "fred", &pos)); |
| 1100 | |
| 1101 | /* arg with empty value */ |
| 1102 | ut_asserteq(0, cmdline_get_arg("fred= mary", "fred", &pos)); |
| 1103 | ut_asserteq(5, pos); |
| 1104 | |
| 1105 | /* arg with a value */ |
| 1106 | ut_asserteq(2, cmdline_get_arg("fred=23", "fred", &pos)); |
| 1107 | ut_asserteq(5, pos); |
| 1108 | |
| 1109 | /* arg with a value */ |
| 1110 | ut_asserteq(3, cmdline_get_arg("mary=1 fred=234", "fred", &pos)); |
| 1111 | ut_asserteq(12, pos); |
| 1112 | |
| 1113 | /* arg with a value, after quoted arg */ |
| 1114 | ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=234", "fred", &pos)); |
| 1115 | ut_asserteq(16, pos); |
| 1116 | |
| 1117 | /* arg in the middle */ |
| 1118 | ut_asserteq(0, cmdline_get_arg("mary=\"1 2\" fred john=23", "fred", |
| 1119 | &pos)); |
| 1120 | ut_asserteq(15, pos); |
| 1121 | |
| 1122 | /* quoted arg */ |
| 1123 | ut_asserteq(3, cmdline_get_arg("mary=\"1 2\" fred=\"3 4\" john=23", |
| 1124 | "fred", &pos)); |
| 1125 | ut_asserteq(17, pos); |
| 1126 | |
| 1127 | /* args starting with the same prefix */ |
| 1128 | ut_asserteq(1, cmdline_get_arg("mary=abc johnathon=3 john=1", "john", |
| 1129 | &pos)); |
| 1130 | ut_asserteq(26, pos); |
| 1131 | |
| 1132 | return 0; |
| 1133 | } |
| 1134 | BOOTSTD_TEST(bootflow_cmdline_get, 0); |
| 1135 | |
| 1136 | static int bootflow_cmdline(struct unit_test_state *uts) |
| 1137 | { |
| 1138 | ut_assertok(run_command("bootflow scan mmc", 0)); |
| 1139 | ut_assertok(run_command("bootflow sel 0", 0)); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1140 | |
| 1141 | ut_asserteq(1, run_command("bootflow cmdline get fred", 0)); |
| 1142 | ut_assert_nextline("Argument not found"); |
| 1143 | ut_assert_console_end(); |
| 1144 | |
| 1145 | ut_asserteq(0, run_command("bootflow cmdline set fred 123", 0)); |
| 1146 | ut_asserteq(0, run_command("bootflow cmdline get fred", 0)); |
| 1147 | ut_assert_nextline("123"); |
| 1148 | |
| 1149 | ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0)); |
| 1150 | ut_asserteq(0, run_command("bootflow cmdline get mary", 0)); |
| 1151 | ut_assert_nextline("abc"); |
| 1152 | |
| 1153 | ut_asserteq(0, run_command("bootflow cmdline delete fred", 0)); |
| 1154 | ut_asserteq(1, run_command("bootflow cmdline get fred", 0)); |
| 1155 | ut_assert_nextline("Argument not found"); |
| 1156 | |
| 1157 | ut_asserteq(0, run_command("bootflow cmdline clear mary", 0)); |
| 1158 | ut_asserteq(0, run_command("bootflow cmdline get mary", 0)); |
| 1159 | ut_assert_nextline_empty(); |
| 1160 | |
Simon Glass | 7a164f8 | 2023-11-29 10:31:19 -0700 | [diff] [blame] | 1161 | ut_asserteq(0, run_command("bootflow cmdline set mary abc", 0)); |
| 1162 | ut_asserteq(0, run_command("bootflow cmdline set mary", 0)); |
Simon Glass | 55a2da3 | 2023-07-12 09:04:39 -0600 | [diff] [blame] | 1163 | ut_assert_console_end(); |
| 1164 | |
| 1165 | return 0; |
| 1166 | } |
Simon Glass | f042502 | 2024-08-22 07:57:54 -0600 | [diff] [blame] | 1167 | BOOTSTD_TEST(bootflow_cmdline, UTF_CONSOLE); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1168 | |
Simon Glass | a61057f | 2023-10-25 07:17:36 +1300 | [diff] [blame] | 1169 | /* test a few special changes to a long command line */ |
| 1170 | static int bootflow_cmdline_special(struct unit_test_state *uts) |
| 1171 | { |
| 1172 | char buf[500]; |
| 1173 | int pos; |
| 1174 | |
| 1175 | /* |
| 1176 | * check handling of an argument which has an embedded '=', as well as |
| 1177 | * handling of a argument which partially matches ("ro" and "root") |
| 1178 | */ |
| 1179 | ut_asserteq(32, cmdline_set_arg( |
| 1180 | buf, sizeof(buf), |
| 1181 | "loglevel=7 root=PARTUUID=d68352e3 rootwait ro noinitrd", |
| 1182 | "root", NULL, &pos)); |
| 1183 | ut_asserteq_str("loglevel=7 rootwait ro noinitrd", buf); |
| 1184 | |
| 1185 | return 0; |
| 1186 | } |
| 1187 | BOOTSTD_TEST(bootflow_cmdline_special, 0); |
| 1188 | |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1189 | /* Test ChromiumOS bootmeth */ |
| 1190 | static int bootflow_cros(struct unit_test_state *uts) |
| 1191 | { |
Simon Glass | 3ff8a9a | 2023-10-01 19:14:37 -0600 | [diff] [blame] | 1192 | ut_assertok(scan_mmc_bootdev(uts, "mmc5", true)); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 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"); |
Simon Glass | d7d3a97 | 2023-08-24 13:55:45 -0600 | [diff] [blame] | 1199 | ut_assert_nextlinen(" 1 cros ready mmc 2 mmc5.bootdev.part_2 "); |
| 1200 | ut_assert_nextlinen(" 2 cros ready mmc 4 mmc5.bootdev.part_4 "); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1201 | ut_assert_nextlinen("---"); |
Simon Glass | d7d3a97 | 2023-08-24 13:55:45 -0600 | [diff] [blame] | 1202 | ut_assert_skip_to_line("(3 bootflows, 3 valid)"); |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1203 | |
Simon Glass | c6a52e7 | 2024-11-15 16:19:23 -0700 | [diff] [blame] | 1204 | ut_assertok(run_command("bootstd images", 0)); |
| 1205 | ut_assert_nextlinen("Seq"); |
| 1206 | ut_assert_nextlinen("---"); |
| 1207 | ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg"); |
| 1208 | ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 x86_setup"); |
| 1209 | ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 cmdline"); |
| 1210 | ut_assert_nextlinen(" 1 mmc5.bootdev.part_2 kernel - 4000 kernel"); |
| 1211 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 x86_setup"); |
| 1212 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 cmdline"); |
| 1213 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_4 kernel - 4000 kernel"); |
| 1214 | ut_assert_nextlinen("---"); |
| 1215 | ut_assert_nextline("(7 images)"); |
| 1216 | |
Simon Glass | fff928c | 2023-08-24 13:55:41 -0600 | [diff] [blame] | 1217 | ut_assert_console_end(); |
| 1218 | |
| 1219 | return 0; |
| 1220 | } |
Mattijs Korpershoek | 33342f0 | 2024-11-22 15:11:34 +0100 | [diff] [blame] | 1221 | BOOTSTD_TEST(bootflow_cros, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 1222 | |
Guillaume La Roque | 368ad9e | 2024-11-26 09:06:13 +0100 | [diff] [blame] | 1223 | /* Test Android bootmeth with boot image version 4 */ |
| 1224 | static int bootflow_android_image_v4(struct unit_test_state *uts) |
Mattijs Korpershoek | d77f815 | 2024-07-10 10:40:06 +0200 | [diff] [blame] | 1225 | { |
| 1226 | if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID)) |
| 1227 | return -EAGAIN; |
| 1228 | |
| 1229 | ut_assertok(scan_mmc_android_bootdev(uts, "mmc7")); |
| 1230 | ut_assertok(run_command("bootflow list", 0)); |
| 1231 | |
| 1232 | ut_assert_nextlinen("Showing all"); |
| 1233 | ut_assert_nextlinen("Seq"); |
| 1234 | ut_assert_nextlinen("---"); |
| 1235 | ut_assert_nextlinen(" 0 extlinux"); |
| 1236 | ut_assert_nextlinen(" 1 android ready mmc 0 mmc7.bootdev.whole "); |
| 1237 | ut_assert_nextlinen("---"); |
| 1238 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 1239 | |
| 1240 | ut_assert_console_end(); |
| 1241 | |
| 1242 | return 0; |
| 1243 | } |
Guillaume La Roque | 368ad9e | 2024-11-26 09:06:13 +0100 | [diff] [blame] | 1244 | BOOTSTD_TEST(bootflow_android_image_v4, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); |
| 1245 | |
| 1246 | /* Test Android bootmeth with boot image version 2 */ |
| 1247 | static int bootflow_android_image_v2(struct unit_test_state *uts) |
| 1248 | { |
| 1249 | if (!IS_ENABLED(CONFIG_BOOTMETH_ANDROID)) |
| 1250 | return -EAGAIN; |
| 1251 | |
| 1252 | ut_assertok(scan_mmc_android_bootdev(uts, "mmc8")); |
| 1253 | ut_assertok(run_command("bootflow list", 0)); |
| 1254 | |
| 1255 | ut_assert_nextlinen("Showing all"); |
| 1256 | ut_assert_nextlinen("Seq"); |
| 1257 | ut_assert_nextlinen("---"); |
| 1258 | ut_assert_nextlinen(" 0 extlinux"); |
| 1259 | ut_assert_nextlinen(" 1 android ready mmc 0 mmc8.bootdev.whole "); |
| 1260 | ut_assert_nextlinen("---"); |
| 1261 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 1262 | |
| 1263 | ut_assert_console_end(); |
| 1264 | |
| 1265 | return 0; |
| 1266 | } |
| 1267 | BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT); |
Simon Glass | 4f378de | 2024-11-07 14:31:50 -0700 | [diff] [blame] | 1268 | |
| 1269 | /* Test EFI bootmeth */ |
| 1270 | static int bootflow_efi(struct unit_test_state *uts) |
| 1271 | { |
| 1272 | static const char *order[] = {"mmc1", "usb", NULL}; |
| 1273 | struct bootstd_priv *std; |
| 1274 | struct udevice *bootstd; |
| 1275 | const char **old_order; |
| 1276 | |
| 1277 | ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd)); |
| 1278 | std = dev_get_priv(bootstd); |
| 1279 | old_order = std->bootdev_order; |
| 1280 | std->bootdev_order = order; |
| 1281 | |
| 1282 | /* disable ethernet since the hunter will run dhcp */ |
| 1283 | test_set_eth_enable(false); |
| 1284 | |
| 1285 | /* make USB scan without delays */ |
| 1286 | test_set_skip_delays(true); |
| 1287 | |
| 1288 | bootstd_reset_usb(); |
| 1289 | |
| 1290 | ut_assertok(run_command("bootflow scan", 0)); |
| 1291 | ut_assert_skip_to_line( |
| 1292 | "Bus usb@1: scanning bus usb@1 for devices... 5 USB Device(s) found"); |
| 1293 | |
| 1294 | ut_assertok(run_command("bootflow list", 0)); |
| 1295 | |
| 1296 | ut_assert_nextlinen("Showing all"); |
| 1297 | ut_assert_nextlinen("Seq"); |
| 1298 | ut_assert_nextlinen("---"); |
| 1299 | ut_assert_nextlinen(" 0 extlinux"); |
| 1300 | ut_assert_nextlinen( |
| 1301 | " 1 efi ready usb_mass_ 1 usb_mass_storage.lun0.boo /EFI/BOOT/BOOTSBOX.EFI"); |
| 1302 | ut_assert_nextlinen("---"); |
| 1303 | ut_assert_skip_to_line("(2 bootflows, 2 valid)"); |
| 1304 | ut_assert_console_end(); |
| 1305 | |
| 1306 | ut_assertok(run_command("bootflow select 1", 0)); |
| 1307 | ut_assert_console_end(); |
| 1308 | |
| 1309 | systab.fw_vendor = test_vendor; |
| 1310 | |
| 1311 | ut_asserteq(1, run_command("bootflow boot", 0)); |
| 1312 | ut_assert_nextline( |
| 1313 | "** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi"); |
| 1314 | if (IS_ENABLED(CONFIG_LOGF_FUNC)) |
| 1315 | ut_assert_skip_to_line(" efi_run_image() Booting /\\EFI\\BOOT\\BOOTSBOX.EFI"); |
| 1316 | else |
| 1317 | ut_assert_skip_to_line("Booting /\\EFI\\BOOT\\BOOTSBOX.EFI"); |
| 1318 | |
| 1319 | /* TODO: Why the \r ? */ |
| 1320 | ut_assert_nextline("U-Boot test app for EFI_LOADER\r"); |
| 1321 | ut_assert_nextline("Exiting test app"); |
| 1322 | ut_assert_nextline("Boot failed (err=-14)"); |
| 1323 | |
| 1324 | ut_assert_console_end(); |
| 1325 | |
| 1326 | ut_assertok(bootstd_test_drop_bootdev_order(uts)); |
| 1327 | |
| 1328 | return 0; |
| 1329 | } |
| 1330 | BOOTSTD_TEST(bootflow_efi, UTF_CONSOLE); |
Simon Glass | c6a52e7 | 2024-11-15 16:19:23 -0700 | [diff] [blame] | 1331 | |
| 1332 | /* Check 'bootflow scan' provides a list of images */ |
| 1333 | static int bootstd_images(struct unit_test_state *uts) |
| 1334 | { |
| 1335 | static const char *order[] = {"mmc2", "mmc1", "mmc4", "mmc5", NULL}; |
| 1336 | const struct legacy_img_hdr *hdr; |
| 1337 | const struct bootflow_img *img; |
| 1338 | const struct bootflow *bflow; |
| 1339 | struct bootstd_priv *std; |
| 1340 | const char **old_order; |
| 1341 | struct udevice *dev; |
| 1342 | ofnode root, node; |
| 1343 | ulong data, len; |
| 1344 | char *ptr; |
| 1345 | |
| 1346 | /* get access to the current bootflow */ |
| 1347 | ut_assertok(bootstd_get_priv(&std)); |
| 1348 | |
| 1349 | ut_assertok(prep_mmc_bootdev(uts, "mmc4", true, &old_order)); |
| 1350 | |
| 1351 | /* bind mmc5 too, for cros */ |
| 1352 | root = oftree_root(oftree_default()); |
| 1353 | node = ofnode_find_subnode(root, "mmc5"); |
| 1354 | ut_assert(ofnode_valid(node)); |
| 1355 | ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false)); |
| 1356 | |
| 1357 | std->bootdev_order = order; |
| 1358 | ut_assertok(run_command("bootflow scan", 0)); |
| 1359 | ut_assert_console_end(); |
| 1360 | std->bootdev_order = old_order; |
| 1361 | |
| 1362 | ut_assertok(run_command("bootflow list", 0)); |
| 1363 | ut_assert_skip_to_line("(4 bootflows, 4 valid)"); |
| 1364 | |
| 1365 | ut_assertok(run_command("bootstd images", 0)); |
| 1366 | ut_assert_nextlinen("Seq"); |
| 1367 | ut_assert_nextlinen("---"); |
| 1368 | ut_assert_nextlinen(" 0 mmc1.bootdev.part_1 extlinux_cfg"); |
| 1369 | ut_assert_nextlinen(" 1 mmc4.bootdev.part_1 script"); |
| 1370 | ut_assert_nextlinen(" 1 mmc4.bootdev.part_1 logo"); |
| 1371 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 x86_setup"); |
| 1372 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 cmdline"); |
| 1373 | ut_assert_nextlinen(" 2 mmc5.bootdev.part_2 kernel -"); |
| 1374 | ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 x86_setup"); |
| 1375 | ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 cmdline"); |
| 1376 | ut_assert_nextlinen(" 3 mmc5.bootdev.part_4 kernel -"); |
| 1377 | ut_assert_nextlinen("---"); |
| 1378 | ut_assert_nextline("(9 images)"); |
| 1379 | |
| 1380 | /* check the first image */ |
| 1381 | bflow = alist_get(&std->bootflows, 0, struct bootflow); |
| 1382 | img = alist_get(&bflow->images, 0, struct bootflow_img); |
| 1383 | ut_asserteq_strn("# extlinux.conf", map_sysmem(img->addr, 0)); |
| 1384 | |
| 1385 | /* check the second image */ |
| 1386 | bflow = alist_get(&std->bootflows, 1, struct bootflow); |
| 1387 | img = alist_get(&bflow->images, 0, struct bootflow_img); |
| 1388 | |
| 1389 | /* this is the length of the script in bytes */ |
| 1390 | hdr = map_sysmem(img->addr, 0); |
| 1391 | image_multi_getimg(hdr, 0, &data, &len); |
| 1392 | ptr = (void *)data; |
| 1393 | ut_asserteq_strn("# DO NOT EDIT THIS FILE", ptr); |
| 1394 | |
| 1395 | /* check the ChromiumOS images */ |
| 1396 | bflow = alist_get(&std->bootflows, 2, struct bootflow); |
| 1397 | img = alist_get(&bflow->images, 1, struct bootflow_img); |
| 1398 | ptr = map_sysmem(img->addr, 0); |
| 1399 | ut_asserteq_strn("BOOT_IMAGE=/vmlinuz-5.15.0-121-generic root=", ptr); |
| 1400 | |
| 1401 | /* |
| 1402 | * the x86 setup is not a real binary, so just check that it is empty, |
| 1403 | * so that if this changes in the future someone will notice and update |
| 1404 | * this test |
| 1405 | */ |
| 1406 | img = alist_get(&bflow->images, 0, struct bootflow_img); |
| 1407 | ptr = map_sysmem(img->addr, 0); |
| 1408 | ut_asserteq(0, *(ulong *)ptr); |
| 1409 | |
| 1410 | ut_assert_console_end(); |
| 1411 | |
| 1412 | return 0; |
| 1413 | } |
| 1414 | BOOTSTD_TEST(bootstd_images, UTF_CONSOLE); |