Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Test for coreboot commands |
| 4 | * |
| 5 | * Copyright 2023 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 9 | #include <cedit.h> |
Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | 47f3652 | 2024-10-14 16:32:10 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 12 | #include <expo.h> |
Simon Glass | 47f3652 | 2024-10-14 16:32:10 -0600 | [diff] [blame] | 13 | #include <rtc.h> |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 14 | #include <test/cedit-test.h> |
Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 15 | #include <test/cmd.h> |
| 16 | #include <test/test.h> |
| 17 | #include <test/ut.h> |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 18 | #include "../../boot/scene_internal.h" |
Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 19 | |
Simon Glass | 47f3652 | 2024-10-14 16:32:10 -0600 | [diff] [blame] | 20 | enum { |
| 21 | CSUM_LOC = 0x3f0 / 8, |
| 22 | }; |
| 23 | |
Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 24 | /** |
| 25 | * test_cmd_cbsysinfo() - test the cbsysinfo command produces expected output |
| 26 | * |
| 27 | * This includes ensuring that the coreboot build has the expected options |
| 28 | * enabled |
| 29 | */ |
| 30 | static int test_cmd_cbsysinfo(struct unit_test_state *uts) |
| 31 | { |
| 32 | ut_assertok(run_command("cbsysinfo", 0)); |
| 33 | ut_assert_nextlinen("Coreboot table at"); |
| 34 | |
Simon Glass | b57a23b | 2024-10-14 16:32:08 -0600 | [diff] [blame] | 35 | /* Make sure CMOS options are enabled */ |
| 36 | ut_assert_skip_to_line( |
| 37 | " 1c0 1 e 1 power_on_after_fail 0:Disable 1:Enable"); |
| 38 | ut_assert_skip_to_line("CMOS start : 1c0"); |
| 39 | ut_assert_nextline(" CMOS end : 1cf"); |
| 40 | ut_assert_nextline(" CMOS csum loc: 3f0"); |
| 41 | |
Simon Glass | 8ec684c | 2024-10-14 16:32:07 -0600 | [diff] [blame] | 42 | /* Make sure the linear frame buffer is enabled */ |
| 43 | ut_assert_skip_to_linen("Framebuffer"); |
| 44 | ut_assert_nextlinen(" Phys addr"); |
| 45 | |
| 46 | ut_assert_skip_to_line("Chrome OS VPD: 00000000"); |
| 47 | ut_assert_nextlinen("RSDP"); |
| 48 | ut_assert_nextlinen("Unimpl."); |
| 49 | ut_assert_console_end(); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | CMD_TEST(test_cmd_cbsysinfo, UTF_CONSOLE); |
Simon Glass | 47f3652 | 2024-10-14 16:32:10 -0600 | [diff] [blame] | 54 | |
| 55 | /* test cbcmos command */ |
| 56 | static int test_cmd_cbcmos(struct unit_test_state *uts) |
| 57 | { |
| 58 | u16 old_csum, new_csum; |
| 59 | struct udevice *dev; |
| 60 | |
| 61 | /* initially the checksum should be correct */ |
| 62 | ut_assertok(run_command("cbcmos check", 0)); |
| 63 | ut_assert_console_end(); |
| 64 | |
| 65 | /* make a change to the checksum */ |
| 66 | ut_assertok(uclass_first_device_err(UCLASS_RTC, &dev)); |
| 67 | ut_assertok(rtc_read16(dev, CSUM_LOC, &old_csum)); |
| 68 | ut_assertok(rtc_write16(dev, CSUM_LOC, old_csum + 1)); |
| 69 | |
| 70 | /* now the command should fail */ |
| 71 | ut_asserteq(1, run_command("cbcmos check", 0)); |
| 72 | ut_assert_nextline("Checksum %04x error: calculated %04x", |
| 73 | old_csum + 1, old_csum); |
| 74 | ut_assert_console_end(); |
| 75 | |
| 76 | /* now get it to fix the checksum */ |
| 77 | ut_assertok(run_command("cbcmos update", 0)); |
| 78 | ut_assert_nextline("Checksum %04x written", old_csum); |
| 79 | ut_assert_console_end(); |
| 80 | |
| 81 | /* check the RTC looks right */ |
| 82 | ut_assertok(rtc_read16(dev, CSUM_LOC, &new_csum)); |
| 83 | ut_asserteq(old_csum, new_csum); |
| 84 | ut_assert_console_end(); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | CMD_TEST(test_cmd_cbcmos, UTF_CONSOLE); |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 89 | |
| 90 | /* test 'cedit cb_load' command */ |
| 91 | static int test_cmd_cedit_cb_load(struct unit_test_state *uts) |
| 92 | { |
| 93 | struct scene_obj_menu *menu; |
| 94 | struct video_priv *vid_priv; |
| 95 | struct scene_obj_txt *txt; |
| 96 | struct scene *scn; |
| 97 | struct expo *exp; |
| 98 | int scn_id; |
| 99 | |
| 100 | ut_assertok(run_command("cedit cb_load", 0)); |
| 101 | ut_assertok(run_command("cedit read_cmos", 0)); |
| 102 | ut_assert_console_end(); |
| 103 | |
| 104 | exp = cur_exp; |
| 105 | scn_id = cedit_prepare(exp, &vid_priv, &scn); |
| 106 | ut_assert(scn_id > 0); |
| 107 | ut_assertnonnull(scn); |
| 108 | |
| 109 | /* just do a very basic test that the first menu is present */ |
| 110 | menu = scene_obj_find(scn, scn->highlight_id, SCENEOBJT_NONE); |
| 111 | ut_assertnonnull(menu); |
| 112 | |
| 113 | txt = scene_obj_find(scn, menu->title_id, SCENEOBJT_NONE); |
| 114 | ut_assertnonnull(txt); |
| 115 | ut_asserteq_str("Boot option", expo_get_str(exp, txt->str_id)); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | CMD_TEST(test_cmd_cedit_cb_load, UTF_CONSOLE); |