2015-07-04 16:44:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_syscmds.c
|
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-07-04 16:44:42 +02:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-07-04 16:44:42 +02:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-07-04 16:44:42 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2019-11-03 16:36:49 +01:00
|
|
|
#include <nuttx/rptun/rptun.h>
|
2023-03-08 09:57:36 +01:00
|
|
|
#include <nuttx/streams.h>
|
2015-07-04 16:44:42 +02:00
|
|
|
#include <sys/boardctl.h>
|
2019-11-03 16:36:49 +01:00
|
|
|
#include <sys/ioctl.h>
|
2015-07-04 23:13:11 +02:00
|
|
|
#include <sys/utsname.h>
|
2022-02-11 14:05:08 +01:00
|
|
|
#include <dirent.h>
|
2019-11-03 16:36:49 +01:00
|
|
|
#include <fcntl.h>
|
2015-07-04 16:44:42 +02:00
|
|
|
#include <stdlib.h>
|
2016-09-05 15:05:17 +02:00
|
|
|
#include <string.h>
|
2015-07-04 16:44:42 +02:00
|
|
|
#include <errno.h>
|
2023-02-04 14:56:06 +01:00
|
|
|
#include <unistd.h>
|
2015-07-04 16:44:42 +02:00
|
|
|
|
|
|
|
#include "nsh.h"
|
|
|
|
#include "nsh_console.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-07-04 23:13:11 +02:00
|
|
|
* Pre-processor Definitions
|
2015-07-04 16:44:42 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-07-05 14:47:29 +02:00
|
|
|
#ifdef CONFIG_ARCH_BOARD_CUSTOM
|
|
|
|
# ifndef CONFIG_ARCH_BOARD_CUSTOM_NAME
|
2015-07-05 16:42:00 +02:00
|
|
|
# define BOARD_NAME g_unknown
|
2015-07-05 14:47:29 +02:00
|
|
|
# else
|
|
|
|
# define BOARD_NAME CONFIG_ARCH_BOARD_CUSTOM_NAME
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# ifndef CONFIG_ARCH_BOARD
|
2015-07-05 16:42:00 +02:00
|
|
|
# define BOARD_NAME g_unknown
|
2015-07-05 14:47:29 +02:00
|
|
|
# else
|
|
|
|
# define BOARD_NAME CONFIG_ARCH_BOARD
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 23:13:11 +02:00
|
|
|
#define UNAME_KERNEL (1 << 0)
|
|
|
|
#define UNAME_NODE (1 << 1)
|
|
|
|
#define UNAME_RELEASE (1 << 2)
|
2022-01-05 16:34:05 +01:00
|
|
|
#define UNAME_VERSION (1 << 3)
|
2015-07-04 23:13:11 +02:00
|
|
|
#define UNAME_MACHINE (1 << 4)
|
2015-07-05 14:47:29 +02:00
|
|
|
#define UNAME_PLATFORM (1 << 5)
|
|
|
|
#define UNAME_UNKNOWN (1 << 6)
|
2015-07-04 23:13:11 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET
|
|
|
|
# define UNAME_ALL (UNAME_KERNEL | UNAME_NODE | UNAME_RELEASE | \
|
2022-01-05 16:34:05 +01:00
|
|
|
UNAME_VERSION | UNAME_MACHINE | UNAME_PLATFORM)
|
2015-07-04 23:13:11 +02:00
|
|
|
#else
|
2022-01-05 16:34:05 +01:00
|
|
|
# define UNAME_ALL (UNAME_KERNEL | UNAME_RELEASE | UNAME_VERSION | \
|
2015-07-05 14:47:29 +02:00
|
|
|
UNAME_MACHINE | UNAME_PLATFORM)
|
2015-07-04 23:13:11 +02:00
|
|
|
#endif
|
|
|
|
|
2022-06-20 08:31:27 +02:00
|
|
|
#ifndef CONFIG_NSH_PROC_MOUNTPOINT
|
|
|
|
# define CONFIG_NSH_PROC_MOUNTPOINT "/proc"
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 16:44:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-07 22:36:18 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_UNAME
|
2015-07-05 16:42:00 +02:00
|
|
|
static const char g_unknown[] = "unknown";
|
2017-03-07 22:36:18 +01:00
|
|
|
#endif
|
2015-07-04 16:44:42 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_shutdown
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-07-04 19:11:16 +02:00
|
|
|
#if (defined(CONFIG_BOARDCTL_POWEROFF) || defined(CONFIG_BOARDCTL_RESET)) && \
|
|
|
|
!defined(CONFIG_NSH_DISABLE_SHUTDOWN)
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2015-07-04 16:44:42 +02:00
|
|
|
{
|
2015-07-04 19:11:16 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET)
|
|
|
|
/* If both shutdown and reset are supported, then a single option may
|
2015-07-04 19:39:44 +02:00
|
|
|
* be provided to select the reset behavior (--reboot). We know here
|
2015-07-04 19:11:16 +02:00
|
|
|
* that argc is either 1 or 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (argc == 2)
|
|
|
|
{
|
2015-07-04 19:39:44 +02:00
|
|
|
/* Verify that the single argument is --reboot */
|
2015-07-04 19:11:16 +02:00
|
|
|
|
2015-07-04 19:39:44 +02:00
|
|
|
if (strcmp(argv[1], "--reboot") != 0)
|
2015-07-04 19:11:16 +02:00
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
|
2016-08-25 14:26:33 +02:00
|
|
|
return ERROR;
|
2015-07-04 19:11:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_RESET, 0);
|
2015-07-04 19:11:16 +02:00
|
|
|
}
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_POWEROFF, 0);
|
2015-07-04 19:11:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(CONFIG_BOARDCTL_RESET)
|
|
|
|
/* Only reset behavior is supported and we already know that exactly one
|
|
|
|
* argument has been provided.
|
|
|
|
*/
|
|
|
|
|
2015-07-04 19:39:44 +02:00
|
|
|
/* Verify that the single argument is --reboot */
|
2015-07-04 19:11:16 +02:00
|
|
|
|
2015-07-04 19:39:44 +02:00
|
|
|
if (strcmp(argv[1], "--reboot") != 0)
|
2015-07-04 19:11:16 +02:00
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
|
2016-09-05 15:05:17 +02:00
|
|
|
return ERROR;
|
2015-07-04 19:11:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_RESET, 0);
|
2015-07-04 19:11:16 +02:00
|
|
|
|
|
|
|
#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.
|
2015-07-04 16:44:42 +02:00
|
|
|
*/
|
|
|
|
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_POWEROFF, 0);
|
2015-07-04 19:11:16 +02:00
|
|
|
#endif
|
2015-07-04 16:44:42 +02:00
|
|
|
|
2022-01-16 05:42:35 +01:00
|
|
|
/* boardctl() will not return in any case. It if does, it means that
|
2023-04-01 14:23:12 +02:00
|
|
|
* there was a problem with the shutdown/reset operation.
|
2015-07-04 16:44:42 +02:00
|
|
|
*/
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
|
2015-07-04 16:44:42 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_BOARDCTL_POWEROFF && !CONFIG_NSH_DISABLE_SHUTDOWN */
|
2015-07-04 20:44:24 +02:00
|
|
|
|
2019-11-04 14:44:33 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_pmconfig
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_PM) && !defined(CONFIG_NSH_DISABLE_PMCONFIG)
|
2022-06-20 08:31:27 +02:00
|
|
|
static int cmd_pmconfig_recursive(FAR struct nsh_vtbl_s *vtbl,
|
|
|
|
FAR const char *dirpath,
|
|
|
|
FAR struct dirent *entryp,
|
|
|
|
FAR void *pvarg)
|
|
|
|
{
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR char *path;
|
2022-06-20 08:31:27 +02:00
|
|
|
int ret = ERROR;
|
|
|
|
|
|
|
|
if (DIRENT_ISDIRECTORY(entryp->d_type))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, "\n%s:\n", path);
|
|
|
|
ret = nsh_catfile(vtbl, pvarg, path);
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_pmconfig(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2019-11-04 14:44:33 +01:00
|
|
|
{
|
|
|
|
struct boardioc_pm_ctrl_s ctrl =
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2022-04-20 06:26:27 +02:00
|
|
|
if (argc <= 2)
|
2019-11-04 14:44:33 +01:00
|
|
|
{
|
2022-05-06 13:31:12 +02:00
|
|
|
int next_state;
|
|
|
|
int last_state;
|
2019-11-04 14:44:33 +01:00
|
|
|
|
2022-04-20 06:26:27 +02:00
|
|
|
if (argc == 2)
|
|
|
|
{
|
|
|
|
ctrl.domain = atoi(argv[1]);
|
|
|
|
}
|
|
|
|
|
2019-11-04 14:44:33 +01:00
|
|
|
ctrl.action = BOARDIOC_PM_QUERYSTATE;
|
|
|
|
boardctl(BOARDIOC_PM_CONTROL, (uintptr_t)&ctrl);
|
2022-05-06 13:31:12 +02:00
|
|
|
last_state = ctrl.state;
|
|
|
|
|
|
|
|
ctrl.action = BOARDIOC_PM_CHECKSTATE;
|
|
|
|
boardctl(BOARDIOC_PM_CONTROL, (uintptr_t)&ctrl);
|
|
|
|
next_state = ctrl.state;
|
2019-11-04 14:44:33 +01:00
|
|
|
|
2022-06-20 08:31:27 +02:00
|
|
|
nsh_output(vtbl, "Last state %d, Next state %d\n",
|
|
|
|
last_state, next_state);
|
2019-11-04 14:44:33 +01:00
|
|
|
|
2022-06-20 08:31:27 +02:00
|
|
|
return nsh_foreach_direntry(vtbl, argv[0],
|
|
|
|
CONFIG_NSH_PROC_MOUNTPOINT "/pm",
|
|
|
|
cmd_pmconfig_recursive, argv[0]);
|
2019-11-04 14:44:33 +01:00
|
|
|
}
|
2022-04-20 06:26:27 +02:00
|
|
|
else if (argc <= 4)
|
2019-11-04 14:44:33 +01:00
|
|
|
{
|
2022-04-20 06:26:27 +02:00
|
|
|
if (argc == 4)
|
|
|
|
{
|
|
|
|
ctrl.domain = atoi(argv[3]);
|
|
|
|
}
|
|
|
|
|
2019-11-04 14:44:33 +01:00
|
|
|
if (strcmp(argv[1], "stay") == 0)
|
|
|
|
{
|
|
|
|
ctrl.action = BOARDIOC_PM_STAY;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "relax") == 0)
|
|
|
|
{
|
|
|
|
ctrl.action = BOARDIOC_PM_RELAX;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtarginvalid, argv[1]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(argv[2], "normal") == 0)
|
|
|
|
{
|
|
|
|
ctrl.state = PM_NORMAL;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[2], "idle") == 0)
|
|
|
|
{
|
|
|
|
ctrl.state = PM_IDLE;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[2], "standby") == 0)
|
|
|
|
{
|
|
|
|
ctrl.state = PM_STANDBY;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[2], "sleep") == 0)
|
|
|
|
{
|
|
|
|
ctrl.state = PM_SLEEP;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtarginvalid, argv[2]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
boardctl(BOARDIOC_PM_CONTROL, (uintptr_t)&ctrl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 20:44:24 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_poweroff
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_POWEROFF)
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_poweroff(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2015-07-04 20:44:24 +02:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2018-08-23 00:08:10 +02:00
|
|
|
if (argc > 1)
|
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_POWEROFF, atoi(argv[1]));
|
2018-08-23 00:08:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_POWEROFF, 0);
|
2018-08-23 00:08:10 +02:00
|
|
|
}
|
2015-07-04 20:44:24 +02:00
|
|
|
|
2022-01-16 05:42:35 +01:00
|
|
|
/* boardctl() will not return in any case. It if does, it means that
|
2020-02-23 05:51:44 +01:00
|
|
|
* there was a problem with the shutdown operation.
|
2015-07-04 20:44:24 +02:00
|
|
|
*/
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
|
2015-07-04 20:44:24 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-04 13:59:45 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_switchboot
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_BOARDCTL_SWITCH_BOOT) && !defined(CONFIG_NSH_DISABLE_SWITCHBOOT)
|
|
|
|
int cmd_switchboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtarginvalid, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
boardctl(BOARDIOC_SWITCH_BOOT, (uintptr_t)argv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-01 14:23:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_boot
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_BOARDCTL_BOOT_IMAGE) && !defined(CONFIG_NSH_DISABLE_BOOT)
|
|
|
|
int cmd_boot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
|
|
|
{
|
|
|
|
struct boardioc_boot_info_s info;
|
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
|
|
|
|
|
|
|
/* Invoke the BOARDIOC_BOOT_IMAGE board control to reset the board. If
|
|
|
|
* the board_boot_image() function returns, then it was not possible to
|
|
|
|
* boot the image due to some constraints.
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (argc)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
info.header_size = strtoul(argv[2], NULL, 0);
|
|
|
|
|
|
|
|
/* Go through */
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
info.path = argv[1];
|
|
|
|
|
|
|
|
/* Go through */
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
/* Nothing to do */
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
boardctl(BOARDIOC_BOOT_IMAGE, (uintptr_t)&info);
|
|
|
|
|
|
|
|
/* boardctl() will not return in this case. It if does, it means that
|
|
|
|
* there was a problem with the boot operation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 20:44:24 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_reboot
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT)
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2015-07-04 20:44:24 +02:00
|
|
|
{
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2018-08-23 00:08:10 +02:00
|
|
|
if (argc > 1)
|
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_RESET, atoi(argv[1]));
|
2018-08-23 00:08:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-28 18:21:53 +01:00
|
|
|
boardctl(BOARDIOC_RESET, 0);
|
2018-08-23 00:08:10 +02:00
|
|
|
}
|
2015-07-04 20:44:24 +02:00
|
|
|
|
2022-01-16 05:42:35 +01:00
|
|
|
/* boardctl() will not return in this case. It if does, it means that
|
2020-02-23 05:51:44 +01:00
|
|
|
* there was a problem with the reset operation.
|
2015-07-04 20:44:24 +02:00
|
|
|
*/
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
|
2015-07-04 20:44:24 +02:00
|
|
|
return ERROR;
|
2022-03-30 09:38:21 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_reset_cause(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2022-03-30 09:38:21 +02:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(argc);
|
|
|
|
|
2022-03-30 09:38:21 +02:00
|
|
|
int ret;
|
|
|
|
struct boardioc_reset_cause_s cause;
|
|
|
|
|
|
|
|
memset(&cause, 0, sizeof(cause));
|
2022-06-23 04:35:05 +02:00
|
|
|
ret = boardctl(BOARDIOC_RESET_CAUSE, (uintptr_t)&cause);
|
2022-03-30 09:38:21 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "boardctl", NSH_ERRNO);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:23:07 +02:00
|
|
|
nsh_output(vtbl, "cause:0x%x,flag:0x%" PRIx32 "\n",
|
2022-03-30 09:38:21 +02:00
|
|
|
cause.cause, cause.flag);
|
|
|
|
return OK;
|
2015-07-04 20:44:24 +02:00
|
|
|
}
|
|
|
|
#endif
|
2015-07-04 23:13:11 +02:00
|
|
|
|
2019-11-03 16:36:49 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_rptun
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
|
2022-03-31 14:11:09 +02:00
|
|
|
static int cmd_rptun_once(FAR struct nsh_vtbl_s *vtbl,
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR const char *path, FAR char **argv)
|
2019-11-03 16:36:49 +01:00
|
|
|
{
|
2022-03-03 11:05:48 +01:00
|
|
|
struct rptun_ping_s ping;
|
2021-12-24 10:18:56 +01:00
|
|
|
unsigned long val = 0;
|
2020-11-02 12:30:26 +01:00
|
|
|
int cmd;
|
2022-02-11 14:05:08 +01:00
|
|
|
int fd;
|
2019-11-03 16:36:49 +01:00
|
|
|
|
|
|
|
if (strcmp(argv[1], "start") == 0)
|
|
|
|
{
|
|
|
|
cmd = RPTUNIOC_START;
|
|
|
|
}
|
|
|
|
else if (strcmp(argv[1], "stop") == 0)
|
|
|
|
{
|
|
|
|
cmd = RPTUNIOC_STOP;
|
|
|
|
}
|
2021-12-24 10:18:56 +01:00
|
|
|
else if (strcmp(argv[1], "reset") == 0)
|
|
|
|
{
|
2022-03-31 14:11:09 +02:00
|
|
|
val = atoi(argv[3]);
|
2021-12-24 10:18:56 +01:00
|
|
|
cmd = RPTUNIOC_RESET;
|
|
|
|
}
|
2021-12-22 12:50:48 +01:00
|
|
|
else if (strcmp(argv[1], "panic") == 0)
|
|
|
|
{
|
|
|
|
cmd = RPTUNIOC_PANIC;
|
|
|
|
}
|
2022-01-19 14:07:59 +01:00
|
|
|
else if (strcmp(argv[1], "dump") == 0)
|
|
|
|
{
|
|
|
|
cmd = RPTUNIOC_DUMP;
|
|
|
|
}
|
2022-03-03 11:05:48 +01:00
|
|
|
else if (strcmp(argv[1], "ping") == 0)
|
|
|
|
{
|
2022-05-11 06:31:25 +02:00
|
|
|
if (argv[3] == 0 || argv[4] == 0 ||
|
|
|
|
argv[5] == 0 || argv[6] == 0)
|
2022-03-03 11:05:48 +01:00
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ping.times = atoi(argv[3]);
|
|
|
|
ping.len = atoi(argv[4]);
|
|
|
|
ping.ack = atoi(argv[5]);
|
2022-05-11 06:31:25 +02:00
|
|
|
ping.sleep = atoi(argv[6]);
|
2022-03-03 11:05:48 +01:00
|
|
|
|
|
|
|
cmd = RPTUNIOC_PING;
|
|
|
|
val = (unsigned long)&ping;
|
|
|
|
}
|
2019-11-03 16:36:49 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtarginvalid, argv[1]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:05:08 +01:00
|
|
|
fd = open(path, 0);
|
2019-11-03 16:36:49 +01:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2022-03-03 11:05:48 +01:00
|
|
|
nsh_output(vtbl, g_fmtarginvalid, path);
|
2019-11-03 16:36:49 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2022-02-11 14:05:08 +01:00
|
|
|
cmd = ioctl(fd, cmd, val);
|
2019-11-03 16:36:49 +01:00
|
|
|
|
|
|
|
close(fd);
|
2022-02-11 14:05:08 +01:00
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_rptun_recursive(FAR struct nsh_vtbl_s *vtbl,
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR const char *dirpath,
|
|
|
|
FAR struct dirent *entryp,
|
|
|
|
FAR void *pvarg)
|
2022-02-11 14:05:08 +01:00
|
|
|
{
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR char *path;
|
2022-03-31 14:11:09 +02:00
|
|
|
int ret = ERROR;
|
2022-02-11 14:05:08 +01:00
|
|
|
|
|
|
|
if (DIRENT_ISDIRECTORY(entryp->d_type))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = nsh_getdirpath(vtbl, dirpath, entryp->d_name);
|
|
|
|
if (path)
|
|
|
|
{
|
2022-03-31 14:11:09 +02:00
|
|
|
ret = cmd_rptun_once(vtbl, path, pvarg);
|
2022-02-11 14:05:08 +01:00
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2022-02-11 14:05:08 +01:00
|
|
|
{
|
2022-03-31 14:11:09 +02:00
|
|
|
if (argc < 3)
|
2022-02-11 14:05:08 +01:00
|
|
|
{
|
|
|
|
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2022-03-31 14:11:09 +02:00
|
|
|
if (strcmp(argv[2], "all") == 0)
|
2022-02-11 14:05:08 +01:00
|
|
|
{
|
|
|
|
return nsh_foreach_direntry(vtbl, "rptun", "/dev/rptun",
|
|
|
|
cmd_rptun_recursive, argv);
|
|
|
|
}
|
|
|
|
|
2022-03-31 14:11:09 +02:00
|
|
|
return cmd_rptun_once(vtbl, argv[2], argv);
|
2019-11-03 16:36:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-07-04 23:13:11 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_uname
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_UNAME
|
2022-09-22 05:38:12 +02:00
|
|
|
int cmd_uname(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2015-07-04 23:13:11 +02:00
|
|
|
{
|
2015-07-05 16:42:00 +02:00
|
|
|
FAR const char *str;
|
2023-03-08 09:57:36 +01:00
|
|
|
struct lib_memoutstream_s stream;
|
2015-07-04 23:13:11 +02:00
|
|
|
struct utsname info;
|
|
|
|
unsigned int set;
|
|
|
|
int option;
|
|
|
|
bool badarg;
|
|
|
|
bool first;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2017-10-23 16:50:01 +02:00
|
|
|
/* Get the uname options */
|
2015-07-04 23:13:11 +02:00
|
|
|
|
2015-07-05 17:06:13 +02:00
|
|
|
set = 0;
|
|
|
|
badarg = false;
|
|
|
|
|
2015-07-04 23:13:11 +02:00
|
|
|
while ((option = getopt(argc, argv, "asonrvmpi")) != ERROR)
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
set = UNAME_ALL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
case 's':
|
|
|
|
set |= UNAME_KERNEL;
|
|
|
|
break;
|
|
|
|
|
2015-09-01 16:18:40 +02:00
|
|
|
#ifdef CONFIG_NET
|
2015-07-04 23:13:11 +02:00
|
|
|
case 'n':
|
|
|
|
set |= UNAME_NODE;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
set |= UNAME_RELEASE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
2022-01-05 16:34:05 +01:00
|
|
|
set |= UNAME_VERSION;
|
2015-07-04 23:13:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
set |= UNAME_MACHINE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
if (set != UNAME_ALL)
|
|
|
|
{
|
|
|
|
set |= UNAME_UNKNOWN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-07-05 14:47:29 +02:00
|
|
|
case 'i':
|
|
|
|
set |= UNAME_PLATFORM;
|
|
|
|
break;
|
|
|
|
|
2015-07-04 23:13:11 +02:00
|
|
|
case '?':
|
|
|
|
default:
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
|
2015-07-04 23:13:11 +02:00
|
|
|
badarg = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If a bad argument was encountered, then return without processing the
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (badarg)
|
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If nothing is provided on the command line, the default is -s */
|
|
|
|
|
|
|
|
if (set == 0)
|
|
|
|
{
|
|
|
|
set = UNAME_KERNEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get uname data */
|
|
|
|
|
|
|
|
ret = uname(&info);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdfailed, argv[0], "uname", NSH_ERRNO);
|
2015-07-04 23:13:11 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process each option */
|
|
|
|
|
|
|
|
first = true;
|
2023-03-08 09:57:36 +01:00
|
|
|
lib_memoutstream(&stream, alloca(sizeof(struct utsname)),
|
|
|
|
sizeof(struct utsname));
|
2015-07-04 23:13:11 +02:00
|
|
|
for (i = 0; set != 0; i++)
|
|
|
|
{
|
|
|
|
unsigned int mask = (1 << i);
|
|
|
|
if ((set & mask) != 0)
|
|
|
|
{
|
|
|
|
set &= ~mask;
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0: /* print the kernel/operating system name */
|
|
|
|
str = info.sysname;
|
|
|
|
break;
|
|
|
|
|
2015-09-01 16:18:40 +02:00
|
|
|
#ifdef CONFIG_NET
|
2015-07-04 23:13:11 +02:00
|
|
|
case 1: /* Print noname */
|
|
|
|
str = info.nodename;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 2: /* Print the kernel release */
|
|
|
|
str = info.release;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: /* Print the kernel version */
|
|
|
|
str = info.version;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: /* Print the machine hardware name */
|
|
|
|
str = info.machine;
|
|
|
|
break;
|
|
|
|
|
2015-07-05 14:47:29 +02:00
|
|
|
case 5: /* Print the machine platform name */
|
|
|
|
str = BOARD_NAME;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: /* Print "unknown" */
|
2015-07-05 16:42:00 +02:00
|
|
|
str = g_unknown;
|
2015-07-04 23:13:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtarginvalid, argv[0]);
|
2015-07-04 23:13:11 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
{
|
2023-03-08 09:57:36 +01:00
|
|
|
lib_stream_putc(&stream, ' ');
|
2015-07-04 23:13:11 +02:00
|
|
|
}
|
|
|
|
|
2023-03-08 09:57:36 +01:00
|
|
|
lib_stream_puts(&stream, str, strlen(str));
|
2015-07-04 23:13:11 +02:00
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-08 09:57:36 +01:00
|
|
|
lib_stream_putc(&stream, '\n');
|
|
|
|
nsh_write(vtbl, stream.buffer, stream.public.nput);
|
2015-07-04 23:13:11 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|