Skip to contentSkip to conversation

tools/kwboot.c: Support UART fallback mode

PATCH New Kevin Smith 2 participants 4 messages Aug 31, 2015 – Mar 29, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/kwboot.c: Support UART fallback mode

On some processors such as Armada 38x, if the hardware- configured boot mode fails, the CPU falls back to booting over UART. When this happens the chip prints a failure message, waits for the magic sequence and, when it is received, prints a "(boot)" message, then sends a NAK to start the transfer.

This breaks the current kwboot behavior because the xmodem transfer only tries to read one character after the magic sequence, looking for the NAK. Instead it gets the "(boot)" text, and retries the magic sequence. The CPU thinks the repeated sequence is part of the packet, stops NAKing, and one side or another eventually times out.

This patch adds support for a fallback mode which continues to scan for a NAK in the characters received after the sequence, printing out any non-NAK characters. This allows kwboot to skip the "(boot)" message, find the NAK, and start the transfer successfully.

---
 tools/kwboot.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
tools/kwboot.c +17 -3
index af7a6ee..6b58fc9 100644
@@ -71,6 +71,7 @@ struct kwboot_block {
 #define KWBOOT_BLK_RSP_TIMEO 1000 /* ms */
 
 static int kwboot_verbose;
+static int support_fallback;
 
 static int msg_req_delay = KWBOOT_MSG_REQ_DELAY;
 static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO;
@@ -300,7 +301,15 @@ kwboot_bootmsg(int tty, void *msg)
 			continue;
 		}
 
-		rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo);
+		while (1) {
+			rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo);
+			if (support_fallback && rc == 0 && c != NAK) {
+				printf("%c", c);
+				fflush(stdout);
+				continue;
+			}
+			break;
+		}
 
 		kwboot_spinner();
 
@@ -657,7 +666,7 @@ static void
 kwboot_usage(FILE *stream, char *progname)
 {
 	fprintf(stream,
-		"Usage: %s [-d | -a | -q <req-delay> | -s <resp-timeo> | -b <image> | -D <image> ] [ -t ] [-B <baud> ] <TTY>\n",
+		"Usage: %s [-f] [-d | -a | -q <req-delay> | -s <resp-timeo> | -b <image> | -D <image> ] [ -t ] [-B <baud> ] <TTY>\n",
 		progname);
 	fprintf(stream, "\n");
 	fprintf(stream,
@@ -667,6 +676,7 @@ kwboot_usage(FILE *stream, char *progname)
 		"  -D <image>: boot <image> without preamble (Dove)\n");
 	fprintf(stream, "  -d: enter debug mode\n");
 	fprintf(stream, "  -a: use timings for Armada XP\n");
+	fprintf(stream, "  -f: support UART fallback after failed boot\n");
 	fprintf(stream, "  -q <req-delay>:  use specific request-delay\n");
 	fprintf(stream, "  -s <resp-timeo>: use specific response-timeout\n");
 	fprintf(stream, "\n");
@@ -701,7 +711,7 @@ main(int argc, char **argv)
 	kwboot_verbose = isatty(STDOUT_FILENO);
 
 	do {
-		int c = getopt(argc, argv, "hb:ptaB:dD:q:s:");
+		int c = getopt(argc, argv, "hb:ptfaB:dD:q:s:");
 		if (c < 0)
 			break;
 
@@ -728,6 +738,10 @@ main(int argc, char **argv)
 			term = 1;
 			break;
 
+		case 'f':
+			support_fallback = 1;
+			break;
+
 		case 'a':
 			msg_req_delay = KWBOOT_MSG_REQ_DELAY_AXP;
 			msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO_AXP;
Signature · 1 line
2.4.6
#1 lore raw

PATCH 1/1 tools/kwboot.c: Support UART fallback mode

Hi Kevin,

(Added Luka to Cc, as the Marvell / MVEBU custodian)

Quoted 13 lines · Kevin Smith

On some processors such as Armada 38x, if the hardware- configured boot mode fails, the CPU falls back to booting over UART. When this happens the chip prints a failure message, waits for the magic sequence and, when it is received, prints a "(boot)" message, then sends a NAK to start the transfer.

This breaks the current kwboot behavior because the xmodem transfer only tries to read one character after the magic sequence, looking for the NAK. Instead it gets the "(boot)" text, and retries the magic sequence. The CPU thinks the repeated sequence is part of the packet, stops NAKing, and one side or another eventually times out.

Quoted 7 lines

This patch adds support for a fallback mode which continues to scan for a NAK in the characters received after the sequence, printing out any non-NAK characters. This allows kwboot to skip the "(boot)" message, find the NAK, and start the transfer successfully.

I've not seen this "(boot)" yet. But the patch looks good. So:

BTW: Please always keep Luka on MVEBU related patches on Cc.

Thanks,
Stefan

#2 lore raw

PATCH 1/1 tools/kwboot.c: Support UART fallback mode

Hi Kevin,

Quoted 24 lines · Stefan Roese

Hi Kevin,

(Added Luka to Cc, as the Marvell / MVEBU custodian)

Quoted 19 lines · Kevin Smith

On some processors such as Armada 38x, if the hardware- configured boot mode fails, the CPU falls back to booting over UART. When this happens the chip prints a failure message, waits for the magic sequence and, when it is received, prints a "(boot)" message, then sends a NAK to start the transfer.

This breaks the current kwboot behavior because the xmodem transfer only tries to read one character after the magic sequence, looking for the NAK. Instead it gets the "(boot)" text, and retries the magic sequence. The CPU thinks the repeated sequence is part of the packet, stops NAKing, and one side or another eventually times out.

This patch adds support for a fallback mode which continues to scan for a NAK in the characters received after the sequence, printing out any non-NAK characters. This allows kwboot to skip the "(boot)" message, find the NAK, and start the transfer successfully.

Quoted 5 lines
Quoted 1 line

I've not seen this "(boot)" yet. But the patch looks good. So:

Is this patch still needed (or helpful)? If yes, please rebase on top of latest u-boot-marvell/master and send a new version so that I can pick it up.

Thanks,
Stefan

#3 lore raw

PATCH 1/1 tools/kwboot.c: Support UART fallback mode

Hi Stefan,

Quoted 31 lines · Stefan Roese

Hi Kevin,

Quoted 28 lines · Stefan Roese

Hi Kevin,

(Added Luka to Cc, as the Marvell / MVEBU custodian)

Quoted 13 lines · Kevin Smith

On some processors such as Armada 38x, if the hardware- configured boot mode fails, the CPU falls back to booting over UART. When this happens the chip prints a failure message, waits for the magic sequence and, when it is received, prints a "(boot)" message, then sends a NAK to start the transfer.

This breaks the current kwboot behavior because the xmodem transfer only tries to read one character after the magic sequence, looking for the NAK. Instead it gets the "(boot)" text, and retries the magic sequence. The CPU thinks the repeated sequence is part of the packet, stops NAKing, and one side or another eventually times out.

Quoted 7 lines

This patch adds support for a fallback mode which continues to scan for a NAK in the characters received after the sequence, printing out any non-NAK characters. This allows kwboot to skip the "(boot)" message, find the NAK, and start the transfer successfully.

I've not seen this "(boot)" yet. But the patch looks good. So:

Quoted 9 lines
Quoted 1 line

Is this patch still needed (or helpful)? If yes, please rebase on top of latest u-boot-marvell/master and send a new version so that I can pick it up.

Thanks,
Stefan

I don't think this is needed in most cases. I will leave it out to avoid cluttering up the program. If that changes, I will resubmit.

Thank you,
Kevin