Skip to contentSkip to conversation

CMD commands improvements

PATCH Superseded Svyatoslav Ryhel 3 participants 7 messages Jan 23, 2023 – Jan 24, 2023

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover CMD commands improvements

- add new command 'continue' which stops performing script until any key is pressed by user. It is useful for keeping logs in output device until user allows to continue script run.

- add ability for 'ums' command to interrupt run of usb mass storage with any key. This is especially useful on devices with limited input capabilities like tablets and smatphones which have only gpio keys in direct access. Current implementation uses Kconfig entry.

Svyatoslav Ryhel (2):
cmd: exit: add continue on key press command
cmd: ums: abort mounting by pressing any key

 cmd/Kconfig            |  6 ++++++
 cmd/exit.c             | 17 +++++++++++++++++
 cmd/usb_mass_storage.c |  9 +++++++++
 3 files changed, 32 insertions(+)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 cmd: exit: add continue on key press command

This command stops performing script until any key is pressed. It is useful for keeping logs
on screen until user decides to continue.

---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
cmd/exit.c +17 -0
index 7bf241ec73..673b4b6be7 100644
@@ -7,6 +7,17 @@
 #include <common.h>
 #include <command.h>
 
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+		       char *const argv[])
+{
+	while (true) {
+		if (getchar())
+			break;
+	}
+
+	return 0;
+}
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
 		   char *const argv[])
 {
@@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
 	return -r - 2;
 }
 
+U_BOOT_CMD(
+	continue,	1,	0,	do_continue,
+	"continue script on key pressed",
+	""
+);
+
 U_BOOT_CMD(
 	exit,	2,	1,	do_exit,
 	"exit script",
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH v1 1/2] cmd: exit: add continue on key press command

Quoted 5 lines · Svyatoslav Ryhel

This command stops performing script until any key is pressed. It is useful for keeping logs
on screen until user decides to continue.

Quoted 7 lines
---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Please add a file in doc/usage/cmd

Also how about a test?

Quoted 36 lines
cmd/exit.c +17 -1
index 7bf241ec73..673b4b6be7 100644
@@ -7,6 +7,17 @@
 #include <common.h>
 #include <command.h>
 
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       while (true) {
+               if (getchar())
+                       break;
+       }
+
+       return 0;
+}
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
                   char *const argv[])
 {
@@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
        return -r - 2;
 }
 
+U_BOOT_CMD(
+       continue,       1,      0,      do_continue,
+       "continue script on key pressed",
+       ""
+);
+
 U_BOOT_CMD(
        exit,   2,      1,      do_exit,
        "exit script",
--
Quoted 2 lines

2.25.1

Regards,
Simon

#3 lore raw

Re: [PATCH v1 1/2] cmd: exit: add continue on key press command

Am 23. Januar 2023 23:25:41 MEZ schrieb Simon Glass <[email protected]>:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 5 lines

This command stops performing script until any key is pressed. It is useful for keeping logs
on screen until user decides to continue.

Quoted 7 lines
---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Please add a file in doc/usage/cmd

Also how about a test?

Quoted 8 lines
cmd/exit.c +0 -0
index 7bf241ec73..673b4b6be7 100644
@@ -7,6 +7,17 @@
 #include <common.h>
 #include <command.h>
 
Quoted 10 lines

cmd/exit.c line 19

Quoted 10 lines
cmd/exit.c +10 -0
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       while (true) {
+               if (getchar())
+                       break;
+       }
+
+       return 0;
+}

We already have the sleep command which waits until CTRL+C is pressed or a time interval has elapsed.

Why does that command not satisfy the use case?

The command name continue is used in other languages for control structures. We should not use it for pausing.

We should not put a new command into an existing C module without good reason.

Best regards

Heinrich

Quoted 23 lines
Quoted 18 lines
cmd/exit.c +7 -1
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
                   char *const argv[])
 {
@@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
        return -r - 2;
 }
 
+U_BOOT_CMD(
+       continue,       1,      0,      do_continue,
+       "continue script on key pressed",
+       ""
+);
+
 U_BOOT_CMD(
        exit,   2,      1,      do_exit,
        "exit script",
--
Quoted 2 lines

2.25.1

Regards,
Simon

#4 lore raw

Re: [PATCH v1 1/2] cmd: exit: add continue on key press command

вт, 24 січ. 2023 р. о 00:43 Heinrich Schuchardt <[email protected]> пише:

Quoted 30 lines

Am 23. Januar 2023 23:25:41 MEZ schrieb Simon Glass <[email protected]>:

Quoted 26 lines · Svyatoslav Ryhel
Quoted 5 lines

This command stops performing script until any key is pressed. It is useful for keeping logs
on screen until user decides to continue.

Quoted 7 lines
---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Please add a file in doc/usage/cmd

Also how about a test?

Quoted 8 lines
cmd/exit.c +0 -0
index 7bf241ec73..673b4b6be7 100644
@@ -7,6 +7,17 @@
 #include <common.h>
 #include <command.h>
 
Quoted 10 lines
Quoted 10 lines

cmd/exit.c line 19

Quoted 10 lines
cmd/exit.c +10 -0
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       while (true) {
+               if (getchar())
+                       break;
+       }
+
+       return 0;
+}

Hello, Heinrich!

Quoted 1 line

We already have the sleep command which waits until CTRL+C is pressed or a time interval has elapsed.

You are correct, this commit duplicates same command, but not sleep. Pause command was merged 2022.09 while I have made this command approx. a year ago and did not check since then if any new commands were added. This commit will be dropped in V2, but the second commit in this patchset has no other implementations.

Quoted 1 line

Why does that command not satisfy the use case?

My keyboard has only 3 keys: up, down and enter. I have no luxury of a 108 key keyboard.

Quoted 8 lines

The command name continue is used in other languages for control structures. We should not use it for pausing.

We should not put a new command into an existing C module without good reason.

Best regards

Heinrich

Thanks for your review.
Best regards, Svyatoslav R.

Quoted 24 lines
Quoted 24 lines
Quoted 19 lines
cmd/exit.c +7 -1
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
                   char *const argv[])
 {
@@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
        return -r - 2;
 }
 
+U_BOOT_CMD(
+       continue,       1,      0,      do_continue,
+       "continue script on key pressed",
+       ""
+);
+
 U_BOOT_CMD(
        exit,   2,      1,      do_exit,
        "exit script",
--
Quoted 2 lines

2.25.1

Regards,
Simon

#5 lore raw

Re: [PATCH v1 1/2] cmd: exit: add continue on key press command

In reply to Simon Glass

Hello Simon!

Thanks for your review. Heinrich Schuchardt made a valid remark that command with such functionality already exists. It is called - pause - and my commit fully duplicates it.

Pause command was merged 2022.09 while I have made this command approx. a year ago in my fork and did not check since then if any new commands were added. This commit will be dropped in V2, but the second commit in this patchset, seems, to have no other implementations.

Best regards, Svyatoslav R.

вт, 24 січ. 2023 р. о 00:25 Simon Glass <[email protected]> пише:

Quoted 60 lines · Svyatoslav Ryhel
Quoted 5 lines

This command stops performing script until any key is pressed. It is useful for keeping logs
on screen until user decides to continue.

Quoted 7 lines
---
 cmd/exit.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Please add a file in doc/usage/cmd

Also how about a test?

Quoted 36 lines
cmd/exit.c +17 -1
index 7bf241ec73..673b4b6be7 100644
@@ -7,6 +7,17 @@
 #include <common.h>
 #include <command.h>
 
+static int do_continue(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
+{
+       while (true) {
+               if (getchar())
+                       break;
+       }
+
+       return 0;
+}
+
 static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
                   char *const argv[])
 {
@@ -19,6 +30,12 @@ static int do_exit(struct cmd_tbl *cmdtp, int flag, int argc,
        return -r - 2;
 }
 
+U_BOOT_CMD(
+       continue,       1,      0,      do_continue,
+       "continue script on key pressed",
+       ""
+);
+
 U_BOOT_CMD(
        exit,   2,      1,      do_exit,
        "exit script",
--
Quoted 2 lines

2.25.1

Regards,
Simon

#6 lore raw

PATCH 2/2 cmd: ums: abort mounting by pressing any key

In reply to Svyatoslav Ryhel

This patch introduses config which allows interrupt run of usb mass storage with any key. This is especially useful on devices with limited input capabilities like tablets and smatphones which have only gpio keys in direct access.

---
 cmd/Kconfig            | 6 ++++++
 cmd/usb_mass_storage.c | 9 +++++++++
 2 files changed, 15 insertions(+)
cmd/Kconfig +6 -0
index 4fe2c75de2..5c177f87ea 100644
@@ -1536,6 +1536,12 @@ config CMD_USB_MASS_STORAGE
 	  export a block device: U-Boot, the USB device, acts as a simple
 	  external hard drive plugged on the host USB port.
 
+config UMS_ABORT_KEYED
+	bool "UMS abort with any key"
+	depends on CMD_USB_MASS_STORAGE
+	help
+	  Allow interruption of usb mass storage run with any key pressed.
+
 config CMD_PVBLOCK
 	bool "Xen para-virtualized block device"
 	depends on XEN
cmd/usb_mass_storage.c +9 -0
index b7daaa6e8e..ade81013d0 100644
@@ -231,6 +231,15 @@ static int do_usb_mass_storage(struct cmd_tbl *cmdtp, int flag,
 			goto cleanup_register;
 		}
 
+		if (IS_ENABLED(CONFIG_UMS_ABORT_KEYED)) {
+			/* Abort by pressing any key */
+			if (getchar()) {
+				printf("\rOperation aborted.\n");
+				rc = CMD_RET_SUCCESS;
+				goto cleanup_register;
+			}
+		}
+
 		schedule();
 	}
 
Signature · 1 line
2.25.1