diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 64861f85d..b9aba1294 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -547,6 +547,12 @@ config NSH_DISABLE_XD bool "Disable xd" default DEFAULT_SMALL +config NSH_DISABLE_RESET_CAUSE + bool "Disable reset cause" + default n if !DEFAULT_SMALL + default y if DEFAULT_SMALL + depends on BOARDCTL_RESET_CAUSE + endmenu if MMCSD diff --git a/nshlib/nsh.h b/nshlib/nsh.h index e2f7ed942..d7d2c5575 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -1157,6 +1157,10 @@ int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE) + int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index a78190d6b..213e70732 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -439,6 +439,10 @@ static const struct cmdmap_s g_cmdmap[] = { "reboot", cmd_reboot, 1, 2, NULL }, #endif +#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE) + { "resetcause", cmd_reset_cause, 1, 1, NULL }, +#endif + #ifdef NSH_HAVE_DIROPTS # ifndef CONFIG_NSH_DISABLE_RM { "rm", cmd_rm, 2, 3, "[-r] " }, diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c index c68c1c12f..471131c24 100644 --- a/nshlib/nsh_syscmds.c +++ b/nshlib/nsh_syscmds.c @@ -319,6 +319,26 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE) +int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + int ret; + struct boardioc_reset_cause_s cause; + + memset(&cause, 0, sizeof(cause)); + ret = boardctl(BOARDIOC_RESET_CAUSE, &cause); + if (ret < 0) + { + nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO); + return ERROR; + } + + nsh_output(vtbl, "cause:0x%x, flag:0x" PRIx32 "\n", + cause.cause, cause.flag); + return OK; +} +#endif + /**************************************************************************** * Name: cmd_rptun ****************************************************************************/