cmd: Add pause command
PATCH v2 1/1 cmd: Add pause command
This command is being introduced with the goal of allowing user-friendly "generic use case" U-Boot builds to pause until user input under some situations.
The main use case would be when a boot failure happens, to pause until the user has had time to acknowledge the current state.
Tested with sandbox using:
make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'
--- cmd/Kconfig | 7 +++++ cmd/Makefile | 1 + cmd/pause.c | 35 +++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + test/cmd/Makefile | 3 ++ test/cmd/test_pause.c | 62 +++++++++++++++++++++++++++++++++++++ 7 files changed, 110 insertions(+) create mode 100644 cmd/pause.c create mode 100644 test/cmd/test_pause.c
cmd/Kconfig +0 -0
@@ -1961,6 +1961,13 @@ config CMD_GETTIME milliseconds. See also the 'bootstage' command which
provides more flexibility for boot timing.
+config CMD_PAUSE
+ bool "pause command"
+ default n
+ help
+ Delay execution waiting for any user input.
+ Useful to allow the user to read a failure log.
+
config CMD_RNG
bool "rng command"
depends on DM_RNG
cmd/Makefile +1 -0
@@ -102,6 +102,7 @@ obj-$(CONFIG_CMD_MFSL) += mfsl.o obj-$(CONFIG_CMD_MII) += mii.o obj-$(CONFIG_CMD_MISC) += misc.o obj-$(CONFIG_CMD_MDIO) += mdio.o +obj-$(CONFIG_CMD_PAUSE) += pause.o obj-$(CONFIG_CMD_SLEEP) += sleep.o obj-$(CONFIG_CMD_MMC) += mmc.o obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
cmd/pause.c new file +10 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* (C) Copyright 2021 +* Samuel Dionne-Riel <[email protected]> +*/ + +#include <command.h> +#include <stdio.h> + +static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char
*const argv[]) +{
+ char *message = "Press any key to continue...";
+
+ if (argc > 2)
+ return CMD_RET_USAGE;
+
+ if (argc == 2)
+ message = argv[1];
+
+ /* No newline, so it sticks to the bottom of the screen */
+ printf("%s", message);
+
+ /* Wait on "any" key... */
+ (void) getchar();
+
+ /* Since there was no newline, we need it now. */
+ printf("\n");
+
+ return CMD_RET_SUCCESS;
+}
+
+U_BOOT_CMD(pause, 2, 1, do_pause,
+ "delay until user input",
+ "pause [prompt] - Wait until users presses any key. [prompt]
can be used to customize the message.\n" +);
configs/sandbox64_defconfig +1 -0
@@ -67,6 +67,7 @@ CONFIG_CMD_BMP=y CONFIG_CMD_EFIDEBUG=y CONFIG_CMD_RTC=y CONFIG_CMD_TIME=y +CONFIG_CMD_PAUSE=y CONFIG_CMD_TIMER=y CONFIG_CMD_SOUND=y CONFIG_CMD_QFW=y
configs/sandbox_defconfig +1 -0
@@ -96,6 +96,7 @@ CONFIG_CMD_BOOTCOUNT=y CONFIG_CMD_EFIDEBUG=y CONFIG_CMD_RTC=y CONFIG_CMD_TIME=y +CONFIG_CMD_PAUSE=y CONFIG_CMD_TIMER=y CONFIG_CMD_SOUND=y CONFIG_CMD_QFW=y
test/cmd/Makefile +3 -0
@@ -5,6 +5,9 @@ ifdef CONFIG_HUSH_PARSER obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o endif +ifdef CONFIG_CONSOLE_RECORD +obj-$(CONFIG_CMD_PAUSE) += test_pause.o +endif obj-y += mem.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_FDT) += fdt.o
test/cmd/test_pause.c new file +49 -0
49 lines not on this page · raw message
pause. */
+ if (pause_data[i].expected_ret == 0)
+ console_in_puts("\n");
+ ut_asserteq(pause_data[i].expected_ret,run_command(pause_data[i].cmd, 0));
+ ut_unsilence_console(uts);
+ console_record_readline(uts->actual_str,
+ sizeof(uts->actual_str));
+ ut_asserteq_str(pause_data[i].expected,uts->actual_str);
+ ut_asserteq(pause_data[i].expected_ret,ut_check_console_end(uts));
+ }
+ return 0;
+}
+
+LIB_TEST(lib_test_hush_pause, 0);
Signature · 5 lines
2.35.1 -- Samuel Dionne-Riel