blob: a5737edc047e34b831ded3fa66d88c06fd89d46c [file] [log] [blame]
Simon Glass5fe76d42022-07-30 15:52:37 -06001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Verified Boot for Embedded (VBE) command
4 *
5 * Copyright 2022 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
10#include <bootmeth.h>
11#include <bootstd.h>
12#include <command.h>
13#include <vbe.h>
14
15static int do_vbe_list(struct cmd_tbl *cmdtp, int flag, int argc,
16 char *const argv[])
17{
18 vbe_list();
19
20 return 0;
21}
22
23static int do_vbe_select(struct cmd_tbl *cmdtp, int flag, int argc,
24 char *const argv[])
25{
26 struct bootstd_priv *std;
27 struct udevice *dev;
28 int ret;
29
30 ret = bootstd_get_priv(&std);
31 if (ret)
32 return CMD_RET_FAILURE;
33 if (argc < 2) {
34 std->vbe_bootmeth = NULL;
35 return 0;
36 }
37 if (vbe_find_by_any(argv[1], &dev))
38 return CMD_RET_FAILURE;
39
40 std->vbe_bootmeth = dev;
41
42 return 0;
43}
44
45static int do_vbe_info(struct cmd_tbl *cmdtp, int flag, int argc,
46 char *const argv[])
47{
48 struct bootstd_priv *std;
49 char buf[256];
50 int ret, len;
51
52 ret = bootstd_get_priv(&std);
53 if (ret)
54 return CMD_RET_FAILURE;
55 if (!std->vbe_bootmeth) {
56 printf("No VBE bootmeth selected\n");
57 return CMD_RET_FAILURE;
58 }
59 ret = bootmeth_get_state_desc(std->vbe_bootmeth, buf, sizeof(buf));
60 if (ret) {
61 printf("Failed (err=%d)\n", ret);
62 return CMD_RET_FAILURE;
63 }
64 len = strnlen(buf, sizeof(buf));
65 if (len >= sizeof(buf)) {
66 printf("Buffer overflow\n");
67 return CMD_RET_FAILURE;
68 }
69
70 puts(buf);
71 if (buf[len] != '\n')
72 putc('\n');
73
74 return 0;
75}
76
77#ifdef CONFIG_SYS_LONGHELP
78static char vbe_help_text[] =
79 "list - list VBE bootmeths\n"
80 "vbe select - select a VBE bootmeth by sequence or name\n"
81 "vbe info - show information about a VBE bootmeth";
82#endif
83
84U_BOOT_CMD_WITH_SUBCMDS(vbe, "Verified Boot for Embedded", vbe_help_text,
85 U_BOOT_SUBCMD_MKENT(list, 1, 1, do_vbe_list),
86 U_BOOT_SUBCMD_MKENT(select, 2, 1, do_vbe_select),
87 U_BOOT_SUBCMD_MKENT(info, 2, 1, do_vbe_info));