summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig27
-rw-r--r--commands/Makefile2
-rw-r--r--commands/reset.c16
-rw-r--r--commands/stat.c62
-rw-r--r--commands/uptime.c82
5 files changed, 183 insertions, 6 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index 9894ecb9aa..a59616ad14 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -947,6 +947,20 @@ config CMD_LS
-C column format (opposite of long format)
-R list subdirectories recursively
+config CMD_STAT
+ tristate
+ prompt "stat"
+ select PRINTF_UUID
+ help
+ Display file status
+
+ Usage: stat [-L] [FILEDIR...]
+
+ Display status information about the specified files or directories.
+
+ Options:
+ -L follow symlinks
+
config CMD_MD5SUM
tristate
select COMPILE_HASH
@@ -2275,6 +2289,19 @@ config CMD_TIME
Note: This command depends on COMMAND being interruptible,
otherwise the timer may overrun resulting in incorrect results
+config CMD_UPTIME
+ bool "uptime"
+ help
+ uptime - Tell how long barebox has been running
+
+ Usage: uptime [-n]
+
+ This command formats the number of elapsed nanoseconds
+ as measured with the current clocksource.
+
+ Options:
+ -n output elapsed time in nanoseconds
+
config CMD_STATE
tristate
depends on STATE
diff --git a/commands/Makefile b/commands/Makefile
index 068fbb32da..cac1d4f253 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_CMD_POWEROFF) += poweroff.o
obj-$(CONFIG_CMD_GO) += go.o
obj-$(CONFIG_CMD_PARTITION) += partition.o
obj-$(CONFIG_CMD_LS) += ls.o
+obj-$(CONFIG_CMD_STAT) += stat.o
obj-$(CONFIG_CMD_CD) += cd.o
obj-$(CONFIG_CMD_PWD) += pwd.o
obj-$(CONFIG_CMD_MKDIR) += mkdir.o
@@ -79,6 +80,7 @@ obj-$(CONFIG_CMD_WD) += wd.o
obj-$(CONFIG_CMD_LED_TRIGGER) += trigger.o
obj-$(CONFIG_CMD_USB) += usb.o
obj-$(CONFIG_CMD_TIME) += time.o
+obj-$(CONFIG_CMD_UPTIME) += uptime.o
obj-$(CONFIG_CMD_OFTREE) += oftree.o
obj-$(CONFIG_CMD_OF_DIFF) += of_diff.o
obj-$(CONFIG_CMD_OF_PROPERTY) += of_property.o
diff --git a/commands/reset.c b/commands/reset.c
index fe54e2f9b4..88e677afab 100644
--- a/commands/reset.c
+++ b/commands/reset.c
@@ -12,12 +12,12 @@
static int cmd_reset(int argc, char *argv[])
{
struct restart_handler *rst;
- int opt, shutdown_flag;
+ int opt, shutdown_flag, flags = 0;
const char *name = NULL;
shutdown_flag = 1;
- while ((opt = getopt(argc, argv, "flr:")) > 0) {
+ while ((opt = getopt(argc, argv, "flwr:")) > 0) {
switch (opt) {
case 'f':
shutdown_flag = 0;
@@ -25,6 +25,9 @@ static int cmd_reset(int argc, char *argv[])
case 'l':
restart_handlers_print();
return 0;
+ case 'w':
+ flags |= RESTART_FLAG_WARM_BOOTROM;
+ break;
case 'r':
name = optarg;
break;
@@ -33,9 +36,9 @@ static int cmd_reset(int argc, char *argv[])
}
}
- rst = restart_handler_get_by_name(name);
- if (!rst && name) {
- printf("reset '%s' does not exist\n", name);
+ rst = restart_handler_get_by_name(name, flags);
+ if (!rst && (name || flags)) {
+ printf("No matching restart handler found\n");
return COMMAND_ERROR;
}
@@ -57,13 +60,14 @@ BAREBOX_CMD_HELP_START(reset)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT("-f", "force RESET, don't call shutdown")
BAREBOX_CMD_HELP_OPT("-l", "list reset handlers")
+BAREBOX_CMD_HELP_OPT("-w", "only consider warm BootROM reboot-mode-preserving resets")
BAREBOX_CMD_HELP_OPT("-r RESET", "use reset handler named RESET")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(reset)
.cmd = cmd_reset,
BAREBOX_CMD_DESC("perform RESET of the CPU")
- BAREBOX_CMD_OPTS("[-flr]")
+ BAREBOX_CMD_OPTS("[-flrw]")
BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
BAREBOX_CMD_HELP(cmd_reset_help)
BAREBOX_CMD_COMPLETE(empty_complete)
diff --git a/commands/stat.c b/commands/stat.c
new file mode 100644
index 0000000000..153eac50f1
--- /dev/null
+++ b/commands/stat.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-FileCopyrightText: © 2022 Ahmad Fatoum, Pengutronix
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <linux/stat.h>
+#include <errno.h>
+#include <malloc.h>
+#include <getopt.h>
+#include <stringlist.h>
+
+static int do_stat(int argc, char *argv[])
+{
+ int (*statfn)(const char *, struct stat *) = lstat;
+ int ret, opt, exitcode = 0;
+ char **filename;
+ struct stat st;
+
+ while((opt = getopt(argc, argv, "L")) > 0) {
+ switch(opt) {
+ case 'L':
+ statfn = stat;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind == argc)
+ return COMMAND_ERROR_USAGE;
+
+ for (filename = &argv[optind]; *filename; filename++) {
+ ret = statfn(*filename, &st);
+
+ if (ret) {
+ printf("%s: %s: %m\n", argv[0], *filename);
+ exitcode = COMMAND_ERROR;
+ continue;
+ }
+
+ stat_print(*filename, &st);
+ }
+
+ return exitcode;
+}
+
+BAREBOX_CMD_HELP_START(stat)
+BAREBOX_CMD_HELP_TEXT("Display status information about the specified files")
+BAREBOX_CMD_HELP_TEXT("or directories.")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-L", "follow links")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(stat)
+ .cmd = do_stat,
+ BAREBOX_CMD_DESC("display file status")
+ BAREBOX_CMD_OPTS("[-L] [FILEDIR...]")
+ BAREBOX_CMD_GROUP(CMD_GRP_FILE)
+ BAREBOX_CMD_HELP(cmd_stat_help)
+BAREBOX_CMD_END
diff --git a/commands/uptime.c b/commands/uptime.c
new file mode 100644
index 0000000000..d67538631c
--- /dev/null
+++ b/commands/uptime.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <common.h>
+#include <command.h>
+#include <clock.h>
+#include <getopt.h>
+#include <linux/math64.h>
+
+#define NSEC_PER_MINUTE (NSEC_PER_SEC * 60LL)
+#define NSEC_PER_HOUR (NSEC_PER_MINUTE * 60LL)
+#define NSEC_PER_DAY (NSEC_PER_HOUR * 24LL)
+#define NSEC_PER_WEEK (NSEC_PER_DAY * 7LL)
+
+static bool print_with_unit(u64 val, const char *unit, bool comma)
+{
+ if (!val)
+ return comma;
+
+ printf("%s%llu %s%s", comma ? ", " : "", val, unit, val > 1 ? "s" : "");
+ return true;
+}
+
+static int do_uptime(int argc, char *argv[])
+{
+ u64 timestamp, weeks, days, hours, minutes;
+ bool comma = false;
+ int opt;
+
+ timestamp = get_time_ns();
+
+ while((opt = getopt(argc, argv, "n")) > 0) {
+ switch(opt) {
+ case 'n':
+ printf("up %lluns\n", timestamp);
+ return 0;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (optind != argc)
+ return COMMAND_ERROR_USAGE;
+
+ printf("up ");
+
+ weeks = div64_u64_rem(timestamp, NSEC_PER_WEEK, &timestamp);
+ days = div64_u64_rem(timestamp, NSEC_PER_DAY, &timestamp);
+ hours = div64_u64_rem(timestamp, NSEC_PER_HOUR, &timestamp);
+ minutes = div64_u64_rem(timestamp, NSEC_PER_MINUTE, &timestamp);
+
+ comma = print_with_unit(weeks, "week", false);
+ comma = print_with_unit(days, "day", comma);
+ comma = print_with_unit(hours, "hour", comma);
+ comma = print_with_unit(minutes, "minute", comma);
+
+ if (!comma) {
+ u64 seconds = div64_u64_rem(timestamp, NSEC_PER_SEC, &timestamp);
+ print_with_unit(seconds, "second", false);
+ }
+
+ printf("\n");
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(uptime)
+BAREBOX_CMD_HELP_TEXT("This command formats the number of elapsed nanoseconds")
+BAREBOX_CMD_HELP_TEXT("as measured with the current clocksource")
+BAREBOX_CMD_HELP_TEXT("Note: Timekeeping is co-operative. If long running code does")
+BAREBOX_CMD_HELP_TEXT("not use delay/is_timeout/get_time_ns/getchar functions")
+BAREBOX_CMD_HELP_TEXT("timer may overrun resulting in incorrect results")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-n", "output elapsed time in nanoseconds")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(uptime)
+ .cmd = do_uptime,
+ BAREBOX_CMD_DESC("Tell how long barebox has been running")
+ BAREBOX_CMD_OPTS("[-n]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_HELP(cmd_uptime_help)
+BAREBOX_CMD_END