blob: b71ec52eb7a18c445b0fefee72e9e488f32d2d69 [file] [log] [blame]
Simon Glassfb1451b2022-04-24 23:31:24 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Test for bootdev functions. All start with 'bootdev'
4 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
10#include <bootdev.h>
11#include <bootflow.h>
Simon Glass0917f772022-07-30 15:52:34 -060012#include <bootmeth.h>
Simon Glassfb1451b2022-04-24 23:31:24 -060013#include <bootstd.h>
Simon Glassd985f1d2023-01-06 08:52:41 -060014#include <cli.h>
Simon Glassfb1451b2022-04-24 23:31:24 -060015#include <dm.h>
Simon Glasse64c2952023-01-06 08:52:42 -060016#include <expo.h>
Simon Glass11361c52022-07-30 15:52:36 -060017#ifdef CONFIG_SANDBOX
Simon Glass2662b542022-07-30 15:52:22 -060018#include <asm/test.h>
Simon Glass11361c52022-07-30 15:52:36 -060019#endif
Simon Glassd985f1d2023-01-06 08:52:41 -060020#include <dm/device-internal.h>
Simon Glassfb1451b2022-04-24 23:31:24 -060021#include <dm/lists.h>
22#include <test/suites.h>
23#include <test/ut.h>
24#include "bootstd_common.h"
Simon Glasse64c2952023-01-06 08:52:42 -060025#include "../../boot/bootflow_internal.h"
26#include "../../boot/scene_internal.h"
Simon Glassfb1451b2022-04-24 23:31:24 -060027
Simon Glassd985f1d2023-01-06 08:52:41 -060028DECLARE_GLOBAL_DATA_PTR;
29
30extern U_BOOT_DRIVER(bootmeth_script);
31
Simon Glassf25f5752022-07-30 15:52:16 -060032static int inject_response(struct unit_test_state *uts)
33{
34 /*
35 * The image being booted presents a menu of options:
36 *
37 * Fedora-Workstation-armhfp-31-1.9 Boot Options.
38 * 1: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
39 * Enter choice:
40 *
41 * Provide input for this, to avoid waiting two seconds for a timeout.
42 */
43 ut_asserteq(2, console_in_puts("1\n"));
44
45 return 0;
46}
47
Simon Glassfb1451b2022-04-24 23:31:24 -060048/* Check 'bootflow scan/list' commands */
49static int bootflow_cmd(struct unit_test_state *uts)
50{
51 console_record_reset_enable();
52 ut_assertok(run_command("bootdev select 1", 0));
53 ut_assert_console_end();
54 ut_assertok(run_command("bootflow scan -l", 0));
55 ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'");
56 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
57 ut_assert_nextlinen("---");
58 ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
59 ut_assert_nextlinen("---");
60 ut_assert_nextline("(1 bootflow, 1 valid)");
61 ut_assert_console_end();
62
63 ut_assertok(run_command("bootflow list", 0));
64 ut_assert_nextline("Showing bootflows for bootdev 'mmc1.bootdev'");
65 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
66 ut_assert_nextlinen("---");
67 ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
68 ut_assert_nextlinen("---");
69 ut_assert_nextline("(1 bootflow, 1 valid)");
70 ut_assert_console_end();
71
72 return 0;
73}
74BOOTSTD_TEST(bootflow_cmd, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
75
76/* Check 'bootflow scan' with a name / label / seq */
77static int bootflow_cmd_label(struct unit_test_state *uts)
78{
79 console_record_reset_enable();
80 ut_assertok(run_command("bootflow scan -l mmc1", 0));
81 ut_assert_nextline("Scanning for bootflows in bootdev 'mmc1.bootdev'");
82 ut_assert_skip_to_line("(1 bootflow, 1 valid)");
83 ut_assert_console_end();
84
85 ut_assertok(run_command("bootflow scan -l mmc0.bootdev", 0));
86 ut_assert_nextline("Scanning for bootflows in bootdev 'mmc0.bootdev'");
87 ut_assert_skip_to_line("(0 bootflows, 0 valid)");
88 ut_assert_console_end();
89
90 ut_assertok(run_command("bootflow scan -l 0", 0));
91 ut_assert_nextline("Scanning for bootflows in bootdev 'mmc2.bootdev'");
92 ut_assert_skip_to_line("(0 bootflows, 0 valid)");
93 ut_assert_console_end();
94
95 return 0;
96}
97BOOTSTD_TEST(bootflow_cmd_label, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
98
99/* Check 'bootflow scan/list' commands using all bootdevs */
100static int bootflow_cmd_glob(struct unit_test_state *uts)
101{
102 ut_assertok(bootstd_test_drop_bootdev_order(uts));
103
104 console_record_reset_enable();
Simon Glass0917f772022-07-30 15:52:34 -0600105 ut_assertok(run_command("bootflow scan -lG", 0));
Simon Glassfb1451b2022-04-24 23:31:24 -0600106 ut_assert_nextline("Scanning for bootflows in all bootdevs");
107 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
108 ut_assert_nextlinen("---");
109 ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
110 ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
111 ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
112 ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
113 ut_assert_nextline("No more bootdevs");
114 ut_assert_nextlinen("---");
115 ut_assert_nextline("(1 bootflow, 1 valid)");
116 ut_assert_console_end();
117
118 ut_assertok(run_command("bootflow list", 0));
119 ut_assert_nextline("Showing all bootflows");
120 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
121 ut_assert_nextlinen("---");
122 ut_assert_nextline(" 0 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
123 ut_assert_nextlinen("---");
124 ut_assert_nextline("(1 bootflow, 1 valid)");
125 ut_assert_console_end();
126
127 return 0;
128}
129BOOTSTD_TEST(bootflow_cmd_glob, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
130
131/* Check 'bootflow scan -e' */
132static int bootflow_cmd_scan_e(struct unit_test_state *uts)
133{
134 ut_assertok(bootstd_test_drop_bootdev_order(uts));
135
136 console_record_reset_enable();
Simon Glass0917f772022-07-30 15:52:34 -0600137 ut_assertok(run_command("bootflow scan -aleG", 0));
Simon Glassfb1451b2022-04-24 23:31:24 -0600138 ut_assert_nextline("Scanning for bootflows in all bootdevs");
139 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
140 ut_assert_nextlinen("---");
141 ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
142 ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>");
143 ut_assert_nextline(" ** No partition found, err=-93");
144 ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>");
145 ut_assert_nextline(" ** No partition found, err=-93");
146
147 ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
148 ut_assert_nextline(" 2 syslinux media mmc 0 mmc1.bootdev.whole <NULL>");
149 ut_assert_nextline(" ** No partition found, err=-2");
150 ut_assert_nextline(" 3 efi media mmc 0 mmc1.bootdev.whole <NULL>");
151 ut_assert_nextline(" ** No partition found, err=-2");
152 ut_assert_nextline(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
153 ut_assert_nextline(" 5 efi fs mmc 1 mmc1.bootdev.part_1 efi/boot/bootsbox.efi");
154
155 ut_assert_skip_to_line("Scanning bootdev 'mmc0.bootdev':");
156 ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>");
157 ut_assert_nextline(" ** No partition found, err=-93");
158 ut_assert_nextline("No more bootdevs");
159 ut_assert_nextlinen("---");
160 ut_assert_nextline("(64 bootflows, 1 valid)");
161 ut_assert_console_end();
162
163 ut_assertok(run_command("bootflow list", 0));
164 ut_assert_nextline("Showing all bootflows");
165 ut_assert_nextline("Seq Method State Uclass Part Name Filename");
166 ut_assert_nextlinen("---");
167 ut_assert_nextline(" 0 syslinux media mmc 0 mmc2.bootdev.whole <NULL>");
168 ut_assert_nextline(" 1 efi media mmc 0 mmc2.bootdev.whole <NULL>");
169 ut_assert_skip_to_line(" 4 syslinux ready mmc 1 mmc1.bootdev.part_1 /extlinux/extlinux.conf");
170 ut_assert_skip_to_line(" 3f efi media mmc 0 mmc0.bootdev.whole <NULL>");
171 ut_assert_nextlinen("---");
172 ut_assert_nextline("(64 bootflows, 1 valid)");
173 ut_assert_console_end();
174
175 return 0;
176}
177BOOTSTD_TEST(bootflow_cmd_scan_e, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
178
179/* Check 'bootflow info' */
180static int bootflow_cmd_info(struct unit_test_state *uts)
181{
182 console_record_reset_enable();
183 ut_assertok(run_command("bootdev select 1", 0));
184 ut_assert_console_end();
185 ut_assertok(run_command("bootflow scan", 0));
186 ut_assert_console_end();
187 ut_assertok(run_command("bootflow select 0", 0));
188 ut_assert_console_end();
189 ut_assertok(run_command("bootflow info", 0));
190 ut_assert_nextline("Name: mmc1.bootdev.part_1");
191 ut_assert_nextline("Device: mmc1.bootdev");
192 ut_assert_nextline("Block dev: mmc1.blk");
193 ut_assert_nextline("Method: syslinux");
194 ut_assert_nextline("State: ready");
195 ut_assert_nextline("Partition: 1");
196 ut_assert_nextline("Subdir: (none)");
197 ut_assert_nextline("Filename: /extlinux/extlinux.conf");
198 ut_assert_nextlinen("Buffer: ");
199 ut_assert_nextline("Size: 253 (595 bytes)");
Simon Glass2175e762023-01-06 08:52:33 -0600200 ut_assert_nextline("OS: Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)");
Simon Glass24d8e1b2023-01-06 08:52:34 -0600201 ut_assert_nextline("Logo: (none)");
Simon Glass7638c852023-01-17 10:47:56 -0700202 ut_assert_nextline("FDT: <NULL>");
Simon Glassfb1451b2022-04-24 23:31:24 -0600203 ut_assert_nextline("Error: 0");
204 ut_assert_console_end();
205
206 ut_assertok(run_command("bootflow info -d", 0));
207 ut_assert_nextline("Name: mmc1.bootdev.part_1");
208 ut_assert_skip_to_line("Error: 0");
209 ut_assert_nextline("Contents:");
210 ut_assert_nextline("%s", "");
211 ut_assert_nextline("# extlinux.conf generated by appliance-creator");
212 ut_assert_skip_to_line(" initrd /initramfs-5.3.7-301.fc31.armv7hl.img");
213 ut_assert_console_end();
214
215 return 0;
216}
217BOOTSTD_TEST(bootflow_cmd_info, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
218
219/* Check 'bootflow scan -b' to boot the first available bootdev */
220static int bootflow_scan_boot(struct unit_test_state *uts)
221{
222 console_record_reset_enable();
Simon Glassf25f5752022-07-30 15:52:16 -0600223 ut_assertok(inject_response(uts));
Simon Glassfb1451b2022-04-24 23:31:24 -0600224 ut_assertok(run_command("bootflow scan -b", 0));
225 ut_assert_nextline(
226 "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
227 ut_assert_nextline("Ignoring unknown command: ui");
228
229 /*
230 * We expect it to get through to boot although sandbox always returns
231 * -EFAULT as it cannot actually boot the kernel
232 */
233 ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux");
234 ut_assert_nextline("Boot failed (err=-14)");
235 ut_assert_console_end();
236
237 return 0;
238}
239BOOTSTD_TEST(bootflow_scan_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
240
241/* Check iterating through available bootflows */
242static int bootflow_iter(struct unit_test_state *uts)
243{
244 struct bootflow_iter iter;
245 struct bootflow bflow;
246
247 bootstd_clear_glob();
248
249 /* The first device is mmc2.bootdev which has no media */
250 ut_asserteq(-EPROTONOSUPPORT,
Simon Glass0917f772022-07-30 15:52:34 -0600251 bootflow_scan_first(&iter, BOOTFLOWF_ALL | BOOTFLOWF_SKIP_GLOBAL, &bflow));
Simon Glassfb1451b2022-04-24 23:31:24 -0600252 ut_asserteq(2, iter.num_methods);
253 ut_asserteq(0, iter.cur_method);
254 ut_asserteq(0, iter.part);
255 ut_asserteq(0, iter.max_part);
256 ut_asserteq_str("syslinux", iter.method->name);
257 ut_asserteq(0, bflow.err);
258
259 /*
Simon Glass0917f772022-07-30 15:52:34 -0600260 * This shows MEDIA even though there is none, since in
Simon Glassfb1451b2022-04-24 23:31:24 -0600261 * bootdev_find_in_blk() we call part_get_info() which returns
262 * -EPROTONOSUPPORT. Ideally it would return -EEOPNOTSUPP and we would
263 * know.
264 */
265 ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
266
267 ut_asserteq(-EPROTONOSUPPORT, bootflow_scan_next(&iter, &bflow));
268 ut_asserteq(2, iter.num_methods);
269 ut_asserteq(1, iter.cur_method);
270 ut_asserteq(0, iter.part);
271 ut_asserteq(0, iter.max_part);
272 ut_asserteq_str("efi", iter.method->name);
273 ut_asserteq(0, bflow.err);
274 ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
275 bootflow_free(&bflow);
276
277 /* The next device is mmc1.bootdev - at first we use the whole device */
278 ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
279 ut_asserteq(2, iter.num_methods);
280 ut_asserteq(0, iter.cur_method);
281 ut_asserteq(0, iter.part);
282 ut_asserteq(0x1e, iter.max_part);
283 ut_asserteq_str("syslinux", iter.method->name);
284 ut_asserteq(0, bflow.err);
285 ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
286 bootflow_free(&bflow);
287
288 ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
289 ut_asserteq(2, iter.num_methods);
290 ut_asserteq(1, iter.cur_method);
291 ut_asserteq(0, iter.part);
292 ut_asserteq(0x1e, iter.max_part);
293 ut_asserteq_str("efi", iter.method->name);
294 ut_asserteq(0, bflow.err);
295 ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
296 bootflow_free(&bflow);
297
298 /* Then more to partition 1 where we find something */
299 ut_assertok(bootflow_scan_next(&iter, &bflow));
300 ut_asserteq(2, iter.num_methods);
301 ut_asserteq(0, iter.cur_method);
302 ut_asserteq(1, iter.part);
303 ut_asserteq(0x1e, iter.max_part);
304 ut_asserteq_str("syslinux", iter.method->name);
305 ut_asserteq(0, bflow.err);
306 ut_asserteq(BOOTFLOWST_READY, bflow.state);
307 bootflow_free(&bflow);
308
309 ut_asserteq(-ENOENT, bootflow_scan_next(&iter, &bflow));
310 ut_asserteq(2, iter.num_methods);
311 ut_asserteq(1, iter.cur_method);
312 ut_asserteq(1, iter.part);
313 ut_asserteq(0x1e, iter.max_part);
314 ut_asserteq_str("efi", iter.method->name);
315 ut_asserteq(0, bflow.err);
316 ut_asserteq(BOOTFLOWST_FS, bflow.state);
317 bootflow_free(&bflow);
318
Simon Glassdcffa442023-01-17 10:47:41 -0700319 /* Then more to partition 2 which exists but is not bootable */
Simon Glassf0e358f2023-01-17 10:47:42 -0700320 ut_asserteq(-EINVAL, bootflow_scan_next(&iter, &bflow));
Simon Glassfb1451b2022-04-24 23:31:24 -0600321 ut_asserteq(2, iter.num_methods);
322 ut_asserteq(0, iter.cur_method);
323 ut_asserteq(2, iter.part);
324 ut_asserteq(0x1e, iter.max_part);
325 ut_asserteq_str("syslinux", iter.method->name);
326 ut_asserteq(0, bflow.err);
Simon Glassf0e358f2023-01-17 10:47:42 -0700327 ut_asserteq(BOOTFLOWST_MEDIA, bflow.state);
Simon Glassfb1451b2022-04-24 23:31:24 -0600328 bootflow_free(&bflow);
329
330 bootflow_iter_uninit(&iter);
331
332 ut_assert_console_end();
333
334 return 0;
335}
336BOOTSTD_TEST(bootflow_iter, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
337
Simon Glass11361c52022-07-30 15:52:36 -0600338#if defined(CONFIG_SANDBOX) && defined(CONFIG_BOOTMETH_GLOBAL)
Simon Glassfb1451b2022-04-24 23:31:24 -0600339/* Check using the system bootdev */
340static int bootflow_system(struct unit_test_state *uts)
341{
Simon Glassecb274c2023-01-17 10:47:23 -0700342 struct udevice *bootstd, *dev;
Simon Glassfb1451b2022-04-24 23:31:24 -0600343
Simon Glassae0bf222022-10-11 09:47:20 -0600344 if (!IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR))
Simon Glassc43635b2022-10-20 18:22:49 -0600345 return -EAGAIN;
Simon Glassecb274c2023-01-17 10:47:23 -0700346 ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
347 ut_assertok(device_bind(bootstd, DM_DRIVER_GET(bootmeth_efi_mgr),
348 "efi_mgr", 0, ofnode_null(), &dev));
349 ut_assertok(device_probe(dev));
Simon Glass2662b542022-07-30 15:52:22 -0600350 sandbox_set_fake_efi_mgr_dev(dev, true);
Simon Glassfb1451b2022-04-24 23:31:24 -0600351
Simon Glassfb1451b2022-04-24 23:31:24 -0600352 /* We should get a single 'bootmgr' method right at the end */
353 bootstd_clear_glob();
354 console_record_reset_enable();
355 ut_assertok(run_command("bootflow scan -l", 0));
Simon Glassc627cfc2022-07-30 15:52:27 -0600356 ut_assert_skip_to_line(
Simon Glassbd18b692022-07-30 15:52:28 -0600357 " 0 efi_mgr ready (none) 0 <NULL> <NULL>");
Simon Glassc627cfc2022-07-30 15:52:27 -0600358 ut_assert_skip_to_line("No more bootdevs");
Simon Glassecb274c2023-01-17 10:47:23 -0700359 ut_assert_skip_to_line("(2 bootflows, 2 valid)");
Simon Glassfb1451b2022-04-24 23:31:24 -0600360 ut_assert_console_end();
361
362 return 0;
363}
Simon Glassbd18b692022-07-30 15:52:28 -0600364BOOTSTD_TEST(bootflow_system, UT_TESTF_DM | UT_TESTF_SCAN_PDATA |
365 UT_TESTF_SCAN_FDT);
Simon Glass11361c52022-07-30 15:52:36 -0600366#endif
Simon Glassfb1451b2022-04-24 23:31:24 -0600367
368/* Check disabling a bootmethod if it requests it */
369static int bootflow_iter_disable(struct unit_test_state *uts)
370{
371 struct udevice *bootstd, *dev;
372 struct bootflow_iter iter;
373 struct bootflow bflow;
374 int i;
375
376 /* Add the EFI bootmgr driver */
377 ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
378 ut_assertok(device_bind_driver(bootstd, "bootmeth_sandbox", "sandbox",
379 &dev));
380
Simon Glassfb1451b2022-04-24 23:31:24 -0600381 ut_assertok(bootstd_test_drop_bootdev_order(uts));
382
383 bootstd_clear_glob();
Simon Glassf25f5752022-07-30 15:52:16 -0600384 console_record_reset_enable();
385 ut_assertok(inject_response(uts));
Simon Glassfb1451b2022-04-24 23:31:24 -0600386 ut_assertok(run_command("bootflow scan -lb", 0));
387
388 /* Try to boot the bootmgr flow, which will fail */
389 console_record_reset_enable();
390 ut_assertok(bootflow_scan_first(&iter, 0, &bflow));
391 ut_asserteq(3, iter.num_methods);
392 ut_asserteq_str("sandbox", iter.method->name);
Simon Glassf25f5752022-07-30 15:52:16 -0600393 ut_assertok(inject_response(uts));
Simon Glassfb1451b2022-04-24 23:31:24 -0600394 ut_asserteq(-ENOTSUPP, bootflow_run_boot(&iter, &bflow));
395
396 ut_assert_skip_to_line("Boot method 'sandbox' failed and will not be retried");
397 ut_assert_console_end();
398
399 /* Check that the sandbox bootmeth has been removed */
400 ut_asserteq(2, iter.num_methods);
401 for (i = 0; i < iter.num_methods; i++)
402 ut_assert(strcmp("sandbox", iter.method_order[i]->name));
403
404 return 0;
405}
406BOOTSTD_TEST(bootflow_iter_disable, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
407
Simon Glass0917f772022-07-30 15:52:34 -0600408/* Check 'bootflow scan' with a bootmeth ordering including a global bootmeth */
409static int bootflow_scan_glob_bootmeth(struct unit_test_state *uts)
410{
Simon Glass11361c52022-07-30 15:52:36 -0600411 if (!IS_ENABLED(CONFIG_BOOTMETH_GLOBAL))
Simon Glassc43635b2022-10-20 18:22:49 -0600412 return -EAGAIN;
Simon Glass11361c52022-07-30 15:52:36 -0600413
Simon Glass0917f772022-07-30 15:52:34 -0600414 ut_assertok(bootstd_test_drop_bootdev_order(uts));
415
416 /*
417 * Make sure that the -G flag makes the scan fail, since this is not
418 * supported when an ordering is provided
419 */
420 console_record_reset_enable();
421 ut_assertok(bootmeth_set_order("efi firmware0"));
422 ut_assertok(run_command("bootflow scan -lG", 0));
423 ut_assert_nextline("Scanning for bootflows in all bootdevs");
424 ut_assert_nextline(
425 "Seq Method State Uclass Part Name Filename");
426 ut_assert_nextlinen("---");
427 ut_assert_nextlinen("---");
428 ut_assert_nextline("(0 bootflows, 0 valid)");
429 ut_assert_console_end();
430
431 ut_assertok(run_command("bootflow scan -l", 0));
432 ut_assert_nextline("Scanning for bootflows in all bootdevs");
433 ut_assert_nextline(
434 "Seq Method State Uclass Part Name Filename");
435 ut_assert_nextlinen("---");
436 ut_assert_nextline("Scanning global bootmeth 'firmware0':");
437 ut_assert_nextline("Scanning bootdev 'mmc2.bootdev':");
438 ut_assert_nextline("Scanning bootdev 'mmc1.bootdev':");
439 ut_assert_nextline("Scanning bootdev 'mmc0.bootdev':");
440 ut_assert_nextline("No more bootdevs");
441 ut_assert_nextlinen("---");
442 ut_assert_nextline("(0 bootflows, 0 valid)");
443 ut_assert_console_end();
444
445 return 0;
446}
447BOOTSTD_TEST(bootflow_scan_glob_bootmeth, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
448
Simon Glassfb1451b2022-04-24 23:31:24 -0600449/* Check 'bootflow boot' to boot a selected bootflow */
450static int bootflow_cmd_boot(struct unit_test_state *uts)
451{
452 console_record_reset_enable();
453 ut_assertok(run_command("bootdev select 1", 0));
454 ut_assert_console_end();
455 ut_assertok(run_command("bootflow scan", 0));
456 ut_assert_console_end();
457 ut_assertok(run_command("bootflow select 0", 0));
458 ut_assert_console_end();
Simon Glassf25f5752022-07-30 15:52:16 -0600459
460 ut_assertok(inject_response(uts));
Simon Glassfb1451b2022-04-24 23:31:24 -0600461 ut_asserteq(1, run_command("bootflow boot", 0));
462 ut_assert_nextline(
463 "** Booting bootflow 'mmc1.bootdev.part_1' with syslinux");
464 ut_assert_nextline("Ignoring unknown command: ui");
465
466 /*
467 * We expect it to get through to boot although sandbox always returns
468 * -EFAULT as it cannot actually boot the kernel
469 */
470 ut_assert_skip_to_line("sandbox: continuing, as we cannot run Linux");
471 ut_assert_nextline("Boot failed (err=-14)");
472 ut_assert_console_end();
473
474 return 0;
475}
476BOOTSTD_TEST(bootflow_cmd_boot, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
Simon Glassd985f1d2023-01-06 08:52:41 -0600477
Simon Glasse64c2952023-01-06 08:52:42 -0600478/**
479 * prep_mmc4_bootdev() - Set up the mmc4 bootdev so we can access a fake Armbian
480 *
481 * @uts: Unit test state
482 * Returns 0 on success, -ve on failure
483 */
484static int prep_mmc4_bootdev(struct unit_test_state *uts)
Simon Glassd985f1d2023-01-06 08:52:41 -0600485{
486 static const char *order[] = {"mmc2", "mmc1", "mmc4", NULL};
487 struct udevice *dev, *bootstd;
488 struct bootstd_priv *std;
489 const char **old_order;
Simon Glassd985f1d2023-01-06 08:52:41 -0600490 ofnode node;
491
492 /* Enable the mmc4 node since we need a second bootflow */
493 node = ofnode_path("/mmc4");
494 ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
495
496 /* Enable the script bootmeth too */
497 ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
498 ut_assertok(device_bind(bootstd, DM_DRIVER_REF(bootmeth_script),
499 "bootmeth_script", 0, ofnode_null(), &dev));
500
501 /* Change the order to include mmc4 */
502 std = dev_get_priv(bootstd);
503 old_order = std->bootdev_order;
504 std->bootdev_order = order;
505
506 console_record_reset_enable();
507 ut_assertok(run_command("bootflow scan", 0));
508 ut_assert_console_end();
509
510 /* Restore the order used by the device tree */
511 std->bootdev_order = old_order;
512
Simon Glasse64c2952023-01-06 08:52:42 -0600513 return 0;
514}
515
516/* Check 'bootflow menu' to select a bootflow */
517static int bootflow_cmd_menu(struct unit_test_state *uts)
518{
519 char prev[3];
520
521 ut_assertok(prep_mmc4_bootdev(uts));
522
Simon Glassd985f1d2023-01-06 08:52:41 -0600523 /* Add keypresses to move to and select the second one in the list */
524 prev[0] = CTL_CH('n');
525 prev[1] = '\r';
526 prev[2] = '\0';
527 ut_asserteq(2, console_in_puts(prev));
528
529 ut_assertok(run_command("bootflow menu", 0));
530 ut_assert_nextline("Selected: Armbian");
531 ut_assert_console_end();
532
533 return 0;
534}
535BOOTSTD_TEST(bootflow_cmd_menu, UT_TESTF_DM | UT_TESTF_SCAN_FDT);
Simon Glasse64c2952023-01-06 08:52:42 -0600536
537/**
538 * check_font() - Check that the font size for an item matches expectations
539 *
540 * @uts: Unit test state
541 * @scn: Scene containing the text object
542 * @id: ID of the text object
543 * Returns 0 on success, -ve on failure
544 */
545static int check_font(struct unit_test_state *uts, struct scene *scn, uint id,
546 int font_size)
547{
548 struct scene_obj_txt *txt;
549
550 txt = scene_obj_find(scn, id, SCENEOBJT_TEXT);
551 ut_assertnonnull(txt);
552
553 ut_asserteq(font_size, txt->font_size);
554
555 return 0;
556}
557
558/* Check themes work with a bootflow menu */
559static int bootflow_menu_theme(struct unit_test_state *uts)
560{
561 const int font_size = 30;
562 struct scene *scn;
563 struct expo *exp;
564 ofnode node;
565 int i;
566
567 ut_assertok(prep_mmc4_bootdev(uts));
568
569 ut_assertok(bootflow_menu_new(&exp));
570 node = ofnode_path("/bootstd/theme");
571 ut_assert(ofnode_valid(node));
572 ut_assertok(bootflow_menu_apply_theme(exp, node));
573
574 scn = expo_lookup_scene_id(exp, MAIN);
575 ut_assertnonnull(scn);
576
577 /*
578 * Check that the txt objects have the correct font size from the
579 * device tree node: bootstd/theme
580 *
581 * Check both menu items, since there are two bootflows
582 */
583 ut_assertok(check_font(uts, scn, OBJ_PROMPT, font_size));
584 ut_assertok(check_font(uts, scn, OBJ_POINTER, font_size));
585 for (i = 0; i < 2; i++) {
586 ut_assertok(check_font(uts, scn, ITEM_DESC + i, font_size));
587 ut_assertok(check_font(uts, scn, ITEM_KEY + i, font_size));
588 ut_assertok(check_font(uts, scn, ITEM_LABEL + i, font_size));
589 }
590
591 expo_destroy(exp);
592
593 return 0;
594}
595BOOTSTD_TEST(bootflow_menu_theme, UT_TESTF_DM | UT_TESTF_SCAN_FDT);