Skip to contentSkip to conversation

tools: kwboot: Allow to use -b without image path as the last getopt() option

PATCH In review Pali Rohár 2 participants 3 messages Feb 7, 2022 – Feb 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: kwboot: Allow to use -b without image path as the last getopt() option

Currently it is possible to call "kwboot -b -t /dev/ttyUSB0" but not to call "kwboot -b /dev/ttyUSB0".

Fix it by not trying to process the last argv[], which is non-getopt() option (tty path) as the image path for -b.

Fixes c513fe47dca2 ("tools: kwboot: Allow to use option -b without image path")
---
 tools/kwboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/kwboot.c +1 -1
index 7737188f0d0a..68c0ef1f1b07 100644
@@ -1770,7 +1770,7 @@ main(int argc, char **argv)
 			bootmsg = kwboot_msg_boot;
 			if (prev_optind == optind)
 				goto usage;
-			if (argv[optind] && argv[optind][0] != '-')
+			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
 				imgpath = argv[optind++];
 			break;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 11 lines · Pali Rohár

Currently it is possible to call "kwboot -b -t /dev/ttyUSB0" but not to call "kwboot -b /dev/ttyUSB0".

Fix it by not trying to process the last argv[], which is non-getopt() option (tty path) as the image path for -b.

Fixes c513fe47dca2 ("tools: kwboot: Allow to use option -b without image path")

Please correct me if I am wrong but AFAIU, this change makes it possible to use kwboot to also boot images on some of the Armada 64 bit platforms, as commented and tested by Marcel.

If this is the case, could you please update the documentation or at least add a note with some comments to the commit text?

Thanks,
Stefan

Quoted 9 lines
---
  tools/kwboot.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/kwboot.c +0 -0
index 7737188f0d0a..68c0ef1f1b07 100644

tools/kwboot.c main(int argc, char **argv) · line 1776

Quoted 8 lines
tools/kwboot.c +1 -1
@@ -1770,7 +1770,7 @@ main(int argc, char **argv)
  			bootmsg = kwboot_msg_boot;
  			if (prev_optind == optind)
  				goto usage;
-			if (argv[optind] && argv[optind][0] != '-')
+			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
  				imgpath = argv[optind++];
  			break;
 

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#2 lore raw
In reply to Pali Rohár
Quoted 11 lines · Pali Rohár

Currently it is possible to call "kwboot -b -t /dev/ttyUSB0" but not to call "kwboot -b /dev/ttyUSB0".

Fix it by not trying to process the last argv[], which is non-getopt() option (tty path) as the image path for -b.

Fixes c513fe47dca2 ("tools: kwboot: Allow to use option -b without image path")

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 9 lines
---
  tools/kwboot.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/kwboot.c +0 -0
index 7737188f0d0a..68c0ef1f1b07 100644

tools/kwboot.c main(int argc, char **argv) · line 1776

Quoted 8 lines
tools/kwboot.c +1 -1
@@ -1770,7 +1770,7 @@ main(int argc, char **argv)
  			bootmsg = kwboot_msg_boot;
  			if (prev_optind == optind)
  				goto usage;
-			if (argv[optind] && argv[optind][0] != '-')
+			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
  				imgpath = argv[optind++];
  			break;
 

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]