diff mbox series

[u-boot-marvell,08/14] tools: kwboot: Allow to use option -b without image path

Message ID 20220125171313.14498-9-kabel@kernel.org
State Accepted
Commit c513fe47dca24de87a904ce7d71cfd8a390e1154
Delegated to: Stefan Roese
Headers show
Series Another set of kwboot improvements | expand

Commit Message

Marek Behún Jan. 25, 2022, 5:13 p.m. UTC
From: Pali Rohár <pali@kernel.org>

Allow option -b without image path parameter, to send boot pattern and
wait for response but not send any image. This allows to use kwboot just
for processing boot pattern and user can use any other xmodem tool for
transferring the image itself (e.g. sx). Useful for debugging purposes.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 tools/kwboot.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

Comments

Stefan Roese Jan. 26, 2022, 3:39 p.m. UTC | #1
On 1/25/22 18:13, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> Allow option -b without image path parameter, to send boot pattern and
> wait for response but not send any image. This allows to use kwboot just
> for processing boot pattern and user can use any other xmodem tool for
> transferring the image itself (e.g. sx). Useful for debugging purposes.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   tools/kwboot.c | 22 +++++++++++++++++-----
>   1 file changed, 17 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/kwboot.c b/tools/kwboot.c
> index 1dcec1969a..c413a8bf51 100644
> --- a/tools/kwboot.c
> +++ b/tools/kwboot.c
> @@ -1699,6 +1699,8 @@ main(int argc, char **argv)
>   	size_t size;
>   	size_t after_img_rsv;
>   	int baudrate;
> +	int prev_optind;
> +	int c;
>   
>   	rv = 1;
>   	tty = -1;
> @@ -1716,22 +1718,32 @@ main(int argc, char **argv)
>   	kwboot_verbose = isatty(STDOUT_FILENO);
>   
>   	do {
> -		int c = getopt(argc, argv, "hb:ptaB:dD:q:s:o:");
> +		prev_optind = optind;
> +		c = getopt(argc, argv, "hbptaB:dD:q:s:o:");
>   		if (c < 0)
>   			break;
>   
>   		switch (c) {
>   		case 'b':
> +			if (imgpath || bootmsg || debugmsg)
> +				goto usage;
>   			bootmsg = kwboot_msg_boot;
> -			imgpath = optarg;
> +			if (prev_optind == optind)
> +				goto usage;
> +			if (argv[optind] && argv[optind][0] != '-')
> +				imgpath = argv[optind++];
>   			break;
>   
>   		case 'D':
> +			if (imgpath || bootmsg || debugmsg)
> +				goto usage;
>   			bootmsg = NULL;
>   			imgpath = optarg;
>   			break;
>   
>   		case 'd':
> +			if (imgpath || bootmsg || debugmsg)
> +				goto usage;
>   			debugmsg = kwboot_msg_debug;
>   			break;
>   
> @@ -1774,11 +1786,11 @@ main(int argc, char **argv)
>   	if (!bootmsg && !term && !debugmsg)
>   		goto usage;
>   
> -	if (argc - optind < 1)
> -		goto usage;
> -
>   	ttypath = argv[optind++];
>   
> +	if (optind != argc)
> +		goto usage;
> +
>   	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
>   	if (tty < 0) {
>   		perror(ttypath);

Viele Grüße,
Stefan Roese
diff mbox series

Patch

diff --git a/tools/kwboot.c b/tools/kwboot.c
index 1dcec1969a..c413a8bf51 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -1699,6 +1699,8 @@  main(int argc, char **argv)
 	size_t size;
 	size_t after_img_rsv;
 	int baudrate;
+	int prev_optind;
+	int c;
 
 	rv = 1;
 	tty = -1;
@@ -1716,22 +1718,32 @@  main(int argc, char **argv)
 	kwboot_verbose = isatty(STDOUT_FILENO);
 
 	do {
-		int c = getopt(argc, argv, "hb:ptaB:dD:q:s:o:");
+		prev_optind = optind;
+		c = getopt(argc, argv, "hbptaB:dD:q:s:o:");
 		if (c < 0)
 			break;
 
 		switch (c) {
 		case 'b':
+			if (imgpath || bootmsg || debugmsg)
+				goto usage;
 			bootmsg = kwboot_msg_boot;
-			imgpath = optarg;
+			if (prev_optind == optind)
+				goto usage;
+			if (argv[optind] && argv[optind][0] != '-')
+				imgpath = argv[optind++];
 			break;
 
 		case 'D':
+			if (imgpath || bootmsg || debugmsg)
+				goto usage;
 			bootmsg = NULL;
 			imgpath = optarg;
 			break;
 
 		case 'd':
+			if (imgpath || bootmsg || debugmsg)
+				goto usage;
 			debugmsg = kwboot_msg_debug;
 			break;
 
@@ -1774,11 +1786,11 @@  main(int argc, char **argv)
 	if (!bootmsg && !term && !debugmsg)
 		goto usage;
 
-	if (argc - optind < 1)
-		goto usage;
-
 	ttypath = argv[optind++];
 
+	if (optind != argc)
+		goto usage;
+
 	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
 	if (tty < 0) {
 		perror(ttypath);