bootcount.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0+
  2. #include <common.h>
  3. #include <command.h>
  4. #include <bootcount.h>
  5. static int do_bootcount_print(struct cmd_tbl *cmdtp, int flag, int argc,
  6. char *const argv[])
  7. {
  8. printf("%lu\n", bootcount_load());
  9. return CMD_RET_SUCCESS;
  10. }
  11. static int do_bootcount_reset(struct cmd_tbl *cmdtp, int flag, int argc,
  12. char *const argv[])
  13. {
  14. /*
  15. * note that we're explicitly not resetting the environment
  16. * variable, so you still have the old bootcounter available
  17. */
  18. bootcount_store(0);
  19. return CMD_RET_SUCCESS;
  20. }
  21. static struct cmd_tbl bootcount_sub[] = {
  22. U_BOOT_CMD_MKENT(print, 1, 1, do_bootcount_print, "", ""),
  23. U_BOOT_CMD_MKENT(reset, 1, 1, do_bootcount_reset, "", ""),
  24. };
  25. static int do_bootcount(struct cmd_tbl *cmdtp, int flag, int argc,
  26. char *const argv[])
  27. {
  28. struct cmd_tbl *cp;
  29. if (argc < 2)
  30. return CMD_RET_USAGE;
  31. /* drop initial "bootcount" arg */
  32. argc--;
  33. argv++;
  34. cp = find_cmd_tbl(argv[0], bootcount_sub, ARRAY_SIZE(bootcount_sub));
  35. if (cp)
  36. return cp->cmd(cmdtp, flag, argc, argv);
  37. return CMD_RET_USAGE;
  38. }
  39. #if CONFIG_IS_ENABLED(SYS_LONGHELP)
  40. static char bootcount_help_text[] =
  41. "print - print current bootcounter\n"
  42. "reset - reset the bootcounter"
  43. ;
  44. #endif
  45. U_BOOT_CMD(bootcount, 2, 1, do_bootcount,
  46. "bootcount",
  47. #if CONFIG_IS_ENABLED(SYS_LONGHELP)
  48. bootcount_help_text
  49. #endif
  50. );