
Add a VBE command which shows the current state. Currently this is just the phases which booted via VBE.
Signed-off-by: Simon Glass sjg@chromium.org ---
cmd/vbe.c | 30 +++++++++++++++++++++++++++++- doc/usage/cmd/vbe.rst | 13 +++++++++++++ include/spl.h | 2 ++ test/boot/vbe.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/cmd/vbe.c b/cmd/vbe.c index a5737edc047..16700af6202 100644 --- a/cmd/vbe.c +++ b/cmd/vbe.c @@ -7,9 +7,11 @@ */
#include <common.h> +#include <bloblist.h> #include <bootmeth.h> #include <bootstd.h> #include <command.h> +#include <spl.h> #include <vbe.h>
static int do_vbe_list(struct cmd_tbl *cmdtp, int flag, int argc, @@ -74,14 +76,40 @@ static int do_vbe_info(struct cmd_tbl *cmdtp, int flag, int argc, return 0; }
+static int do_vbe_state(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct vbe_handoff *handoff; + int i; + + handoff = bloblist_find(BLOBLISTT_VBE, sizeof(struct vbe_handoff)); + if (!handoff) { + printf("No VBE state\n"); + return CMD_RET_FAILURE; + } + + printf("Phases:"); + for (i = PHASE_NONE; i < PHASE_COUNT; i++) { + if (handoff->phases & (1 << i)) + printf(" %s", spl_phase_name(i)); + } + if (!handoff->phases) + printf(" (none)"); + printf("\n"); + + return 0; +} + #ifdef CONFIG_SYS_LONGHELP static char vbe_help_text[] = "list - list VBE bootmeths\n" "vbe select - select a VBE bootmeth by sequence or name\n" - "vbe info - show information about a VBE bootmeth"; + "vbe info - show information about a VBE bootmeth\n" + "vbe state - show VBE state"; #endif
U_BOOT_CMD_WITH_SUBCMDS(vbe, "Verified Boot for Embedded", vbe_help_text, U_BOOT_SUBCMD_MKENT(list, 1, 1, do_vbe_list), U_BOOT_SUBCMD_MKENT(select, 2, 1, do_vbe_select), + U_BOOT_SUBCMD_MKENT(state, 2, 1, do_vbe_state), U_BOOT_SUBCMD_MKENT(info, 2, 1, do_vbe_info)); diff --git a/doc/usage/cmd/vbe.rst b/doc/usage/cmd/vbe.rst index 2b5cdd7d411..67ccd0ce3ad 100644 --- a/doc/usage/cmd/vbe.rst +++ b/doc/usage/cmd/vbe.rst @@ -8,6 +8,7 @@ Synopsis
vbe list vbe select <name_or_id> + vbe state
Description ----------- @@ -49,6 +50,13 @@ device name can be provided. Without any arguments, any selected device is deselected.
+vbe state +~~~~~~~~~ + +This shows the current state of VBE. At present this is just a list of the +U-Boot phases which booted using VBE. + + Examples --------
@@ -82,6 +90,11 @@ This shows selecting a VBE device by its name:: --- --- -------------- -------------- ----------- =>
+This shows the state after a successful boot into U-Boot proper, using VBE:: + + => vbe state + Phases: VPL SPL +
Return value ------------ diff --git a/include/spl.h b/include/spl.h index e407c7fe55b..ab62813c4fe 100644 --- a/include/spl.h +++ b/include/spl.h @@ -66,6 +66,8 @@ enum u_boot_phase { PHASE_SPL, /* Running in SPL */ PHASE_BOARD_F, /* Running in U-Boot before relocation */ PHASE_BOARD_R, /* Running in U-Boot after relocation */ + + PHASE_COUNT, };
/** diff --git a/test/boot/vbe.c b/test/boot/vbe.c index 9653ac5d94b..d5209c040d7 100644 --- a/test/boot/vbe.c +++ b/test/boot/vbe.c @@ -7,7 +7,9 @@ */
#include <common.h> +#include <bloblist.h> #include <dm.h> +#include <spl.h> #include <vbe.h> #include <test/suites.h> #include <test/ut.h> @@ -67,3 +69,29 @@ static int vbe_cmd_select(struct unit_test_state *uts) return 0; } BOOTSTD_TEST(vbe_cmd_select, UT_TESTF_DM | UT_TESTF_SCAN_FDT); + +/* Check the 'vbe state' command */ +static int vbe_cmd_state(struct unit_test_state *uts) +{ + struct vbe_handoff *handoff; + + console_record_reset_enable(); + ut_asserteq(CMD_RET_FAILURE, run_command("vbe state", 0)); + ut_assert_nextline("No VBE state"); + ut_assert_console_end(); + + ut_assertok(bloblist_ensure_size(BLOBLISTT_VBE, + sizeof(struct vbe_handoff), 0, + (void **)&handoff)); + ut_assertok(run_command("vbe state", 0)); + ut_assert_nextline("Phases: (none)"); + ut_assert_console_end(); + + handoff->phases = 1 << PHASE_VPL | 1 << PHASE_SPL; + ut_assertok(run_command("vbe state", 0)); + ut_assert_nextline("Phases: VPL SPL"); + ut_assert_console_end(); + + return 0; +} +BOOTSTD_TEST(vbe_cmd_state, 0);