diff mbox

[U-Boot] tools/kwboot.c: Support UART fallback mode

Message ID 1441052989-14603-1-git-send-email-kevin.smith@elecsyscorp.com
State Deferred
Delegated to: Stefan Roese
Headers show

Commit Message

Kevin Smith Aug. 31, 2015, 8:30 p.m. UTC
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.

Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>
---
 tools/kwboot.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Stefan Roese Sept. 1, 2015, 12:52 p.m. UTC | #1
Hi Kevin,

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

On 31.08.2015 22:30, Kevin Smith wrote:
> 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.
>
> Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>

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

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

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

Thanks,
Stefan
Stefan Roese March 24, 2016, 9:29 a.m. UTC | #2
Hi Kevin,

On 01.09.2015 14:52, Stefan Roese wrote:
> Hi Kevin,
>
> (Added Luka to Cc, as the Marvell / MVEBU custodian)
>
> On 31.08.2015 22:30, Kevin Smith wrote:
>> 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.
>>
>> Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>
>
> I've not seen this "(boot)" yet. But the patch looks good. So:
>
> Reviewed-by: Stefan Roese <sr@denx.de>

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
Kevin Smith March 29, 2016, 3:47 p.m. UTC | #3
Hi Stefan,

On 03/24/2016 04:29 AM, Stefan Roese wrote:
> Hi Kevin,
>
> On 01.09.2015 14:52, Stefan Roese wrote:
>> Hi Kevin,
>>
>> (Added Luka to Cc, as the Marvell / MVEBU custodian)
>>
>> On 31.08.2015 22:30, Kevin Smith wrote:
>>> 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.
>>>
>>> Signed-off-by: Kevin Smith <kevin.smith@elecsyscorp.com>
>>
>> I've not seen this "(boot)" yet. But the patch looks good. So:
>>
>> Reviewed-by: Stefan Roese <sr@denx.de>
>
> 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
diff mbox

Patch

diff --git a/tools/kwboot.c b/tools/kwboot.c
index af7a6ee..6b58fc9 100644
--- a/tools/kwboot.c
+++ b/tools/kwboot.c
@@ -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;