summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/ectool.c76
1 files changed, 71 insertions, 5 deletions
diff --git a/util/ectool.c b/util/ectool.c
index dd51dc62a9..98b85f22f4 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -12,8 +12,10 @@
#include <unistd.h>
#include "battery.h"
-#include "lightbar.h"
#include "ec_commands.h"
+#include "lightbar.h"
+#include "system.h"
+#include "vboot.h"
/* Handy tricks */
#define BUILD_ASSERT(cond) ((void)sizeof(char[1 - 2*!(cond)]))
@@ -54,10 +56,12 @@ const char help_str[] =
" Erases EC flash\n"
" hello\n"
" Checks for basic communication with EC\n"
- " lightbar reset\n"
- " Puts the lightbar into idle mode\n"
- " lightbar test [NUM]\n"
- " Cycles lights once. Optional argument does nothing.\n"
+ " lightbar [CMDS]\n"
+ " Various lightbar control commands\n"
+ " vboot get\n"
+ " Get vboot flags\n"
+ " vboot set VAL\n"
+ " Set vboot flags\n"
" pstoreinfo\n"
" Prints information on the EC host persistent storage\n"
" pstoreread <offset> <size> <outfile>\n"
@@ -1031,6 +1035,66 @@ static int cmd_lightbar(int argc, char **argv)
return lb_help(argv[0]);
}
+
+/* This needs to match the values defined in vboot.h. I'd like to
+ * define this in one and only one place, but I can't think of a good way to do
+ * that without adding bunch of complexity. This will do for now.
+ */
+static const struct {
+ uint8_t insize;
+ uint8_t outsize;
+} vb_command_paramcount[] = {
+ { sizeof(((struct ec_params_vboot_cmd *)0)->in.get_flags),
+ sizeof(((struct ec_params_vboot_cmd *)0)->out.get_flags) },
+ { sizeof(((struct ec_params_vboot_cmd *)0)->in.set_flags),
+ sizeof(((struct ec_params_vboot_cmd *)0)->out.set_flags) },
+};
+
+/* Note: depends on enum system_image_copy_t */
+static const char * const image_names[] = {"unknown", "RO", "A", "B"};
+
+static int cmd_vboot(int argc, char **argv)
+{
+ int r;
+ uint8_t v;
+ char *e;
+ struct ec_params_vboot_cmd param;
+
+ if (argc == 1) { /* no args = get */
+ param.in.cmd = VBOOT_CMD_GET_FLAGS;
+ r = ec_command(EC_CMD_VBOOT_CMD,
+ &param,
+ vb_command_paramcount[param.in.cmd].insize,
+ &param,
+ vb_command_paramcount[param.in.cmd].outsize);
+ if (r)
+ return r;
+
+ v = param.out.get_flags.val;
+ printf("0x%02x image=%s fake_dev=%d\n", v,
+ image_names[VBOOT_FLAGS_IMAGE_MASK & v],
+ VBOOT_FLAGS_FAKE_DEVMODE & v ? 1 : 0);
+ return 0;
+ }
+
+ /* else args => set values */
+
+ v = strtoul(argv[1], &e, 16) & 0xff;
+ if (e && *e) {
+ fprintf(stderr, "Bad value\n");
+ return -1;
+ }
+
+ param.in.cmd = VBOOT_CMD_SET_FLAGS;
+ param.in.set_flags.val = v;
+ r = ec_command(EC_CMD_VBOOT_CMD,
+ &param,
+ vb_command_paramcount[param.in.cmd].insize,
+ &param,
+ vb_command_paramcount[param.in.cmd].outsize);
+ return r;
+}
+
int cmd_usb_charge_set_mode(int argc, char *argv[])
{
struct ec_params_usb_charge_set_mode p;
@@ -1482,6 +1546,7 @@ const struct command commands[] = {
{"flashinfo", cmd_flash_info},
{"hello", cmd_hello},
{"lightbar", cmd_lightbar},
+ {"vboot", cmd_vboot},
{"pstoreinfo", cmd_pstore_info},
{"pstoreread", cmd_pstore_read},
{"pstorewrite", cmd_pstore_write},
@@ -1509,6 +1574,7 @@ int main(int argc, char *argv[])
const struct command *cmd;
BUILD_ASSERT(ARRAY_SIZE(lb_command_paramcount) == LIGHTBAR_NUM_CMDS);
+ BUILD_ASSERT(ARRAY_SIZE(vb_command_paramcount) == VBOOT_NUM_CMDS);
if (argc < 2 || !strcasecmp(argv[1], "-?") ||
!strcasecmp(argv[1], "help")) {