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