From a2a1530694f26229b61a5c9897a6715504d08e8f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 4 Jul 2015 11:11:16 -0600 Subject: [PATCH] The NSH shutdown command now supports the --reset option, if available in hardware --- ChangeLog.txt | 4 ++- nshlib/README.txt | 9 +++--- nshlib/nsh.h | 3 +- nshlib/nsh_command.c | 8 ++++- nshlib/nsh_syscmds.c | 71 ++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 83 insertions(+), 12 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 4d8a02173..af0e52bba 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1328,7 +1328,9 @@ and now stands alone in its own repository (2015-06-27). * apps/examples/poll: Fix a few bit-rot compilation errors (2015-07-01). * apps/nshlib: NSH will now support an (optional) shutdown command if - the board provides the option CONFIG_BOARD_POWEROFF (2015-07-04). + the board provides the option CONFIG_BOARDCTL_POWEROFF. The command can + also be used to reset the system if CONFIG_BOARDCTL_RESET=y. + (2015-07-04). * apps/system/poweroff: Remove the system poweroff command. This is replaced with the NSH shutdown commandi (2015-07-02). diff --git a/nshlib/README.txt b/nshlib/README.txt index 479efbc0b..4b8a31c8e 100644 --- a/nshlib/README.txt +++ b/nshlib/README.txt @@ -884,10 +884,11 @@ o sh Execute the sequence of NSH commands in the file referred to by . -o shutdown +o shutdown [--reset] - Shutdown and power off the system immediately. This command depends on - hardware support to power down the system. + Shutdown and power off the system or, optionally, reset the system + immediately. This command depends on hardware support to power down or + reset the system; one, both, or neither behavior may be supported. o sleep @@ -995,7 +996,7 @@ Command Dependencies on Configuration Settings rmdir (((!CONFIG_DISABLE_MOUNTPOINT && CONFIG_FS_WRITABLE) || !CONFIG_DISABLE_PSEUDOFS_OPERATIONS) && CONFIG_NFILE_DESCRIPTORS > 0) set !CONFIG_DISABLE_ENVIRON sh CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !CONFIG_NSH_DISABLESCRIPT - shutdown CONFIG_BOARDCTL_POWEROFF + shutdown CONFIG_BOARDCTL_POWEROFF || CONFIG_BOARDCTL_RESET sleep !CONFIG_DISABLE_SIGNALS test !CONFIG_NSH_DISABLESCRIPT umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE diff --git a/nshlib/nsh.h b/nshlib/nsh.h index c43fd7a4f..ee32c4eef 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -988,7 +988,8 @@ void nsh_usbtrace(void); # endif #endif /* CONFIG_NET */ -#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_SHUTDOWN) +#if (defined(CONFIG_BOARDCTL_POWEROFF) || defined(CONFIG_BOARDCTL_RESET)) && \ + !defined(CONFIG_NSH_DISABLE_SHUTDOWN) int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 8a7b9cd7a..9af47dfe5 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -369,8 +369,14 @@ static const struct cmdmap_s g_cmdmap[] = # endif #endif -#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_SHUTDOWN) +#ifndef CONFIG_NSH_DISABLE_SHUTDOWN +#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET) + { "shutdown", cmd_shutdown, 1, 2, "[--reset]" }, +#elif defined(CONFIG_BOARDCTL_POWEROFF) { "shutdown", cmd_shutdown, 1, 1, NULL }, +#elif defined(CONFIG_BOARDCTL_RESET) + { "shutdown", cmd_shutdown, 2, 2, "--reset" }, +#endif #endif #ifndef CONFIG_DISABLE_SIGNALS diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c index f9525d1af..2495fb843 100644 --- a/nshlib/nsh_syscmds.c +++ b/nshlib/nsh_syscmds.c @@ -78,17 +78,78 @@ * Name: cmd_shutdown ****************************************************************************/ -#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_SHUTDOWN) +#if (defined(CONFIG_BOARDCTL_POWEROFF) || defined(CONFIG_BOARDCTL_RESET)) && \ + !defined(CONFIG_NSH_DISABLE_SHUTDOWN) + int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) { - /* Invoide the BOARDIOC_POWEROFF board control to shutdown the board - * If board_power_off function returns, then it was not possible to power-off the - * board due to some constraints. +#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET) + /* If both shutdown and reset are supported, then a single option may + * be provided to select the reset behavior (--reset). We know here + * that argc is either 1 or 2. + */ + + if (argc == 2) + { + /* Verify that the single argument is --reset */ + + if (strcmp(argv[1], "--reset") != 0) + { + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + return ERROR + } + + /* Invoke the BOARDIOC_RESET board control to reset the board. If + * the board_reset() function returns, then it was not possible to + * reset the board due to some constraints. + */ + + (void)boardctl(BOARDIOC_RESET, EXIT_SUCCESS); + } + else + { + /* Invoke the BOARDIOC_POWEROFF board control to shutdown the board. + * If the board_power_off function returns, then it was not possible + * to power-off the* board due to some constraints. + */ + + (void)boardctl(BOARDIOC_POWEROFF, EXIT_SUCCESS); + } + +#elif defined(CONFIG_BOARDCTL_RESET) + /* Only reset behavior is supported and we already know that exactly one + * argument has been provided. + */ + + /* Verify that the single argument is --reset */ + + if (strcmp(argv[1], "--reset") != 0) + { + nsh_output(vtbl, g_fmtarginvalid, argv[0]); + return ERROR + } + + /* Invoke the BOARDIOC_RESET board control to reset the board. If + * the board_reset() function returns, then it was not possible to + * reset the board due to some constraints. + */ + + (void)boardctl(BOARDIOC_RESET, EXIT_SUCCESS); + +#else + /* Only the reset behavior is supported and we already know that there is + * no argument to the command. + */ + + /* Invoke the BOARDIOC_POWEROFF board control to shutdown the board. If + * the board_power_off function returns, then it was not possible to power- + * off the board due to some constraints. */ (void)boardctl(BOARDIOC_POWEROFF, EXIT_SUCCESS); +#endif - /* boarctl() will not return in this case. It if does, it means that + /* boarctl() will not return in any case. It if does, it means that * there was a problem with the shutdown operaion. */