Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9599AC00140 for ; Thu, 18 Aug 2022 19:44:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7681C8486B; Thu, 18 Aug 2022 21:44:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=dionne-riel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=dionne-riel-com.20210112.gappssmtp.com header.i=@dionne-riel-com.20210112.gappssmtp.com header.b="jzbkaFEn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ACAC78487B; Thu, 18 Aug 2022 21:44:13 +0200 (CEST) Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 92FA78485C for ; Thu, 18 Aug 2022 21:44:10 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=dionne-riel.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=samuel@dionne-riel.com Received: by mail-qv1-xf29.google.com with SMTP id mn10so1938555qvb.10 for ; Thu, 18 Aug 2022 12:44:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dionne-riel-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :from:date:from:to:cc; bh=CbHYPF7RUhGU/4KyD4eAFjqwt+dW5ryV4dB5oG67Iwc=; b=jzbkaFEnjsAwxNvwAxcrZGNNcjNMBiTWfz8Mj1aFEoWetK0AXJHKCiG2ubDWP2zA+E pXFgh0fJuv1ath7gqaxjxCjZuIrGLkkmIO3Akp5Y0tStZr/sKKzZuF27zPYKVztPRa7e 9AxxfvIercfb+QsGsG3LeW2GQ5jYL4b6XgUzwMmqsxCL6wrIHwLl5vuVKE/FsROrpnJd x+dgn+aEUG15ka99vDnYCY9UtV9R1zK96uvEo8CrkBUglnNXTO8t80WYPZJ/B3xczk/B xVtCOvf0x4bf/7MqYGWUJv3v3LUuacpjwEroXu2FEZ6PRUe/5mRL1Ax1Q+ZbZRBdjJiR G4mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:subject:cc:to :from:date:x-gm-message-state:from:to:cc; bh=CbHYPF7RUhGU/4KyD4eAFjqwt+dW5ryV4dB5oG67Iwc=; b=xw82DrailGVhwfJz+xz2RMJ3H12uTZE3emrj0Smzja8eOCP1GjW4E0UQQAqvA87h4F Is1r1rm262O+Q1RFXP0cpvhCveLmfKj/FkB/TWkPb0Il9lkVSVvGlKW/Ht5kiBPa6m22 B9xgWDSJsuWMqE/hVfHmyTwefG1TpLtyockvBOhXzCtbCfGCQLnRg+EBKKW5CfibsQER QAtMe/vCvlBkJY7aHfU54np7zjVVBCxfLba2fR6mSVo2d6be8k8ZbvrRIAsRY9Mi+fZ1 LvKxGcKVi7hIoi32mlbhJt1kXXBqGh29AGLxFMByGzpI3BfRnIzubaQODOcFXKUGgPOa VBsA== X-Gm-Message-State: ACgBeo0PkZ3Rj8X7J0CoWDfKMhcnIdBJ0V/pz1OACqoTCQaL8U26qZb/ pZYcynHGatu+//o8VOwuc7oRFNZIcTAp4A== X-Google-Smtp-Source: AA6agR4I4DGxBt+N5/bK/4COOvpwhlFBZYNju6J93chijvPVUMzujXUoV2IGsZC5ugKM7b7IbGId7Q== X-Received: by 2002:a0c:8dc9:0:b0:473:14fe:7c4e with SMTP id u9-20020a0c8dc9000000b0047314fe7c4emr3794462qvb.44.1660851848830; Thu, 18 Aug 2022 12:44:08 -0700 (PDT) Received: from DUFFMAN (135-23-195-85.cpe.pppoe.ca. [135.23.195.85]) by smtp.gmail.com with ESMTPSA id ca26-20020a05622a1f1a00b003445b83de67sm1638373qtb.3.2022.08.18.12.44.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Aug 2022 12:44:08 -0700 (PDT) Date: Thu, 18 Aug 2022 15:44:04 -0400 From: Samuel Dionne-Riel To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v4] cmd: Add pause command Message-ID: <20220818154404.70e84f5a.samuel@dionne-riel.com> X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean 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 Cc: Simon Glass --- Hi! I believe everything is addressed. I took the comment about the sort order being wonky as needing no changes. Changes for v4 - No functional change in command, mainly code style - Addressed nits - Added missing docs - Wrote test fully in code Changes for v3 - No functional change in patch - Sent with lines unwrapped - Added changelog Changes for v2 - Added test, as requested by Tom - Made CMD_PAUSE default n --- cmd/Kconfig | 6 +++++ cmd/Makefile | 1 + cmd/pause.c | 32 ++++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + doc/usage/cmd/pause.rst | 53 +++++++++++++++++++++++++++++++++++++ doc/usage/index.rst | 1 + test/cmd/Makefile | 3 +++ test/cmd/test_pause.c | 45 +++++++++++++++++++++++++++++++ 9 files changed, 143 insertions(+) create mode 100644 cmd/pause.c create mode 100644 doc/usage/cmd/pause.rst create mode 100644 test/cmd/test_pause.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 3625ff2a50b..e8d1f73cd0d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1961,6 +1961,12 @@ config CMD_GETTIME milliseconds. See also the 'bootstage' command which provides more flexibility for boot timing. +config CMD_PAUSE + bool "pause command" + 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 diff --git a/cmd/Makefile b/cmd/Makefile index 5e43a1e022e..98a6224bdc1 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -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 diff --git a/cmd/pause.c b/cmd/pause.c new file mode 100644 index 00000000000..c97833c0d70 --- /dev/null +++ b/cmd/pause.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2021 + * Samuel Dionne-Riel + */ + +#include +#include + +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) + 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", + "[prompt] - Wait until users presses any key. [prompt] can be used to customize the message.\n" +); diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 6553568e768..0af582d642d 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -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 diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index eba7bcbb483..d856d9b0942 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -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 diff --git a/doc/usage/cmd/pause.rst b/doc/usage/cmd/pause.rst new file mode 100644 index 00000000000..c79e399c020 --- /dev/null +++ b/doc/usage/cmd/pause.rst @@ -0,0 +1,53 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later: + +pause command +============= + +Synopsis +-------- + +:: + + pause [prompt] + + +Description +----------- + +The pause command delays execution waiting for any user input. + +It can accept a single parameter to change the prompt message. + +Examples +-------- + +Using with the default prompt: + +:: + + => pause + Press any key to continue... + + +Using with a custom prompt: + +:: + + => pause 'Prompt for pause...' + Prompt for pause... + +Note that complex prompts require proper quoting: + +:: + + => pause Prompt for pause... + pause - delay until user input + + Usage: + pause [prompt] - Wait until users presses any key. [prompt] can be used to customize the message. + +Return value +------------ + +The return value $? is always set to 0 (true), unless invoked in an invalid +manner. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 2ba8733b92c..decfc2cc843 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -51,6 +51,7 @@ Shell commands cmd/mbr cmd/md cmd/mmc + cmd/pause cmd/pinmux cmd/printenv cmd/pstore diff --git a/test/cmd/Makefile b/test/cmd/Makefile index c331757425e..1bb02d93a23 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -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 diff --git a/test/cmd/test_pause.c b/test/cmd/test_pause.c new file mode 100644 index 00000000000..2b85cce3271 --- /dev/null +++ b/test/cmd/test_pause.c @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for pause command + * + * Copyright 2022, Samuel Dionne-Riel + */ + +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +static int lib_test_hush_pause(struct unit_test_state *uts) +{ + /* Test default message */ + console_record_reset_enable(); + /* Cook a newline when the command is expected to pause */ + console_in_puts("\n"); + ut_assertok(run_command("pause", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_str("Press any key to continue...", uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + + /* Test provided message */ + console_record_reset_enable(); + /* Cook a newline when the command is expected to pause */ + console_in_puts("\n"); + ut_assertok(run_command("pause 'Prompt for pause...'", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_str("Prompt for pause...", uts->actual_str); + ut_assertok(ut_check_console_end(uts)); + + /* Test providing more than one params */ + console_record_reset_enable(); + /* No newline cooked here since the command is expected to fail */ + ut_asserteq(1, run_command("pause a b", 0)); + console_record_readline(uts->actual_str, sizeof(uts->actual_str)); + ut_asserteq_str("pause - delay until user input", uts->actual_str); + ut_asserteq(1, ut_check_console_end(uts)); + + return 0; +} +LIB_TEST(lib_test_hush_pause, 0); -- 2.35.1 -- Samuel Dionne-Riel