blob: 30ce5dba30d9bd69efdf3ce182e19e0d7e5228c0 [file] [log] [blame]
Alex Kiernanb11ed7d2018-05-12 05:49:47 +00001// SPDX-License-Identifier: GPL-2.0+
2
3#include <common.h>
4#include <command.h>
5#include <bootcount.h>
6
Simon Glass09140112020-05-10 11:40:03 -06007static int do_bootcount_print(struct cmd_tbl *cmdtp, int flag, int argc,
8 char *const argv[])
Alex Kiernanb11ed7d2018-05-12 05:49:47 +00009{
10 printf("%lu\n", bootcount_load());
11 return CMD_RET_SUCCESS;
12}
13
Simon Glass09140112020-05-10 11:40:03 -060014static int do_bootcount_reset(struct cmd_tbl *cmdtp, int flag, int argc,
15 char *const argv[])
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000016{
17 /*
18 * note that we're explicitly not resetting the environment
19 * variable, so you still have the old bootcounter available
20 */
21 bootcount_store(0);
22 return CMD_RET_SUCCESS;
23}
24
Simon Glass09140112020-05-10 11:40:03 -060025static struct cmd_tbl bootcount_sub[] = {
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000026 U_BOOT_CMD_MKENT(print, 1, 1, do_bootcount_print, "", ""),
27 U_BOOT_CMD_MKENT(reset, 1, 1, do_bootcount_reset, "", ""),
28};
29
Simon Glass09140112020-05-10 11:40:03 -060030static int do_bootcount(struct cmd_tbl *cmdtp, int flag, int argc,
31 char *const argv[])
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000032{
Simon Glass09140112020-05-10 11:40:03 -060033 struct cmd_tbl *cp;
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000034
35 if (argc < 2)
36 return CMD_RET_USAGE;
37
38 /* drop initial "bootcount" arg */
39 argc--;
40 argv++;
41
42 cp = find_cmd_tbl(argv[0], bootcount_sub, ARRAY_SIZE(bootcount_sub));
43 if (cp)
44 return cp->cmd(cmdtp, flag, argc, argv);
45
46 return CMD_RET_USAGE;
47}
48
Tom Rini36162182023-10-07 15:13:08 -040049U_BOOT_LONGHELP(bootcount,
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000050 "print - print current bootcounter\n"
Tom Rini36162182023-10-07 15:13:08 -040051 "reset - reset the bootcounter");
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000052
53U_BOOT_CMD(bootcount, 2, 1, do_bootcount,
54 "bootcount",
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000055 bootcount_help_text
Alex Kiernanb11ed7d2018-05-12 05:49:47 +000056);