Skip to contentSkip to conversation

tools: kwboot: Allow to specify custom baudrate only in supported operations

PATCH In review Pali Rohár 3 participants 11 messages Mar 7, 2022 – Mar 14, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 tools: kwboot: Allow to specify custom baudrate only in supported operations

Custom baudrate different than 115200 may be specified only when kwboot is not going to send boot/debug message pattern or when it is going to send boot message pattern with image file (in which case baudrate change happens after sending kwbimage header). BootROM detects boot/debug message pattern only at baudrate 115200.

---
 tools/kwboot.c | 6 ++++++
 1 file changed, 6 insertions(+)
tools/kwboot.c +6 -0
index 69d1be0f4823..986f27c2012a 100644
@@ -2133,6 +2133,12 @@ main(int argc, char **argv)
 	if (optind != argc)
 		goto usage;
 
+	/* boot and debug message use baudrate 115200 */
+	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
+		fprintf(stderr, "Baudrate other than 115200 cannot be used for this operation.\n");
+		goto usage;
+	}
+
 	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
 	if (tty < 0) {
 		perror(ttypath);
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 2/3 tools: kwboot: Check if baudrate value is supported before sending image

Call kwboot_open_tty() which baudrate value which was specified at the command line by option -B. This function returns error if baudrate is not supported by selected tty device.

Initial baudrate for image transfer is always 115200, so call kwboot_tty_change_baudrate() with value 115200 immediately after kwboot_open_tty() if baudrate specified by option -B is different than 115200.

This makes kwboot fail immediately, informing that baudrate is unsupported, instead of failing only after the first part of image is already sent.

---
 tools/kwboot.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
tools/kwboot.c +13 -1
index 986f27c2012a..3b45e19a30aa 100644
@@ -2139,12 +2139,24 @@ main(int argc, char **argv)
 		goto usage;
 	}
 
-	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
+	tty = kwboot_open_tty(ttypath, baudrate);
 	if (tty < 0) {
 		perror(ttypath);
 		goto out;
 	}
 
+	/*
+	 * initial baudrate for image transfer is always 115200,
+	 * the change to different baudrate is done only after the header is sent
+	 */
+	if (imgpath && baudrate != 115200) {
+		rc = kwboot_tty_change_baudrate(tty, 115200);
+		if (rc) {
+			perror(ttypath);
+			goto out;
+		}
+	}
+
 	if (baudrate == 115200)
 		/* do not change baudrate during Xmodem to the same value */
 		baudrate = 0;
Signature · 1 line
2.20.1
#3 lore raw

PATCH v2 3/3 tools: kwboot: Allow to mix positional arguments with option -b

In reply to Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
 tools/kwboot.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +14 -4
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
 			bootmsg = 1;
 			if (prev_optind == optind)
 				goto usage;
-			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+			/* Option -b could have optional argument which specify image path */
+			if (optind < argc && argv[optind] && argv[optind][0] != '-')
 				imgpath = argv[optind++];
 			break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
 	if (!bootmsg && !term && !debugmsg && !imgpath)
 		goto usage;
 
-	ttypath = argv[optind++];
-
-	if (optind != argc)
+	/*
+	 * If there is no remaining argument but optional imgpath was parsed
+	 * then it means that optional imgpath was eaten by getopt parser.
+	 * Reassing imgpath to required ttypath argument.
+	 */
+	if (optind == argc && imgpath) {
+		ttypath = imgpath;
+		imgpath = NULL;
+	} else if (optind + 1 == argc) {
+		ttypath = argv[optind];
+	} else {
 		goto usage;
+	}
 
 	/* boot and debug message use baudrate 115200 */
 	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
Signature · 1 line
2.20.1
Tested-by on v2 3/3
#4 lore raw

Re: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b

Hi Pali,

I've tested this patch series and it's all working fine!

Thanks,
Tony

Tested-by Tony Dinh <mibodhi at gmail.com>
Quoted 58 lines · Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
 tools/kwboot.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +14 -5
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
                        bootmsg = 1;
                        if (prev_optind == optind)
                                goto usage;
-                       if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+                       /* Option -b could have optional argument which specify image path */
+                       if (optind < argc && argv[optind] && argv[optind][0] != '-')
                                imgpath = argv[optind++];
                        break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
        if (!bootmsg && !term && !debugmsg && !imgpath)
                goto usage;
 
-       ttypath = argv[optind++];
-
-       if (optind != argc)
+       /*
+        * If there is no remaining argument but optional imgpath was parsed
+        * then it means that optional imgpath was eaten by getopt parser.
+        * Reassing imgpath to required ttypath argument.
+        */
+       if (optind == argc && imgpath) {
+               ttypath = imgpath;
+               imgpath = NULL;
+       } else if (optind + 1 == argc) {
+               ttypath = argv[optind];
+       } else {
                goto usage;
+       }
 
        /* boot and debug message use baudrate 115200 */
        if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
--

2.20.1

Reviewed-by on v2 1/3
#9 lore raw
In reply to Pali Rohár
Quoted 7 lines · Pali Rohár

Custom baudrate different than 115200 may be specified only when kwboot is not going to send boot/debug message pattern or when it is going to send boot message pattern with image file (in which case baudrate change happens after sending kwbimage header). BootROM detects boot/debug message pattern only at baudrate 115200.

Thanks,
Stefan

Quoted 11 lines
---
  tools/kwboot.c | 6 ++++++
  1 file changed, 6 insertions(+)
tools/kwboot.c +0 -0
index 69d1be0f4823..986f27c2012a 100644
@@ -2133,6 +2133,12 @@ main(int argc, char **argv)
  	if (optind != argc)
  		goto usage;

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

Quoted 10 lines
tools/kwboot.c +6 -0
 
+	/* boot and debug message use baudrate 115200 */
+	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
+		fprintf(stderr, "Baudrate other than 115200 cannot be used for this operation.\n");
+		goto usage;
+	}
+
  	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
  	if (tty < 0) {
  		perror(ttypath);

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]
Reviewed-by on v2 2/3
#2 lore raw

Re: [PATCH v2 2/3] tools: kwboot: Check if baudrate value is supported before sending image

In reply to Pali Rohár
Quoted 9 lines · Pali Rohár

Call kwboot_open_tty() which baudrate value which was specified at the command line by option -B. This function returns error if baudrate is not supported by selected tty device.

Initial baudrate for image transfer is always 115200, so call kwboot_tty_change_baudrate() with value 115200 immediately after kwboot_open_tty() if baudrate specified by option -B is different than 115200.

Quoted 4 lines

This makes kwboot fail immediately, informing that baudrate is unsupported, instead of failing only after the first part of image is already sent.

Thanks,
Stefan

Quoted 24 lines
---
  tools/kwboot.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
tools/kwboot.c +6 -1
index 986f27c2012a..3b45e19a30aa 100644
@@ -2139,12 +2139,24 @@ main(int argc, char **argv)
  		goto usage;
  	}
 
-	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
+	tty = kwboot_open_tty(ttypath, baudrate);
  	if (tty < 0) {
  		perror(ttypath);
  		goto out;
  	}
 
+	/*
+	 * initial baudrate for image transfer is always 115200,
+	 * the change to different baudrate is done only after the header is sent
+	 */
+	if (imgpath && baudrate != 115200) {

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

Quoted 10 lines
tools/kwboot.c +7 -0
+		rc = kwboot_tty_change_baudrate(tty, 115200);
+		if (rc) {
+			perror(ttypath);
+			goto out;
+		}
+	}
+
  	if (baudrate == 115200)
  		/* do not change baudrate during Xmodem to the same value */
  		baudrate = 0;

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]
Reviewed-by on v2 3/3
#7 lore raw

Re: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b

In reply to Pali Rohár
Quoted 10 lines · Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

   kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

Thanks,
Stefan

Quoted 34 lines

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
  tools/kwboot.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +8 -4
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
  			bootmsg = 1;
  			if (prev_optind == optind)
  				goto usage;
-			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+			/* Option -b could have optional argument which specify image path */
+			if (optind < argc && argv[optind] && argv[optind][0] != '-')
  				imgpath = argv[optind++];
  			break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
  	if (!bootmsg && !term && !debugmsg && !imgpath)
  		goto usage;
 
-	ttypath = argv[optind++];
-
-	if (optind != argc)
+	/*
+	 * If there is no remaining argument but optional imgpath was parsed
+	 * then it means that optional imgpath was eaten by getopt parser.
+	 * Reassing imgpath to required ttypath argument.
+	 */
+	if (optind == argc && imgpath) {

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

Quoted 10 lines
tools/kwboot.c +6 -0
+		ttypath = imgpath;
+		imgpath = NULL;
+	} else if (optind + 1 == argc) {
+		ttypath = argv[optind];
+	} else {
  		goto usage;
+	}
 
  	/* boot and debug message use baudrate 115200 */
  	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {

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]
#5 lore raw

Re: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b

In reply to Tony Dinh
Quoted 3 lines · On Monday 07 March 2022 21:23:29 Tony Dinh wrote:

Hi Pali,

I've tested this patch series and it's all working fine!

Perfect!

Stefan, I think that this change should go into 2022.04 as it is fixing regression introduced during 2022.04 development.

Could you do more checks/testing of kwboot if everything is also working fine for you?

Quoted 65 lines

Thanks,
Tony

Tested-by Tony Dinh <mibodhi at gmail.com>
Quoted 58 lines · Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
 tools/kwboot.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +14 -5
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
                        bootmsg = 1;
                        if (prev_optind == optind)
                                goto usage;
-                       if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+                       /* Option -b could have optional argument which specify image path */
+                       if (optind < argc && argv[optind] && argv[optind][0] != '-')
                                imgpath = argv[optind++];
                        break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
        if (!bootmsg && !term && !debugmsg && !imgpath)
                goto usage;
 
-       ttypath = argv[optind++];
-
-       if (optind != argc)
+       /*
+        * If there is no remaining argument but optional imgpath was parsed
+        * then it means that optional imgpath was eaten by getopt parser.
+        * Reassing imgpath to required ttypath argument.
+        */
+       if (optind == argc && imgpath) {
+               ttypath = imgpath;
+               imgpath = NULL;
+       } else if (optind + 1 == argc) {
+               ttypath = argv[optind];
+       } else {
                goto usage;
+       }
 
        /* boot and debug message use baudrate 115200 */
        if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
--

2.20.1

#6 lore raw

Re: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b

Quoted 9 lines · Pali Rohár
Quoted 3 lines · On Monday 07 March 2022 21:23:29 Tony Dinh wrote:

Hi Pali,

I've tested this patch series and it's all working fine!

Perfect!

Stefan, I think that this change should go into 2022.04 as it is fixing regression introduced during 2022.04 development.

I agree.

Quoted 2 lines

Could you do more checks/testing of kwboot if everything is also working fine for you?

I'll try to do this later this week, yes.

Thanks,
Stefan

Quoted 60 lines
Quoted 60 lines

Thanks,
Tony

Tested-by Tony Dinh <mibodhi at gmail.com>
Quoted 53 lines · Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

   kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
  tools/kwboot.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +14 -4
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
                         bootmsg = 1;
                         if (prev_optind == optind)
                                 goto usage;
-                       if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+                       /* Option -b could have optional argument which specify image path */
+                       if (optind < argc && argv[optind] && argv[optind][0] != '-')
                                 imgpath = argv[optind++];
                         break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
         if (!bootmsg && !term && !debugmsg && !imgpath)
                 goto usage;
 
-       ttypath = argv[optind++];
-
-       if (optind != argc)
+       /*
+        * If there is no remaining argument but optional imgpath was parsed
+        * then it means that optional imgpath was eaten by getopt parser.
+        * Reassing imgpath to required ttypath argument.
+        */
+       if (optind == argc && imgpath) {
+               ttypath = imgpath;
+               imgpath = NULL;
+       } else if (optind + 1 == argc) {
+               ttypath = argv[optind];
+       } else {
                 goto usage;
+       }
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
tools/kwboot.c +0 -1
         /* boot and debug message use baudrate 115200 */
         if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
--

2.20.1

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]
#10 lore raw
In reply to Pali Rohár
Quoted 7 lines · Pali Rohár

Custom baudrate different than 115200 may be specified only when kwboot is not going to send boot/debug message pattern or when it is going to send boot message pattern with image file (in which case baudrate change happens after sending kwbimage header). BootROM detects boot/debug message pattern only at baudrate 115200.

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 11 lines
---
  tools/kwboot.c | 6 ++++++
  1 file changed, 6 insertions(+)
tools/kwboot.c +0 -0
index 69d1be0f4823..986f27c2012a 100644
@@ -2133,6 +2133,12 @@ main(int argc, char **argv)
  	if (optind != argc)
  		goto usage;

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

Quoted 10 lines
tools/kwboot.c +6 -0
 
+	/* boot and debug message use baudrate 115200 */
+	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
+		fprintf(stderr, "Baudrate other than 115200 cannot be used for this operation.\n");
+		goto usage;
+	}
+
  	tty = kwboot_open_tty(ttypath, imgpath ? 115200 : baudrate);
  	if (tty < 0) {
  		perror(ttypath);

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]
#8 lore raw

Re: [PATCH v2 3/3] tools: kwboot: Allow to mix positional arguments with option -b

In reply to Pali Rohár
Quoted 10 lines · Pali Rohár

Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments:

   kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb

Fix parsing of option -b with optional argument again.

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

Applied to u-boot-marvell/master

Thanks,
Stefan

Quoted 34 lines

---
Tony and Marcel, could you test this change if all your kwboot use cases still work correctly?

---
  tools/kwboot.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
tools/kwboot.c +8 -4
index 3b45e19a30aa..9f2dd2de4ef5 100644
@@ -2073,7 +2073,8 @@ main(int argc, char **argv)
  			bootmsg = 1;
  			if (prev_optind == optind)
  				goto usage;
-			if (optind < argc - 1 && argv[optind] && argv[optind][0] != '-')
+			/* Option -b could have optional argument which specify image path */
+			if (optind < argc && argv[optind] && argv[optind][0] != '-')
  				imgpath = argv[optind++];
  			break;
 
@@ -2128,10 +2129,19 @@ main(int argc, char **argv)
  	if (!bootmsg && !term && !debugmsg && !imgpath)
  		goto usage;
 
-	ttypath = argv[optind++];
-
-	if (optind != argc)
+	/*
+	 * If there is no remaining argument but optional imgpath was parsed
+	 * then it means that optional imgpath was eaten by getopt parser.
+	 * Reassing imgpath to required ttypath argument.
+	 */
+	if (optind == argc && imgpath) {

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

Quoted 10 lines
tools/kwboot.c +6 -0
+		ttypath = imgpath;
+		imgpath = NULL;
+	} else if (optind + 1 == argc) {
+		ttypath = argv[optind];
+	} else {
  		goto usage;
+	}
 
  	/* boot and debug message use baudrate 115200 */
  	if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {

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]