"Das U-Boot" Source Tree
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 using:

make && ./u-boot -v -T -c 'ut lib lib_test_hush_pause'

Signed-off-by: Samuel Dionne-Riel <samuel@dionne-riel.com>
Cc: Simon Glass <sjg@chromium.org>

authored by

Samuel Dionne-Riel and committed by
Tom Rini
dc0d17c2 d8826071

+143
+6
cmd/Kconfig
··· 1971 1971 milliseconds. See also the 'bootstage' command which provides more 1972 1972 flexibility for boot timing. 1973 1973 1974 + config CMD_PAUSE 1975 + bool "pause command" 1976 + help 1977 + Delay execution waiting for any user input. 1978 + Useful to allow the user to read a failure log. 1979 + 1974 1980 config CMD_RNG 1975 1981 bool "rng command" 1976 1982 depends on DM_RNG
+1
cmd/Makefile
··· 102 102 obj-$(CONFIG_CMD_MII) += mii.o 103 103 obj-$(CONFIG_CMD_MISC) += misc.o 104 104 obj-$(CONFIG_CMD_MDIO) += mdio.o 105 + obj-$(CONFIG_CMD_PAUSE) += pause.o 105 106 obj-$(CONFIG_CMD_SLEEP) += sleep.o 106 107 obj-$(CONFIG_CMD_MMC) += mmc.o 107 108 obj-$(CONFIG_CMD_OPTEE_RPMB) += optee_rpmb.o
+32
cmd/pause.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * (C) Copyright 2021 4 + * Samuel Dionne-Riel <samuel@dionne-riel.com> 5 + */ 6 + 7 + #include <command.h> 8 + #include <stdio.h> 9 + 10 + static int do_pause(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) 11 + { 12 + char *message = "Press any key to continue..."; 13 + 14 + if (argc == 2) 15 + message = argv[1]; 16 + 17 + /* No newline, so it sticks to the bottom of the screen */ 18 + printf("%s", message); 19 + 20 + /* Wait on "any" key... */ 21 + (void) getchar(); 22 + 23 + /* Since there was no newline, we need it now */ 24 + printf("\n"); 25 + 26 + return CMD_RET_SUCCESS; 27 + } 28 + 29 + U_BOOT_CMD(pause, 2, 1, do_pause, 30 + "delay until user input", 31 + "[prompt] - Wait until users presses any key. [prompt] can be used to customize the message.\n" 32 + );
+1
configs/sandbox64_defconfig
··· 67 67 CONFIG_CMD_EFIDEBUG=y 68 68 CONFIG_CMD_RTC=y 69 69 CONFIG_CMD_TIME=y 70 + CONFIG_CMD_PAUSE=y 70 71 CONFIG_CMD_TIMER=y 71 72 CONFIG_CMD_SOUND=y 72 73 CONFIG_CMD_QFW=y
+1
configs/sandbox_defconfig
··· 96 96 CONFIG_CMD_EFIDEBUG=y 97 97 CONFIG_CMD_RTC=y 98 98 CONFIG_CMD_TIME=y 99 + CONFIG_CMD_PAUSE=y 99 100 CONFIG_CMD_TIMER=y 100 101 CONFIG_CMD_SOUND=y 101 102 CONFIG_CMD_QFW=y
+53
doc/usage/cmd/pause.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0-or-later: 2 + 3 + pause command 4 + ============= 5 + 6 + Synopsis 7 + -------- 8 + 9 + :: 10 + 11 + pause [prompt] 12 + 13 + 14 + Description 15 + ----------- 16 + 17 + The pause command delays execution waiting for any user input. 18 + 19 + It can accept a single parameter to change the prompt message. 20 + 21 + Examples 22 + -------- 23 + 24 + Using with the default prompt: 25 + 26 + :: 27 + 28 + => pause 29 + Press any key to continue... 30 + 31 + 32 + Using with a custom prompt: 33 + 34 + :: 35 + 36 + => pause 'Prompt for pause...' 37 + Prompt for pause... 38 + 39 + Note that complex prompts require proper quoting: 40 + 41 + :: 42 + 43 + => pause Prompt for pause... 44 + pause - delay until user input 45 + 46 + Usage: 47 + pause [prompt] - Wait until users presses any key. [prompt] can be used to customize the message. 48 + 49 + Return value 50 + ------------ 51 + 52 + The return value $? is always set to 0 (true), unless invoked in an invalid 53 + manner.
+1
doc/usage/index.rst
··· 52 52 cmd/mbr 53 53 cmd/md 54 54 cmd/mmc 55 + cmd/pause 55 56 cmd/pinmux 56 57 cmd/printenv 57 58 cmd/pstore
+3
test/cmd/Makefile
··· 5 5 ifdef CONFIG_HUSH_PARSER 6 6 obj-$(CONFIG_CONSOLE_RECORD) += test_echo.o 7 7 endif 8 + ifdef CONFIG_CONSOLE_RECORD 9 + obj-$(CONFIG_CMD_PAUSE) += test_pause.o 10 + endif 8 11 obj-y += mem.o 9 12 obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o 10 13 obj-$(CONFIG_CMD_FDT) += fdt.o
+45
test/cmd/test_pause.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Tests for pause command 4 + * 5 + * Copyright 2022, Samuel Dionne-Riel <samuel@dionne-riel.com> 6 + */ 7 + 8 + #include <common.h> 9 + #include <asm/global_data.h> 10 + #include <test/lib.h> 11 + #include <test/ut.h> 12 + 13 + DECLARE_GLOBAL_DATA_PTR; 14 + 15 + static int lib_test_hush_pause(struct unit_test_state *uts) 16 + { 17 + /* Test default message */ 18 + console_record_reset_enable(); 19 + /* Cook a newline when the command is expected to pause */ 20 + console_in_puts("\n"); 21 + ut_assertok(run_command("pause", 0)); 22 + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); 23 + ut_asserteq_str("Press any key to continue...", uts->actual_str); 24 + ut_assertok(ut_check_console_end(uts)); 25 + 26 + /* Test provided message */ 27 + console_record_reset_enable(); 28 + /* Cook a newline when the command is expected to pause */ 29 + console_in_puts("\n"); 30 + ut_assertok(run_command("pause 'Prompt for pause...'", 0)); 31 + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); 32 + ut_asserteq_str("Prompt for pause...", uts->actual_str); 33 + ut_assertok(ut_check_console_end(uts)); 34 + 35 + /* Test providing more than one params */ 36 + console_record_reset_enable(); 37 + /* No newline cooked here since the command is expected to fail */ 38 + ut_asserteq(1, run_command("pause a b", 0)); 39 + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); 40 + ut_asserteq_str("pause - delay until user input", uts->actual_str); 41 + ut_asserteq(1, ut_check_console_end(uts)); 42 + 43 + return 0; 44 + } 45 + LIB_TEST(lib_test_hush_pause, 0);