tools: kwboot: Fix boot and terminal mode
PATCH 1/10 tools: kwboot: Check for return value of kwboot_tty_send() and tcflush()
In reply to Pali RohárFailure of kwboot_tty_send() and tcflush() functions is fatal, it does not make sense to continue. So return error back to the caller like in other places where are called these functions.
--- tools/kwboot.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
tools/kwboot.c +19 -11
@@ -740,10 +740,8 @@ kwboot_bootmsg(int tty, void *msg)for (count =0 ; count <128 ; count++) { rc =kwboot_tty_send (tty, msg,8 ,0 ); -if (rc) { -usleep (msg_req_delay *1000 ); -continue ; - } +if (rc) +break ; } rc =kwboot_tty_recv (tty, &c,1 , msg_rsp_timeo);
@@ -772,11 +770,19 @@ kwboot_bootmsg(int tty, void *msg)*/ /* flush output queue with remaining boot message patterns */ -tcflush (tty,TCOFLUSH ); + rc =tcflush (tty,TCOFLUSH ); +if (rc) { +perror ("Failed to flush output queue" ); +return rc; + }/* send one xmodem packet with 0xff bytes to force BootROM to re-sync */ memset (&block,0xff ,sizeof (block)); -kwboot_tty_send (tty, &block,sizeof (block),0 ); + rc =kwboot_tty_send (tty, &block,sizeof (block),0 ); +if (rc) { +perror ("Failed to send sync sequence" ); +return rc; + }/* * Sending 132 bytes via 115200B/8-N-1 takes 11.45 ms, reading 132 bytes
@@ -785,7 +791,11 @@ kwboot_bootmsg(int tty, void *msg)usleep (30 *1000 );/* flush remaining NAK replies from input queue */ -tcflush (tty,TCIFLUSH ); + rc =tcflush (tty,TCIFLUSH ); +if (rc) { +perror ("Failed to flush input queue" ); +return rc; + }return 0 ; }
@@ -805,10 +815,8 @@ kwboot_debugmsg(int tty, void *msg)break ; rc =kwboot_tty_send (tty, msg,8 ,0 ); -if (rc) { -usleep (msg_req_delay *1000 ); -continue ; - } +if (rc) +break ; rc =kwboot_tty_recv (tty, buf,16 , msg_rsp_timeo);
Signature · 1 line
2.20.1
PATCH 4/10 tools: kwboot: Use separate thread for sending boot message pattern
In reply to Pali RohárAfter BootROM successfully detects boot message pattern on UART it waits until host stop sending data on UART. For example Armada 385 BootROM requires that host does not send anything on UART at least 24 ms. If host is still sending something then BootROM waits (possibly infinitely).
BootROM successfully detects boot message pattern if it receives it in small period of time after power on.
So to ensure that host put BootROM into UART boot mode, host must send continuous stream of boot message pattern with a small gap (for A385 at least 24 ms) after series of pattern. But this gap cannot be too often or too long to ensure that it does not cover whole BootROM time window when it is detecting for boot message pattern.
Therefore it is needed to do following steps in cycle without any delay:
1. send series of boot message pattern over UART
2. wait until kernel transmit all data
3. sleep small period of time
At the same time, host needs to monitor input queue, data received on the UART and checking if it contains NAK byte by which BootROM informs that xmodem transfer is ready.
But it is not possible to wait until kernel transmit all data on UART and at the same time in the one process to also wait for input data. This is limitation of POSIX tty API and also by linux kernel that it does not provide asynchronous function for waiting until all data are transmitted. There is only synchronous variant tcdrain().
So to correctly implement this handshake on systems with linux kernel, it is needed to use tcdrain() in separate thread.
Implement sending of boot message pattern in one thread and reading of reply in the main thread. Use pthread library for threads.
This change makes UART booting on Armada 385 more reliable. It is possible to start kwboot and power on board after minute and kwboot correctly put board into UART boot mode.
Old implementation without separate thread has an issue that it read just one byte from UART input queue and then it send 128 message pattern to the output queue. If some noise was on UART then kwboot was not able to read BootROM response as its input queue was just overflowed and kwboot was sending more data than receiving.
This change basically fixed above issue too.
--- tools/Makefile | 3 ++ tools/kwboot.c | 120 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 104 insertions(+), 19 deletions(-)
tools/Makefile +3 -0
@@ -199,6 +199,9 @@ hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl HOSTCFLAGS_mkexynosspl.o := -pedantic +HOSTCFLAGS_kwboot.o += -pthread +HOSTLDLIBS_kwboot += -pthread + ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o hostprogs-$(CONFIG_X86) += ifdtool
tools/kwboot.c +101 -19
154 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 2/10 tools: kwboot: Remove msg_req_delay
In reply to Pali RohárVariable msg_req_delay is set but never used. So completely remove it.
--- tools/kwboot.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
tools/kwboot.c +1 -6
@@ -48,11 +48,9 @@ static unsigned char kwboot_msg_debug[] = { };/* Defines known to work on Kirkwood */ -#define KWBOOT_MSG_REQ_DELAY 10/* ms */ #define KWBOOT_MSG_RSP_TIMEO 50/* ms */ /* Defines known to work on Armada XP */ -#define KWBOOT_MSG_REQ_DELAY_AXP 1000/* ms */ #define KWBOOT_MSG_RSP_TIMEO_AXP 1000/* ms */ /*
@@ -285,7 +283,6 @@ static const char kwb_baud_magic[16] = "$baudratechange";static int kwboot_verbose; -static int msg_req_delay =KWBOOT_MSG_REQ_DELAY ;static int msg_rsp_timeo =KWBOOT_MSG_RSP_TIMEO ;static int blk_rsp_timeo =KWBOOT_BLK_RSP_TIMEO ;
@@ -1725,7 +1722,6 @@ 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," -q <req-delay>: use specific request-delay\n" );fprintf (stream," -s <resp-timeo>: use specific response-timeout\n" );fprintf (stream," -o <block-timeo>: use specific xmodem block timeout\n" );
@@ -1804,12 +1800,11 @@ main(int argc, char **argv)break ;case 'a' : - msg_req_delay =KWBOOT_MSG_REQ_DELAY_AXP ; msg_rsp_timeo =KWBOOT_MSG_RSP_TIMEO_AXP ;break ;case 'q' : - msg_req_delay =atoi (optarg); +/* nop, for backward compatibility */ break ;case 's' :
Signature · 1 line
2.20.1
PATCH 3/10 tools: kwboot: Cleanup bootmsg and debugmsg variables
In reply to Pali RohárFunction kwboot_debugmsg() is always called with kwboot_msg_debug as msg and function kwboot_bootmsg() with kwboot_msg_debug as msg. Function kwboot_bootmsg() is never called with NULL msg.
Simplify, cleanup and remove dead code.
No functional change.
--- tools/kwboot.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
tools/kwboot.c +14 -17
@@ -718,17 +718,14 @@ out: }static int -kwboot_bootmsg (int tty,void *msg) +kwboot_bootmsg (int tty) {struct kwboot_block block;int rc;char c;int count; -if (msg ==NULL ) -kwboot_printv ("Please reboot the target into UART boot mode..." ); -else -kwboot_printv ("Sending boot message. Please reboot the target..." ); +kwboot_printv ("Sending boot message. Please reboot the target..." ); do { rc = tcflush(tty, TCIOFLUSH);
@@ -736,7 +733,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ,0 ); + rc =kwboot_tty_send (tty, kwboot_msg_boot,sizeof (kwboot_msg_boot),0 );if (rc)break ; }
@@ -798,7 +795,7 @@ kwboot_bootmsg(int tty, void *msg) }static int -kwboot_debugmsg (int tty,void *msg) +kwboot_debugmsg (int tty) {int rc;
@@ -811,7 +808,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ,0 ); + rc =kwboot_tty_send (tty, kwboot_msg_debug,sizeof (kwboot_msg_debug),0 );if (rc)break ;
@@ -1737,8 +1734,8 @@ main(int argc, char **argv) {const char *ttypath, *imgpath;int rv, rc, tty, term; -void *bootmsg; -void *debugmsg; +int bootmsg; +int debugmsg;void *img;size_t size;size_t after_img_rsv;
@@ -1748,8 +1745,8 @@ main(int argc, char **argv) rv =1 ; tty =-1 ; - bootmsg =NULL ; - debugmsg =NULL ; + bootmsg =0 ; + debugmsg =0 ; imgpath =NULL ; img =NULL ; term =0 ;
@@ -1771,7 +1768,7 @@ main(int argc, char **argv)case 'b' :if (imgpath || bootmsg || debugmsg) goto usage; - bootmsg = kwboot_msg_boot; + bootmsg =1 ;if (prev_optind == optind) goto usage;if (optind < argc -1 && argv[optind] && argv[optind][0 ] !='-' )
@@ -1781,14 +1778,14 @@ main(int argc, char **argv)case 'D' :if (imgpath || bootmsg || debugmsg) goto usage; - bootmsg =NULL ; + bootmsg =0 ; imgpath = optarg;break ;case 'd' :if (imgpath || bootmsg || debugmsg) goto usage; - debugmsg = kwboot_msg_debug; + debugmsg =1 ;break ;case 'p' :
@@ -1869,13 +1866,13 @@ main(int argc, char **argv) }if (debugmsg) { - rc =kwboot_debugmsg (tty, debugmsg); + rc =kwboot_debugmsg (tty);if (rc) {perror ("debugmsg" ); goto out; } }else if (bootmsg) { - rc =kwboot_bootmsg (tty, bootmsg); + rc =kwboot_bootmsg (tty);if (rc) {perror ("bootmsg" ); goto out;
Signature · 1 line
2.20.1
cover tools: kwboot: Fix boot and terminal mode
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value of kwboot_tty_send() and
tcflush()
tools: kwboot: Remove msg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public links
doc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)
Signature · 1 line
2.20.1
PATCH 6/10 tools: kwboot: Add support for backspace key in mini terminal
Marvell BootROM recognize only '\b' byte as backspace. Use terminfo for retrieving current backspace sequence and replace any occurrence of backspace sequence by the '\b' byte.
Reading terminfo database is possible via tigetstr() function from system library libtinfo.so.*. So link kwboot with -ltinfo.
Normally terminfo functions are in <term.h> system header file. But this header file conflicts with U-Boot "termios_linux.h" header file. So declare terminfo functions manually.
--- tools/Makefile | 2 +- tools/kwboot.c | 109 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 14 deletions(-)
tools/Makefile +1 -1
@@ -200,7 +200,7 @@ hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl HOSTCFLAGS_mkexynosspl.o := -pedantic HOSTCFLAGS_kwboot.o += -pthread -HOSTLDLIBS_kwboot += -pthread +HOSTLDLIBS_kwboot += -pthread -ltinfo ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o hostprogs-$(CONFIG_X86) += ifdtool
tools/kwboot.c +96 -13
171 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 7/10 tools: kwboot: Update usage
In reply to Pali RohárAdd all supported Armada SoCs and document -b and -d options in usage.
--- tools/kwboot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tools/kwboot.c +4 -3
@@ -1986,14 +1986,15 @@ static void kwboot_usage(FILE *stream, char *progname) {fprintf (stream, -"Usage: %s [OPTIONS] [-b <image> | -D <image> ] [-B <baud> ] <TTY>\n" , +"Usage: %s [OPTIONS] [-b <image> | -D <image> | -b | -d ] [-B <baud> ] [-t] <TTY>\n" , progname);fprintf (stream,"\n" );fprintf (stream, -" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n" ); +" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP/375/38x/39x)\n" );fprintf (stream," -D <image>: boot <image> without preamble (Dove)\n" ); -fprintf (stream," -d: enter debug mode\n" ); +fprintf (stream," -b: enter xmodem boot mode\n" ); +fprintf (stream," -d: enter console debug mode\n" );fprintf (stream," -a: use timings for Armada XP\n" );fprintf (stream," -s <resp-timeo>: use specific response-timeout\n" ); fprintf(stream,
Signature · 1 line
2.20.1
PATCH 5/10 tools: kwboot: Fix sending and processing debug message pattern (-d option)
In reply to Pali Rohár-d option is currently broken. In most cases BootROM does not detect this message pattern. For sending debug message pattern it is needed to do same steps as for boot message pattern.
Implement sending debug message pattern via same separate thread like it is for boot message pattern.
Checking if BootROM entered into UART debug mode is different than detecting UART boot mode. When in boot mode, BootROM sends xmodem NAK bytes. When in debug mode, BootROM activates console echo and reply back every written byte (extept \r\n which is interpreted as executing command and \b which is interpreting as removing the last sent byte).
So in kwboot, check that BootROM send back at least 4 debug message patterns as a echo reply for debug message patterns which kwboot is sending in the loop.
Then there is another observation, if host writes too many bytes (as command) then BootROM command line buffer may overflow after trying to execute such long command. To workaround this overflow, it is enough to remove bytes from the input line buffer by sending 3 \b bytes for every sent character. So do it.
With this change, it is possbile to enter into the UART debug mode with kwboot -d option.
--- tools/kwboot.c | 139 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 16 deletions(-)
tools/kwboot.c +123 -16
@@ -881,30 +881,139 @@ kwboot_bootmsg(int tty)static int kwboot_debugmsg (int tty) { -int rc; +unsigned char buf[8192 ]; +pthread_t write_thread; +int rc, err, i, pos; +size_t off; -kwboot_printv ("Sending debug message. Please reboot the target..." ); +/* flush input and output queue */ +tcflush (tty,TCIOFLUSH ); -do { -char buf[16 ]; + rc =kwboot_msg_start_thread (&write_thread, &tty, kwboot_msg_debug); +if (rc) { +perror ("Failed to start write thread" ); +return rc; + } - rc =tcflush (tty,TCIOFLUSH ); -if (rc) -break ; +kwboot_printv ("Sending debug message. Please reboot the target..." ); +kwboot_spinner (); - rc =kwboot_tty_send (tty, kwboot_msg_debug,sizeof (kwboot_msg_debug),0 ); -if (rc) + err =0 ; + off =0 ; +while (1 ) { +/* Read immediately all bytes in queue without waiting */ + rc =read (tty, buf + off,sizeof (buf) - off); +if ((rc <0 && errno ==EINTR ) || rc ==0 ) { +continue ; + }else if (rc <0 ) { + err = errno;break ; - - rc =kwboot_tty_recv (tty, buf,16 , msg_rsp_timeo); + } + off += rc -1 ;kwboot_spinner (); - }while (rc); +/* +* Check if we received at least 4 debug message patterns +* (console echo from BootROM) in cyclic buffer +*/ + +for (pos =0 ; pos <sizeof (kwboot_msg_debug); pos++) +if (buf[off] == kwboot_msg_debug[(pos + off) %sizeof (kwboot_msg_debug)]) +break ; + +for (i = off; i >=0 ; i--) +if (buf[i] != kwboot_msg_debug[(pos + i) %sizeof (kwboot_msg_debug)]) +break ; + + off -= i; + +if (off >=4 *sizeof (kwboot_msg_debug)) +break ; + +/* If not move valid suffix from end of the buffer to the beginning of buffer */ +memmove (buf, buf + i +1 , off); + }kwboot_printv ("\n" ); -return rc; + rc =kwboot_msg_stop_thread (write_thread); +if (rc) { +perror ("Failed to stop write thread" ); +return rc; + } + +if (err) { + errno = err; +perror ("Failed to read response for debug message pattern" ); +return -1 ; + } + +/* flush output queue with remaining debug message patterns */ + rc =tcflush (tty,TCOFLUSH ); +if (rc) { +perror ("Failed to flush output queue" ); +return rc; + } + +kwboot_printv ("Clearing input buffer...\n" ); + +/* +* Wait until BootROM transmit all remaining echo characters. +* Experimentally it was measured that for Armada 385 BootROM +* it is required to wait at least 0.415s. So wait 0.5s. +*/ +usleep (500 *1000 ); + +/* +* In off variable is stored number of characters received after the +* successful detection of echo reply. So these characters are console +* echo for other following debug message patterns. BootROM may have in +* its output queue other echo characters which were being transmitting +* before above sleep call. So read remaining number of echo characters +* sent by the BootROM now. +*/ +while ((rc =kwboot_tty_recv (tty, &buf[0 ],1 ,0 )) ==0 ) + off++; +if (errno !=ETIMEDOUT ) { +perror ("Failed to read response" ); +return rc; + } + +/* +* Clear every echo character set by the BootROM by backspace byte. +* This is required prior writing any command to the BootROM debug +* because BootROM command line buffer has limited size. If length +* of the command is larger than buffer size then it looks like +* that Armada 385 BootROM crashes after sending ENTER. So erase it. +* Experimentally it was measured that for Armada 385 BootROM it is +* required to send at least 3 backspace bytes for one echo character. +* This is unknown why. But lets do it. +*/ + off *=3 ; +memset (buf,'\x08' ,sizeof (buf)); +while (off >sizeof (buf)) { + rc =kwboot_tty_send (tty, buf,sizeof (buf),1 ); +if (rc) { +perror ("Failed to send clear sequence" ); +return rc; + } + off -=sizeof (buf); + } + rc =kwboot_tty_send (tty, buf, off,0 ); +if (rc) { +perror ("Failed to send clear sequence" ); +return rc; + } + +usleep (msg_rsp_timeo *1000 ); + rc =tcflush (tty,TCIFLUSH ); +if (rc) { +perror ("Failed to flush input queue" ); +return rc; + } + +return 0 ; } static size_t
@@ -1951,10 +2060,8 @@ main(int argc, char **argv)if (debugmsg) { rc =kwboot_debugmsg (tty); -if (rc) { -perror ("debugmsg" ); +if (rc) goto out; - } }else if (bootmsg) { rc =kwboot_bootmsg (tty);if (rc)
Signature · 1 line
2.20.1
PATCH 8/10 tools: kwboot: Update manpage
In reply to Pali RohárDocument -D, -b, -d, -q and -s options.
Add common examples how to use kwboot.
Add information about Armada 38x BootROM bug for debug console mode and how to workaround it.
--- doc/kwboot.1 | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-)
doc/kwboot.1 +99 -4
@@ -1,4 +1,4 @@ -.TH KWBOOT 1 "2021-08-25" +.TH KWBOOT 1 "2022-03-02" .SH NAME kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over a serial link.
@@ -47,6 +47,48 @@ code in it's header which may also print some output via UART (for example U-Boot SPL does this). In such a case, this output is also written to stdout after the header is sent. +.TP +.B "\-b" +Do only handshake on \fITTY\fP without uploading any file. File upload +could be done later via option \fB\-D\fP or via any other Xmodem +application, like \fBsx\fP(1). + +.TP +.B "\-d" +Do special handshake on \fITTY\fP for console debug mode. + +This will instruct BootROM to enter builtin simple console debug mode. +Should be combined with option \fB\-t\fP. + +To get a BootROM help, type this command followed by ENTER key: + +.RS 1.2i +.TP +.B ? +.RE +.IP + +Armada 38x BootROM has a bug which cause that BootROM's standard output +is turned off on UART when SPI-NOR contains valid boot image. Nevertheless +BootROM's standard input and BootROM's terminal echo are active and working +fine. To workaround this BootROM bug with standard output, it is possible +to manually overwrite BootROM variables stored in SRAM which BootROM use +for checking if standard output is enabled or not. To enable BootROM +standard output on UART, type this command folled by ENTER key: + +.RS 1.2i +.TP +.B w 0x40034100 1 +.RE + +.TP +.BI "\-D" " image" +Upload file \fIimage\fP over \fITTY\fP without initial handshake. + +This method is used primary on Dove platforms, where BootROM does +not support initial handshake for entering UART upload mode and +strapping pins (exported via e.g. buttons) are used instead. + .TP .BI "\-p" Obsolete. Does nothing.
@@ -55,13 +97,33 @@ In the past, when this option was used, the program patched the header in the image prior upload, to "UART boot" type. This is now done by default. +.TP +.B "\-q" +Obsolete. Does nothing. + +It is unknown whether it did something in the past. + +.TP +.BI "\-s" " response-timeout" +Specify custom response timeout when doing handshake. Default value is 50 ms. +It is the timeout between sending two consecutive handshake patterns, meaning +how long to wait for response from BootROM. Affects only option \fB\-b\fP with +image file and option \fB\-d\fP. + +Option \fB-a\fP specify response timeout suitable for Armada XP BootROM and +currently it is 1000 ms. + +Some testing showed that specifying 24 ms as response timeout make handshake +with Armada 385 BootROM more stable. + .TP .BI "\-t" Run a terminal program, connecting standard input and output to .RB \fITTY\fP. -If used in combination with \fB-b\fP, terminal mode is entered -immediately following a successful image upload. +If used in combination with \fB\-b\fP, \fB\-D\fP or \fB\-d\fP option, +terminal mode is entered immediately following a successful image upload +or successful handshake (if not doing image upload). If standard I/O streams connect to a console, this mode will terminate after receiving \fBctrl-\e\fP followed by \fBc\fP from console input.
@@ -85,9 +147,42 @@ Tested values for \fIbaudrate\fP for Armada 38x include: 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3125000, 4000000 and 5200000. +.SH "EXAMPLES" + +Instruct BootROM to enter boot Xmodem boot mode, send \fIu-boot-spl.kwb\fP +kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP at 115200 Bd and run terminal +program: +.IP +.B kwboot -b u-boot-spl.kwb -t /dev/ttyUSB0 + +.PP +Instruct BootROM to enter boot Xmodem boot mode, send header of +\fIu-boot-spl.kwb\fP kwbimage file via Xmodem at 115200 Bd, then instruct +BootROM to change baudrate to 5200000 Bd, send data part of the kwbimage +file via Xmodem at high speed and finally run terminal program: +.IP +.B kwboot -b u-boot-spl.kwb -B 5200000 -t /dev/ttyUSB0 + +.PP +Only send \fIu-boot-spl.kwb\fP kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP +at 115200 Bd: +.IP +.B kwboot -D u-boot-spl.kwb /dev/ttyUSB0 + +.PP +Instruct BootROM to enter console debug mode and run terminal program on +\fI/dev/ttyUSB0\fP at 115200 Bd: +.IP +.B kwboot -d -t /dev/ttyUSB0 + +.PP +Only run terminal program on \fI/dev/ttyUSB0\fP at 115200 Bd: +.IP +.B kwboot -t /dev/ttyUSB0 + .SH "SEE ALSO" .PP -\fBmkimage\fP(1) +\fBmkimage\fP(1), \fBsx\fP(1) .SH "AUTHORS"
Signature · 1 line
2.20.1
PATCH 9/10 tools: kwboot: Update doc about Avanta
In reply to Pali RohárTestes proved that current kwboot version supports also Avanta SoCs. It looks like that Avanta SoCs are using same kwbimage format as Armada.
--- doc/kwboot.1 | 2 +- tools/kwboot.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
doc/kwboot.1 +1 -1
@@ -11,7 +11,7 @@ kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over a serial link. .SH "DESCRIPTION" The \fBkwboot\fP program boots boards based on Marvell's 32-bit -platforms including Kirkwood, Dove, A370, AXP, A375, A38x +platforms including Kirkwood, Dove, Avanta, A370, AXP, A375, A38x and A39x over their integrated UART. Boot image files will typically contain a second stage boot loader, such as U-Boot. The image file must conform to Marvell's BootROM firmware image format
tools/kwboot.c +3 -3
@@ -1,7 +1,7 @@/* * Boot a Marvell SoC, with Xmodem over UART0. -* supports Kirkwood, Dove, Armada 370, Armada XP, Armada 375, Armada 38x and -* Armada 39x +* supports Kirkwood, Dove, Avanta, Armada 370, Armada XP, Armada 375, +* Armada 38x and Armada 39x. * * (c) 2012 Daniel Stodden <[email protected]> * (c) 2021 Pali Rohár <[email protected]>
@@ -1990,7 +1990,7 @@ kwboot_usage(FILE *stream, char *progname) progname);fprintf (stream,"\n" );fprintf (stream, -" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP/375/38x/39x)\n" ); +" -b <image>: boot <image> with preamble (Kirkwood, Avanta, Armada 370/XP/375/38x/39x)\n" );fprintf (stream," -D <image>: boot <image> without preamble (Dove)\n" );fprintf (stream," -b: enter xmodem boot mode\n" );
Signature · 1 line
2.20.1
PATCH 10/10 tools: kwboot: Update references with public links
In reply to Pali RohárPublic documents about BootROM of some Marvell SoCs are available in the public Web Archive. Put this information into source code.
--- tools/kwboot.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
tools/kwboot.c +28 -3
@@ -7,9 +7,34 @@* (c) 2021 Pali Rohár <[email protected]> * (c) 2021 Marek Behún <[email protected]> * -* References: marvell.com, "88F6180, 88F6190, 88F6192, and 88F6281 -* Integrated Controller: Functional Specifications" December 2, -* 2008. Chapter 24.2 "BootROM Firmware". +* References: +* - "88F6180, 88F6190, 88F6192, and 88F6281: Integrated Controller: Functional +* Specifications" December 2, 2008. Chapter 24.2 "BootROM Firmware". +* https://web.archive.org/web/20130730091033/https://www.marvell.com/embedded-processors/kirkwood/assets/FS_88F6180_9x_6281_OpenSource.pdf +* - "88AP510: High-Performance SoC with Integrated CPU, 2D/3D Graphics +* Processor, and High-Definition Video Decoder: Functional Specifications" +* August 3, 2011. Chapter 5 "BootROM Firmware" +* https://web.archive.org/web/20120130172443/https://www.marvell.com/application-processors/armada-500/assets/Armada-510-Functional-Spec.pdf +* - "88F6710, 88F6707, and 88F6W11: ARMADA(R) 370 SoC: Functional Specifications" +* May 26, 2014. Chapter 6 "BootROM Firmware". +* https://web.archive.org/web/20140617183701/https://www.marvell.com/embedded-processors/armada-300/assets/ARMADA370-FunctionalSpec-datasheet.pdf +* - "MV78230, MV78260, and MV78460: ARMADA(R) XP Family of Highly Integrated +* Multi-Core ARMv7 Based SoC Processors: Functional Specifications" +* May 29, 2014. Chapter 6 "BootROM Firmware". +* https://web.archive.org/web/20180829171131/https://www.marvell.com/embedded-processors/armada-xp/assets/ARMADA-XP-Functional-SpecDatasheet.pdf +* - "ARMADA(R) 375 Value-Performance Dual Core CPU System on Chip: Functional +* Specifications" Doc. No. MV-S109377-00, Rev. A. September 18, 2013. +* Chapter 7 "Boot Sequence" +* CONFIDENTIAL, no public documentation available +* - "88F6810, 88F6811, 88F6821, 88F6W21, 88F6820, and 88F6828: ARMADA(R) 38x +* Family High-Performance Single/Dual CPU System on Chip: Functional +* Specifications" Doc. No. MV-S109094-00, Rev. C. August 2, 2015. +* Chapter 7 "Boot Flow" +* CONFIDENTIAL, no public documentation available +* - "88F6920, 88F6925 and 88F6928: ARMADA(R) 39x High-Performance Dual Core CPU +* System on Chip Functional Specifications" Doc. No. MV-S109896-00, Rev. B. +* December 22, 2015. Chapter 7 "Boot Flow" +* CONFIDENTIAL, no public documentation available */ #include "kwbimage.h"
Signature · 1 line
2.20.1
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Thanks,
Tony
Quoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Quoted 4 lines · On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Hello, this patch series depends on following kwboot patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Quoted 39 lines
Thanks,
TonyQuoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Hi Pali,
Quoted 9 lines · Pali Rohár
Quoted 4 lines · On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Hello, this patch series depends on following kwboot patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
That was it. I will try to kwboot a few different boxes and let you know.
Thanks,
Tony
Quoted 39 lines
Quoted 39 lines
Thanks,
TonyQuoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Hi Pali,
Here is the test report.
1. Kirkwood SoC
Tested with Seagate GoFlex Home board (88F6281):
- Everything is working fine as before.
- kwboot -d also works to get BootROM into debug mode.
- At the BootROM command line, x 0x5 selected boot source NAND, and started booting from u-boot in NAND successfully.
<BEGIN LOG>
./kwboot -t -B 115200 /dev/ttyUSB0 -d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]
Quoted 1 line
x
0x5
<END LOG>
2. Armada SoC
Tested with Globalscale Technologies Mirabox (Armada 370)
- Everything is working fine as before
- kwboot -d also works to get BootROM into debug mode
<BEGIN LOG>
./kwboot -t -B 115200 /dev/ttyUSB2 -d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]
Quoted 1 line
help
h/? - print this help screen
r <0xXXXXXXXX> - read memory address 0xXXXXXXXX w <0xXXXXXXXX> <0xYYYYYYYY> - write 0xYYY YYYYY to address 0xXXXXXXXX
j <0xXXXXXXXX> - jump to address 0xXXXXXXXX x <X> - select SAR boot source X and restart
Quoted 1 line
<END LOG>
3. Dove SoC
Tested with HP Thin Client T5335z (Dove 88AP510)
- Everything is working as before.
- No change in behavior since the last test. IOW, u-boot image was transferred successfully, but the BootROM did not start u-boot, as described here:
https://lists.denx.de/pipermail/u-boot/2022-February/475494.html
4. Avanta ȘoC
Tested with the ActionTec MI424WR-I (88F6560 A0)
- This kwboot version is broken for this board. The header and image were not transferred at all.
- The last tested and working kwboot version was built on Feb 15th (up until and including patch tools-kwbimage-Support-for-parsing-extended-v0-format.patch)
Thanks,
Tony
Quoted 59 lines · Tony Dinh
Hi Pali,
Quoted 9 lines · Pali Rohár
Quoted 4 lines · On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Hello, this patch series depends on following kwboot patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/That was it. I will try to kwboot a few different boxes and let you know.
Thanks,
TonyQuoted 39 lines
Quoted 39 lines
Thanks,
TonyQuoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Hello!
Quoted 35 lines · On Thursday 03 March 2022 15:58:41 Tony Dinh wrote:
Hi Pali,
Here is the test report.
1. Kirkwood SoC
Tested with Seagate GoFlex Home board (88F6281):
- Everything is working fine as before.
- kwboot -d also works to get BootROM into debug mode.
- At the BootROM command line, x0x5selected boot source NAND, and started booting from u-boot in NAND successfully.<BEGIN LOG>
./kwboot -t -B 115200/dev/ttyUSB0-d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]Quoted 1 line
x
0x5<END LOG>
2. Armada SoC
Tested with Globalscale Technologies Mirabox (Armada 370)
- Everything is working fine as before
- kwboot -d also works to get BootROM into debug mode<BEGIN LOG>
./kwboot -t -B 115200/dev/ttyUSB2-d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]Quoted 1 line
help
Quoted 8 lines
h/? - print this help screen
r <0xXXXXXXXX> - read memory address 0xXXXXXXXX w <0xXXXXXXXX> <0xYYYYYYYY> - write 0xYYY YYYYY to address 0xXXXXXXXX
j <0xXXXXXXXX> - jump to address 0xXXXXXXXX x <X> - select SAR boot source X and restartQuoted 1 line
<END LOG>
Thank you for testing. Nice to see that -d is working!
Quoted 11 lines
3. Dove SoC
Tested with HP Thin Client T5335z (Dove 88AP510)
- Everything is working as before.
- No change in behavior since the last test. IOW, u-boot image was transferred successfully, but the BootROM did not start u-boot, as described here:
https://lists.denx.de/pipermail/u-boot/2022-February/475494.html4. Avanta ȘoC
Quoted 7 lines
Tested with the ActionTec MI424WR-I (88F6560 A0)
- This kwboot version is broken for this board. The header and image were not transferred at all.
- The last tested and working kwboot version was built on Feb 15th (up until and including patch tools-kwbimage-Support-for-parsing-extended-v0-format.patch)
Ou. This needs to be fixed.
Could you try adjust "-s" argument? Default value is 50. My tests showed that Armada 385 is better detected with value 24. And some old documentation says that Armada XP needs value 1000.
Quoted 65 lines
Thanks,
TonyQuoted 59 lines · Tony Dinh
Hi Pali,
Quoted 9 lines · Pali Rohár
Quoted 4 lines · On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Hello, this patch series depends on following kwboot patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/That was it. I will try to kwboot a few different boxes and let you know.
Thanks,
TonyQuoted 39 lines
Quoted 39 lines
Thanks,
TonyQuoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Tony Dinh
Tested-byHi Pali,
It seems the problem was with the ActionTec MI424WR-I board quirk. It has nothing to do with the new kwboot on Avanta SoC. Sorry for the false alarm!
I spent a couple hours running with various delays for the option -s, even with 50, and it all works fine! Uhm... So I went back to the default run (without -s) and it also worked. All these tests were done with a cold start each time.
So that's when I realized it was probably a quirk with this board. Sometimes the warm boot caused problems for the serial port. But the new kwboot will work whenever I coldstart (power cycle).
Thanks for a new and improved kwboot!
Thanks,
Tony
Quoted 140 lines · Pali Rohár
Hello!
Quoted 35 lines · On Thursday 03 March 2022 15:58:41 Tony Dinh wrote:
Hi Pali,
Here is the test report.
1. Kirkwood SoC
Tested with Seagate GoFlex Home board (88F6281):
- Everything is working fine as before.
- kwboot -d also works to get BootROM into debug mode.
- At the BootROM command line, x0x5selected boot source NAND, and started booting from u-boot in NAND successfully.<BEGIN LOG>
./kwboot -t -B 115200/dev/ttyUSB0-d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]Quoted 1 line
x
0x5<END LOG>
2. Armada SoC
Tested with Globalscale Technologies Mirabox (Armada 370)
- Everything is working fine as before
- kwboot -d also works to get BootROM into debug mode<BEGIN LOG>
./kwboot -t -B 115200/dev/ttyUSB2-d kwboot version 2022.04-rc3-00002-gf64aac4a69-dirty Sending debug message. Please reboot the target.../ Clearing input buffer...
[Type Ctrl-\ + c to quit]Quoted 1 line
help
Quoted 8 lines
h/? - print this help screen
r <0xXXXXXXXX> - read memory address 0xXXXXXXXX w <0xXXXXXXXX> <0xYYYYYYYY> - write 0xYYY YYYYY to address 0xXXXXXXXX
j <0xXXXXXXXX> - jump to address 0xXXXXXXXX x <X> - select SAR boot source X and restartQuoted 1 line
<END LOG>
Thank you for testing. Nice to see that -d is working!
Quoted 11 lines
3. Dove SoC
Tested with HP Thin Client T5335z (Dove 88AP510)
- Everything is working as before.
- No change in behavior since the last test. IOW, u-boot image was transferred successfully, but the BootROM did not start u-boot, as described here:
https://lists.denx.de/pipermail/u-boot/2022-February/475494.html4. Avanta ȘoC
Quoted 7 lines
Tested with the ActionTec MI424WR-I (88F6560 A0)
- This kwboot version is broken for this board. The header and image were not transferred at all.
- The last tested and working kwboot version was built on Feb 15th (up until and including patch tools-kwbimage-Support-for-parsing-extended-v0-format.patch)Ou. This needs to be fixed.
Could you try adjust "-s" argument? Default value is 50. My tests showed that Armada 385 is better detected with value 24. And some old documentation says that Armada XP needs value 1000.
Quoted 65 lines
Thanks,
TonyQuoted 59 lines · Tony Dinh
Hi Pali,
Quoted 9 lines · Pali Rohár
Quoted 4 lines · On Wednesday 02 March 2022 12:51:25 Tony Dinh wrote:
Hi Pali,
The patch did not apply cleanly to the master branch (I downloaded the series from patchwork). Do you have a link where I can use it?
Hello, this patch series depends on following kwboot patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/That was it. I will try to kwboot a few different boxes and let you know.
Thanks,
TonyQuoted 39 lines
Quoted 39 lines
Thanks,
TonyQuoted 33 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public linksdoc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)--
2.20.1
Hi Pali,
Quoted 7 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
I've never used '-d' before. Seems to work though on my Armada XP board:
$ ./tools/kwboot -B 115200 -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 -d kwboot version 2022.04-rc3-01493-g756122ad25a9 Sending debug message. Please reboot the target...- Clearing input buffer... [Type Ctrl-\ + c to quit]
Quoted 2 lines
help
h/? - print this help screen
r <0xXXXXXXXX> - read memory address 0xXXXXXXXX
w <0xXXXXXXXX> <0xYYYYYYYY> - write 0xYYYYYYYY to address 0xXXXXXXXX j <0xXXXXXXXX> - jump to address 0xXXXXXXXX
x <X> - select SAR boot source X and restart
Also UART booting still works.
Thanks,
Stefan
Quoted 16 lines
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public links
Quoted 5 lines
doc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)
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]
Re: [PATCH u-boot-marvell 01/10] tools: kwboot: Check for return value of kwboot_tty_send() and tcflush()
In reply to Pali RohárQuoted 5 lines · Pali Rohár
Failure of
kwboot_tty_send()andtcflush()functions is fatal, it does not make sense to continue. So return error back to the caller like in other places where are called these functions.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 59 lines
--- tools/kwboot.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)tools/kwboot.c +17
-7@@ -740,10 +740,8 @@ kwboot_bootmsg(int tty, void *msg)for (count =0 ; count <128 ; count++) { rc =kwboot_tty_send (tty, msg,8 ,0 ); -if (rc) { -usleep (msg_req_delay *1000 ); -continue ; - } +if (rc) +break ; } rc =kwboot_tty_recv (tty, &c,1 , msg_rsp_timeo);@@ -772,11 +770,19 @@ kwboot_bootmsg(int tty, void *msg)*/ /* flush output queue with remaining boot message patterns */ -tcflush (tty,TCOFLUSH ); + rc =tcflush (tty,TCOFLUSH ); +if (rc) { +perror ("Failed to flush output queue" ); +return rc; + }/* send one xmodem packet with 0xff bytes to force BootROM to re-sync */ memset (&block,0xff ,sizeof (block)); -kwboot_tty_send (tty, &block,sizeof (block),0 ); + rc =kwboot_tty_send (tty, &block,sizeof (block),0 ); +if (rc) { +perror ("Failed to send sync sequence" ); +return rc; + }/* * Sending 132 bytes via 115200B/8-N-1 takes 11.45 ms, reading 132 bytes @@ -785,7 +791,11 @@ kwboot_bootmsg(int tty, void *msg)usleep (30 *1000 );/* flush remaining NAK replies from input queue */ -tcflush (tty,TCIFLUSH ); + rc =tcflush (tty,TCIFLUSH ); +if (rc) { +perror ("Failed to flush input queue" ); +return rc; + }return 0 ; }@@ -805,10 +815,8 @@ kwboot_debugmsg(int tty, void *msg)break ;
tools/kwboot.c kwboot_debugmsg(int tty, void *msg) · line 822
Quoted 10 lines
tools/kwboot.c +2
-4rc =kwboot_tty_send (tty, msg,8 ,0 ); -if (rc) { -usleep (msg_req_delay *1000 ); -continue ; - } +if (rc) +break ; rc =kwboot_tty_recv (tty, buf,16 , msg_rsp_timeo);
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]
Re: [PATCH u-boot-marvell 02/10] tools: kwboot: Remove msg_req_delay
In reply to Pali RohárQuoted 3 lines · Pali Rohár
Variable
msg_req_delayis set but never used. So completely remove it.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 40 lines
--- tools/kwboot.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)tools/kwboot.c +0
-4@@ -48,11 +48,9 @@ static unsigned char kwboot_msg_debug[] = { };/* Defines known to work on Kirkwood */ -#define KWBOOT_MSG_REQ_DELAY 10/* ms */ #define KWBOOT_MSG_RSP_TIMEO 50/* ms */ /* Defines known to work on Armada XP */ -#define KWBOOT_MSG_REQ_DELAY_AXP 1000/* ms */ #define KWBOOT_MSG_RSP_TIMEO_AXP 1000/* ms */ /* @@ -285,7 +283,6 @@ static const char kwb_baud_magic[16] = "$baudratechange";static int kwboot_verbose; -static int msg_req_delay =KWBOOT_MSG_REQ_DELAY ;static int msg_rsp_timeo =KWBOOT_MSG_RSP_TIMEO ;static int blk_rsp_timeo =KWBOOT_BLK_RSP_TIMEO ;@@ -1725,7 +1722,6 @@ 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," -q <req-delay>: use specific request-delay\n" );fprintf (stream," -s <resp-timeo>: use specific response-timeout\n" );fprintf (stream," -o <block-timeo>: use specific xmodem block timeout\n" );@@ -1804,12 +1800,11 @@ main(int argc, char **argv)break ;case 'a' :
tools/kwboot.c main(int argc, char **argv) · line 1810
Quoted 10 lines
tools/kwboot.c +1
-2- msg_req_delay =KWBOOT_MSG_REQ_DELAY_AXP ; msg_rsp_timeo =KWBOOT_MSG_RSP_TIMEO_AXP ;break ;case 'q' : - msg_req_delay =atoi (optarg); +/* nop, for backward compatibility */ break ;case 's' :
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]
Re: [PATCH u-boot-marvell 03/10] tools: kwboot: Cleanup bootmsg and debugmsg variables
In reply to Pali RohárQuoted 9 lines · Pali Rohár
Function
kwboot_debugmsg()is always called withkwboot_msg_debugas msg and functionkwboot_bootmsg()withkwboot_msg_debugas msg. Functionkwboot_bootmsg()is never called with NULL msg.Simplify, cleanup and remove dead code.
No functional change.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 109 lines
--- tools/kwboot.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)tools/kwboot.c +13
-16@@ -718,17 +718,14 @@ out: }static int -kwboot_bootmsg (int tty,void *msg) +kwboot_bootmsg (int tty) {struct kwboot_block block;int rc;char c;int count; -if (msg ==NULL ) -kwboot_printv ("Please reboot the target into UART boot mode..." ); -else -kwboot_printv ("Sending boot message. Please reboot the target..." ); +kwboot_printv ("Sending boot message. Please reboot the target..." ); do { rc = tcflush(tty, TCIOFLUSH);@@ -736,7 +733,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ,0 ); + rc =kwboot_tty_send (tty, kwboot_msg_boot,sizeof (kwboot_msg_boot),0 );if (rc)break ; }@@ -798,7 +795,7 @@ kwboot_bootmsg(int tty, void *msg) }static int -kwboot_debugmsg (int tty,void *msg) +kwboot_debugmsg (int tty) {int rc;@@ -811,7 +808,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ,0 ); + rc =kwboot_tty_send (tty, kwboot_msg_debug,sizeof (kwboot_msg_debug),0 );if (rc)break ;@@ -1737,8 +1734,8 @@ main(int argc, char **argv) {const char *ttypath, *imgpath;int rv, rc, tty, term; -void *bootmsg; -void *debugmsg; +int bootmsg; +int debugmsg;void *img;size_t size;size_t after_img_rsv;@@ -1748,8 +1745,8 @@ main(int argc, char **argv) rv =1 ; tty =-1 ; - bootmsg =NULL ; - debugmsg =NULL ; + bootmsg =0 ; + debugmsg =0 ; imgpath =NULL ; img =NULL ; term =0 ;@@ -1771,7 +1768,7 @@ main(int argc, char **argv)case 'b' :if (imgpath || bootmsg || debugmsg) goto usage; - bootmsg = kwboot_msg_boot; + bootmsg =1 ;if (prev_optind == optind) goto usage;if (optind < argc -1 && argv[optind] && argv[optind][0 ] !='-' )@@ -1781,14 +1778,14 @@ main(int argc, char **argv)case 'D' :if (imgpath || bootmsg || debugmsg) goto usage; - bootmsg =NULL ; + bootmsg =0 ; imgpath = optarg;break ;case 'd' :if (imgpath || bootmsg || debugmsg) goto usage; - debugmsg = kwboot_msg_debug; + debugmsg =1 ;break ;case 'p' :@@ -1869,13 +1866,13 @@ main(int argc, char **argv) }if (debugmsg) { - rc =kwboot_debugmsg (tty, debugmsg); + rc =kwboot_debugmsg (tty);
tools/kwboot.c main(int argc, char **argv) · line 1878
Quoted 10 lines
tools/kwboot.c +1
-1if (rc) {perror ("debugmsg" ); goto out; } }else if (bootmsg) { - rc =kwboot_bootmsg (tty, bootmsg); + rc =kwboot_bootmsg (tty);if (rc) {perror ("bootmsg" ); goto out;
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]
Re: [PATCH u-boot-marvell 04/10] tools: kwboot: Use separate thread for sending boot message pattern
In reply to Pali RohárQuoted 45 lines · Pali Rohár
After BootROM successfully detects boot message pattern on UART it waits until host stop sending data on UART. For example Armada 385 BootROM requires that host does not send anything on UART at least 24 ms. If host is still sending something then BootROM waits (possibly infinitely).
BootROM successfully detects boot message pattern if it receives it in small period of time after power on.
So to ensure that host put BootROM into UART boot mode, host must send continuous stream of boot message pattern with a small gap (for A385 at least 24 ms) after series of pattern. But this gap cannot be too often or too long to ensure that it does not cover whole BootROM time window when it is detecting for boot message pattern.
Therefore it is needed to do following steps in cycle without any delay:
1. send series of boot message pattern over UART
2. wait until kernel transmit all data
3. sleep small period of timeAt the same time, host needs to monitor input queue, data received on the UART and checking if it contains NAK byte by which BootROM informs that xmodem transfer is ready.
But it is not possible to wait until kernel transmit all data on UART and at the same time in the one process to also wait for input data. This is limitation of POSIX tty API and also by linux kernel that it does not provide asynchronous function for waiting until all data are transmitted. There is only synchronous variant
tcdrain().So to correctly implement this handshake on systems with linux kernel, it is needed to use
tcdrain()in separate thread.Implement sending of boot message pattern in one thread and reading of reply in the main thread. Use pthread library for threads.
This change makes UART booting on Armada 385 more reliable. It is possible to start kwboot and power on board after minute and kwboot correctly put board into UART boot mode.
Old implementation without separate thread has an issue that it read just one byte from UART input queue and then it send 128 message pattern to the output queue. If some noise was on UART then kwboot was not able to read BootROM response as its input queue was just overflowed and kwboot was sending more data than receiving.
Quoted 3 lines
This change basically fixed above issue too.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 170 lines
--- tools/Makefile | 3 ++ tools/kwboot.c | 120 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 104 insertions(+), 19 deletions(-)tools/Makefile +3
-0@@ -199,6 +199,9 @@ hostprogs-$(CONFIG_EXYNOS5250) += mkexynosspl hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl HOSTCFLAGS_mkexynosspl.o := -pedantic +HOSTCFLAGS_kwboot.o += -pthread +HOSTLDLIBS_kwboot += -pthread + ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o hostprogs-$(CONFIG_X86) += ifdtooltools/kwboot.c +100
-16@@ -28,6 +28,7 @@#include <stdint.h> #include <time.h> #include <sys/stat.h> +#include <pthread.h> #ifdef __linux__#include "termios_linux.h" @@ -717,37 +718,120 @@ out:return rc; } +static void * +kwboot_msg_write_handler (void *arg) +{ +int tty = *(int *)((void **)arg)[0 ]; +const void *msg = ((void **)arg)[1 ]; +int rsp_timeo = msg_rsp_timeo; +int i, dummy_oldtype; + +/* allow to cancel this thread at any time */ +pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS , &dummy_oldtype); + +while (1 ) { +/* write 128 samples of message pattern into the output queue without waiting */ +for (i =0 ; i <128 ; i++) { +if (kwboot_tty_send (tty, msg,8 ,1 ) <0 ) { +perror ("\nFailed to send message pattern" ); +exit (1 ); + } + } +/* wait until output queue is transmitted and then make pause */ +if (tcdrain (tty) <0 ) { +perror ("\nFailed to send message pattern" ); +exit (1 ); + } +/* BootROM requires pause on UART after it detects message pattern */ +usleep (rsp_timeo *1000 ); + } +} + +static int +kwboot_msg_start_thread (pthread_t *thread,int *tty,void *msg) +{ +void *arg[2 ]; +int rc; + + arg[0 ] = tty; + arg[1 ] = msg; + rc =pthread_create (thread,NULL , kwboot_msg_write_handler, arg); +if (rc) { + errno = rc; +return -1 ; + } + +return 0 ; +} + +static int +kwboot_msg_stop_thread (pthread_t thread) +{ +int rc; + + rc =pthread_cancel (thread); +if (rc) { + errno = rc; +return -1 ; + } + + rc =pthread_join (thread,NULL ); +if (rc) { + errno = rc; +return -1 ; + } + +return 0 ; +} +static int kwboot_bootmsg (int tty) {struct kwboot_block block; -int rc; +pthread_t write_thread; +int rc, err;char c; -int count; - -kwboot_printv ("Sending boot message. Please reboot the target..." ); -do { - rc =tcflush (tty,TCIOFLUSH ); -if (rc) -break ; +/* flush input and output queue */ +tcflush (tty,TCIOFLUSH ); -for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, kwboot_msg_boot,sizeof (kwboot_msg_boot),0 ); -if (rc) -break ; - } + rc =kwboot_msg_start_thread (&write_thread, &tty, kwboot_msg_boot); +if (rc) { +perror ("Failed to start write thread" ); +return rc; + } - rc =kwboot_tty_recv (tty, &c,1 , msg_rsp_timeo); +kwboot_printv ("Sending boot message. Please reboot the target..." ); + err =0 ; +while (1 ) {kwboot_spinner (); - }while (rc || c !=NAK ); + rc =kwboot_tty_recv (tty, &c,1 , msg_rsp_timeo); +if (rc && errno ==ETIMEDOUT ) { +continue ; + }else if (rc) { + err = errno; +break ; + } + +if (c ==NAK ) +break ; + }kwboot_printv ("\n" ); -if (rc) + rc =kwboot_msg_stop_thread (write_thread); +if (rc) { +perror ("Failed to stop write thread" );return rc; + } + +if (err) { + errno = err; +perror ("Failed to read response for boot message pattern" ); +return -1 ; + }/* * At this stage we have sent more boot message patterns and BootROM @@ -1873,10 +1957,8 @@ main(int argc, char **argv) }
tools/kwboot.c main(int argc, char **argv) · line 1964
Quoted 10 lines
tools/kwboot.c +1
-3}else if (bootmsg) { rc =kwboot_bootmsg (tty); -if (rc) { -perror ("bootmsg" ); +if (rc) goto out; - } }if (img) {
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]
Re: [PATCH u-boot-marvell 05/10] tools: kwboot: Fix sending and processing debug message pattern (-d option)
In reply to Pali RohárQuoted 23 lines · Pali Rohár
-d option is currently broken. In most cases BootROM does not detect this message pattern. For sending debug message pattern it is needed to do same steps as for boot message pattern.
Implement sending debug message pattern via same separate thread like it is for boot message pattern.
Checking if BootROM entered into UART debug mode is different than detecting UART boot mode. When in boot mode, BootROM sends xmodem NAK bytes. When in debug mode, BootROM activates console echo and reply back every written byte (extept \r\n which is interpreted as executing command and \b which is interpreting as removing the last sent byte).
So in kwboot, check that BootROM send back at least 4 debug message patterns as a echo reply for debug message patterns which kwboot is sending in the loop.
Then there is another observation, if host writes too many bytes (as command) then BootROM command line buffer may overflow after trying to execute such long command. To workaround this overflow, it is enough to remove bytes from the input line buffer by sending 3 \b bytes for every sent character. So do it.
Quoted 4 lines
With this change, it is possbile to enter into the UART debug mode with kwboot -d option.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 163 lines
--- tools/kwboot.c | 139 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 123 insertions(+), 16 deletions(-)tools/kwboot.c +122
-13@@ -881,30 +881,139 @@ kwboot_bootmsg(int tty)static int kwboot_debugmsg (int tty) { -int rc; +unsigned char buf[8192 ]; +pthread_t write_thread; +int rc, err, i, pos; +size_t off; -kwboot_printv ("Sending debug message. Please reboot the target..." ); +/* flush input and output queue */ +tcflush (tty,TCIOFLUSH ); -do { -char buf[16 ]; + rc =kwboot_msg_start_thread (&write_thread, &tty, kwboot_msg_debug); +if (rc) { +perror ("Failed to start write thread" ); +return rc; + } - rc =tcflush (tty,TCIOFLUSH ); -if (rc) -break ; +kwboot_printv ("Sending debug message. Please reboot the target..." ); +kwboot_spinner (); - rc =kwboot_tty_send (tty, kwboot_msg_debug,sizeof (kwboot_msg_debug),0 ); -if (rc) + err =0 ; + off =0 ; +while (1 ) { +/* Read immediately all bytes in queue without waiting */ + rc =read (tty, buf + off,sizeof (buf) - off); +if ((rc <0 && errno ==EINTR ) || rc ==0 ) { +continue ; + }else if (rc <0 ) { + err = errno;break ; - - rc =kwboot_tty_recv (tty, buf,16 , msg_rsp_timeo); + } + off += rc -1 ;kwboot_spinner (); - }while (rc); +/* +* Check if we received at least 4 debug message patterns +* (console echo from BootROM) in cyclic buffer +*/ + +for (pos =0 ; pos <sizeof (kwboot_msg_debug); pos++) +if (buf[off] == kwboot_msg_debug[(pos + off) %sizeof (kwboot_msg_debug)]) +break ; + +for (i = off; i >=0 ; i--) +if (buf[i] != kwboot_msg_debug[(pos + i) %sizeof (kwboot_msg_debug)]) +break ; + + off -= i; + +if (off >=4 *sizeof (kwboot_msg_debug)) +break ; + +/* If not move valid suffix from end of the buffer to the beginning of buffer */ +memmove (buf, buf + i +1 , off); + }kwboot_printv ("\n" ); -return rc; + rc =kwboot_msg_stop_thread (write_thread); +if (rc) { +perror ("Failed to stop write thread" ); +return rc; + } + +if (err) { + errno = err; +perror ("Failed to read response for debug message pattern" ); +return -1 ; + } + +/* flush output queue with remaining debug message patterns */ + rc =tcflush (tty,TCOFLUSH ); +if (rc) { +perror ("Failed to flush output queue" ); +return rc; + } + +kwboot_printv ("Clearing input buffer...\n" ); + +/* +* Wait until BootROM transmit all remaining echo characters. +* Experimentally it was measured that for Armada 385 BootROM +* it is required to wait at least 0.415s. So wait 0.5s. +*/ +usleep (500 *1000 ); + +/* +* In off variable is stored number of characters received after the +* successful detection of echo reply. So these characters are console +* echo for other following debug message patterns. BootROM may have in +* its output queue other echo characters which were being transmitting +* before above sleep call. So read remaining number of echo characters +* sent by the BootROM now. +*/ +while ((rc =kwboot_tty_recv (tty, &buf[0 ],1 ,0 )) ==0 ) + off++; +if (errno !=ETIMEDOUT ) { +perror ("Failed to read response" ); +return rc; + } + +/* +* Clear every echo character set by the BootROM by backspace byte. +* This is required prior writing any command to the BootROM debug +* because BootROM command line buffer has limited size. If length +* of the command is larger than buffer size then it looks like +* that Armada 385 BootROM crashes after sending ENTER. So erase it. +* Experimentally it was measured that for Armada 385 BootROM it is +* required to send at least 3 backspace bytes for one echo character. +* This is unknown why. But lets do it. +*/ + off *=3 ; +memset (buf,'\x08' ,sizeof (buf)); +while (off >sizeof (buf)) { + rc =kwboot_tty_send (tty, buf,sizeof (buf),1 ); +if (rc) { +perror ("Failed to send clear sequence" ); +return rc; + } + off -=sizeof (buf); + } + rc =kwboot_tty_send (tty, buf, off,0 ); +if (rc) { +perror ("Failed to send clear sequence" ); +return rc; + } + +usleep (msg_rsp_timeo *1000 ); + rc =tcflush (tty,TCIFLUSH ); +if (rc) { +perror ("Failed to flush input queue" ); +return rc; + } + +return 0 ; } static size_t@@ -1951,10 +2060,8 @@ main(int argc, char **argv)
tools/kwboot.c main(int argc, char **argv) · line 2067
Quoted 10 lines
tools/kwboot.c +1
-3if (debugmsg) { rc =kwboot_debugmsg (tty); -if (rc) { -perror ("debugmsg" ); +if (rc) goto out; - } }else if (bootmsg) { rc =kwboot_bootmsg (tty);if (rc)
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]
Re: [PATCH u-boot-marvell 06/10] tools: kwboot: Add support for backspace key in mini terminal
In reply to Pali RohárQuoted 4 lines · Pali Rohár
Marvell BootROM recognize only '\b' byte as backspace. Use terminfo for retrieving current backspace sequence and replace any occurrence of backspace sequence by the '\b' byte.
Quoted 8 lines
Reading terminfo database is possible via
tigetstr()function from system library libtinfo.so.*. So link kwboot with -ltinfo.Normally terminfo functions are in <
term.h> system header file. But this header file conflicts with U-Boot "termios_linux.h" header file. So declare terminfo functions manually.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 189 lines
--- tools/Makefile | 2 +- tools/kwboot.c | 109 +++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 97 insertions(+), 14 deletions(-)tools/Makefile +1
-1@@ -200,7 +200,7 @@ hostprogs-$(CONFIG_EXYNOS5420) += mkexynosspl HOSTCFLAGS_mkexynosspl.o := -pedantic HOSTCFLAGS_kwboot.o += -pthread -HOSTLDLIBS_kwboot += -pthread +HOSTLDLIBS_kwboot += -pthread -ltinfo ifdtool-objs := $(LIBFDT_OBJS) ifdtool.o hostprogs-$(CONFIG_X86) += ifdtooltools/kwboot.c +95
-12@@ -36,6 +36,13 @@#include <termios.h> #endif +/* +* These functions are in <term.h> header file, but this header file conflicts +* with "termios_linux.h" header file. So declare these functions manually. +*/ +extern int setupterm (const char *,int ,int *); +extern char *tigetstr (const char *); +/* * Marvell BootROM UART Sensing */ @@ -1376,37 +1383,84 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate) }static int -kwboot_term_pipe (int in,int out,const char *quit,int *s) +kwboot_term_pipe (int in,int out,const char *quit,int *s,const char *kbs,int *k) {char buf[128 ]; -ssize_t nin; +ssize_t nin, noff; nin =read (in, buf,sizeof (buf));if (nin <=0 )return -1 ; -if (quit) { + noff =0 ; + +if (quit || kbs) {int i;for (i =0 ; i < nin; i++) { -if (buf[i] == quit[*s]) { +if ((quit || kbs) && + (!quit || buf[i] != quit[*s]) && + (!kbs || buf[i] != kbs[*k])) { +const char *prefix; +int plen; + +if (quit && kbs) { + prefix = (*s >= *k) ? quit : kbs; + plen = (*s >= *k) ? *s : *k; + }else if (quit) { + prefix = quit; + plen = *s; + }else { + prefix = kbs; + plen = *k; + } + +if (plen > i &&kwboot_write (out, prefix, plen - i) <0 ) +return -1 ; + } + +if (quit && buf[i] == quit[*s]) { (*s)++;if (!quit[*s]) { nin = (i > *s) ? (i - *s) :0 ;break ; } - }else { -if (*s > i &&kwboot_write (out, quit, *s - i) <0 ) -return -1 ; + }else if (quit) { *s =0 ; } + +if (kbs && buf[i] == kbs[*k]) { + (*k)++; +if (!kbs[*k]) { +if (i > *k + noff && +kwboot_write (out, buf + noff, i - *k - noff) <0 ) +return -1 ; +/* +* Replace backspace key by '\b' (0x08) +* byte which is the only recognized +* backspace byte by Marvell BootROM. +*/ +if (write (out,"\x08" ,1 ) <0 ) +return -1 ; + noff = i +1 ; + *k =0 ; + } + }else if (kbs) { + *k =0 ; + } } -if (i == nin) - nin -= (nin > *s) ? *s : nin; +if (i == nin) { + i =0 ; +if (quit && i < *s) + i = *s; +if (kbs && i < *k) + i = *k; + nin -= (nin > i) ? i : nin; + } } -if (kwboot_write (out, buf, nin) <0 ) +if (nin > noff &&kwboot_write (out, buf + noff, nin - noff) <0 )return -1 ;return 0 ;@@ -1415,7 +1469,8 @@ kwboot_term_pipe(int in, int out, const char *quit, int *s)static int kwboot_terminal (int tty) { -int rc, in, s; +int rc, in, s, k; +const char *kbs =NULL ;const char *quit ="\34c" ;struct termios otio, tio;@@ -1434,6 +1489,33 @@ kwboot_terminal(int tty) goto out; } +/* +* Get sequence for backspace key used by the current +* terminal. Every occurrence of this sequence will be +* replaced by '\b' byte which is the only recognized +* backspace byte by Marvell BootROM. +* +* Note that we cannot read this sequence from termios +* c_cc[VERASE] as VERASE is valid only when ICANON is +* set in termios c_lflag, which is not case for us. +* +* Also most terminals do not set termios c_cc[VERASE] +* as c_cc[VERASE] can specify only one-byte sequence +* and instead let applications to read (possible +* multi-byte) sequence for backspace key from "kbs" +* terminfo database based on $TERM env variable. +* +* So read "kbs" from terminfo database via tigetstr() +* call after successful setupterm(). Most terminals +* use byte 0x7F for backspace key, so replacement with +* '\b' is required. +*/ +if (setupterm (NULL ,STDOUT_FILENO , &rc) ==0 ) { + kbs =tigetstr ("kbs" ); +if (kbs == (char *)-1 ) + kbs =NULL ; + } +kwboot_printv ("[Type Ctrl-%c + %c to quit]\r\n" , quit[0 ] |0100 , quit[1 ]); }else @@ -1441,6 +1523,7 @@ kwboot_terminal(int tty) rc =0 ; s =0 ; + k =0 ; do { fd_set rfds;@@ -1460,13 +1543,13 @@ kwboot_terminal(int tty)break ;if (FD_ISSET (tty, &rfds)) { - rc =kwboot_term_pipe (tty,STDOUT_FILENO ,NULL ,NULL ); + rc =kwboot_term_pipe (tty,STDOUT_FILENO ,NULL ,NULL ,NULL ,NULL );
tools/kwboot.c kwboot_terminal(int tty) · line 1555
Quoted 10 lines
tools/kwboot.c +1
-1if (rc)break ; }if (in >=0 &&FD_ISSET (in, &rfds)) { - rc =kwboot_term_pipe (in, tty, quit, &s); + rc =kwboot_term_pipe (in, tty, quit, &s, kbs, &k);if (rc)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]
Re: [PATCH u-boot-marvell 07/10] tools: kwboot: Update usage
In reply to Pali RohárQuoted 3 lines · Pali Rohár
Add all supported Armada SoCs and document -b and -d options in usage.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 17 lines
--- tools/kwboot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)tools/kwboot.c +1
-1@@ -1986,14 +1986,15 @@ static void kwboot_usage(FILE *stream, char *progname) {fprintf (stream, -"Usage: %s [OPTIONS] [-b <image> | -D <image> ] [-B <baud> ] <TTY>\n" , +"Usage: %s [OPTIONS] [-b <image> | -D <image> | -b | -d ] [-B <baud> ] [-t] <TTY>\n" , progname);fprintf (stream,"\n" ); fprintf(stream,
tools/kwboot.c static void · line 2000
Quoted 10 lines
tools/kwboot.c +3
-2- " -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP)\n"); + " -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP/375/38x/39x)\n");fprintf (stream," -D <image>: boot <image> without preamble (Dove)\n" ); -fprintf (stream," -d: enter debug mode\n" ); +fprintf (stream," -b: enter xmodem boot mode\n" ); +fprintf (stream," -d: enter console debug mode\n" );fprintf (stream," -a: use timings for Armada XP\n" );fprintf (stream," -s <resp-timeo>: use specific response-timeout\n" ); fprintf(stream,
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]
Re: [PATCH u-boot-marvell 08/10] tools: kwboot: Update manpage
In reply to Pali RohárQuoted 8 lines · Pali Rohár
Document -D, -b, -d, -q and -s options.
Add common examples how to use kwboot.
Add information about Armada 38x BootROM bug for debug console mode and how to workaround it.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 133 lines
--- doc/kwboot.1 | 103 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-)doc/kwboot.1 +95
-3@@ -1,4 +1,4 @@ -.TH KWBOOT 1 "2021-08-25" +.TH KWBOOT 1 "2022-03-02" .SH NAME kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over a serial link.@@ -47,6 +47,48 @@ code in it's header which may also print some output via UART (for example U-Boot SPL does this). In such a case, this output is also written to stdout after the header is sent. +.TP +.B "\-b" +Do only handshake on \fITTY\fP without uploading any file. File upload +could be done later via option \fB\-D\fP or via any other Xmodem +application, like \fBsx\fP(1). + +.TP +.B "\-d" +Do special handshake on \fITTY\fP for console debug mode. + +This will instruct BootROM to enter builtin simple console debug mode. +Should be combined with option \fB\-t\fP. + +To get a BootROM help, type this command followed by ENTER key: + +.RS 1.2i +.TP +.B ? +.RE +.IP + +Armada 38x BootROM has a bug which cause that BootROM's standard output +is turned off on UART when SPI-NOR contains valid boot image. Nevertheless +BootROM's standard input and BootROM's terminal echo are active and working +fine. To workaround this BootROM bug with standard output, it is possible +to manually overwrite BootROM variables stored in SRAM which BootROM use +for checking if standard output is enabled or not. To enable BootROM +standard output on UART, type this command folled by ENTER key: + +.RS 1.2i +.TP +.B w 0x40034100 1 +.RE + +.TP +.BI "\-D" " image" +Upload file \fIimage\fP over \fITTY\fP without initial handshake. + +This method is used primary on Dove platforms, where BootROM does +not support initial handshake for entering UART upload mode and +strapping pins (exported via e.g. buttons) are used instead. + .TP .BI "\-p" Obsolete. Does nothing.@@ -55,13 +97,33 @@ In the past, when this option was used, the program patched the header in the image prior upload, to "UART boot" type. This is now done by default. +.TP +.B "\-q" +Obsolete. Does nothing. + +It is unknown whether it did something in the past. + +.TP +.BI "\-s" " response-timeout" +Specify custom response timeout when doing handshake. Default value is 50 ms. +It is the timeout between sending two consecutive handshake patterns, meaning +how long to wait for response from BootROM. Affects only option \fB\-b\fP with +image file and option \fB\-d\fP. + +Option \fB-a\fP specify response timeout suitable for Armada XP BootROM and +currently it is 1000 ms. + +Some testing showed that specifying 24 ms as response timeout make handshake +with Armada 385 BootROM more stable. + .TP .BI "\-t" Run a terminal program, connecting standard input and output to .RB \fITTY\fP. -If used in combination with \fB-b\fP, terminal mode is entered -immediately following a successful image upload. +If used in combination with \fB\-b\fP, \fB\-D\fP or \fB\-d\fP option, +terminal mode is entered immediately following a successful image upload +or successful handshake (if not doing image upload). If standard I/O streams connect to a console, this mode will terminate after receiving \fBctrl-\e\fP followed by \fBc\fP from console input.@@ -85,9 +147,42 @@ Tested values for \fIbaudrate\fP for Armada 38x include: 115200, 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3125000, 4000000 and 5200000. +.SH "EXAMPLES" + +Instruct BootROM to enter boot Xmodem boot mode, send \fIu-boot-spl.kwb\fP +kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP at 115200 Bd and run terminal +program: +.IP +.B kwboot -b u-boot-spl.kwb -t /dev/ttyUSB0 + +.PP +Instruct BootROM to enter boot Xmodem boot mode, send header of +\fIu-boot-spl.kwb\fP kwbimage file via Xmodem at 115200 Bd, then instruct +BootROM to change baudrate to 5200000 Bd, send data part of the kwbimage +file via Xmodem at high speed and finally run terminal program: +.IP +.B kwboot -b u-boot-spl.kwb -B 5200000 -t /dev/ttyUSB0 + +.PP +Only send \fIu-boot-spl.kwb\fP kwbimage file via Xmodem on \fI/dev/ttyUSB0\fP +at 115200 Bd: +.IP +.B kwboot -D u-boot-spl.kwb /dev/ttyUSB0 + +.PP +Instruct BootROM to enter console debug mode and run terminal program on +\fI/dev/ttyUSB0\fP at 115200 Bd: +.IP +.B kwboot -d -t /dev/ttyUSB0 + +.PP +Only run terminal program on \fI/dev/ttyUSB0\fP at 115200 Bd:
doc/kwboot.1 Tested values for \fIbaudrate\fP for Armada 38x include: 115200, · line 188
Quoted 10 lines
doc/kwboot.1 +4
-1+.IP +.B kwboot -t /dev/ttyUSB0 + .SH "SEE ALSO" .PP -\fBmkimage\fP(1) +\fBmkimage\fP(1), \fBsx\fP(1) .SH "AUTHORS"
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]
Re: [PATCH u-boot-marvell 09/10] tools: kwboot: Update doc about Avanta
In reply to Pali RohárQuoted 5 lines · Pali Rohár
Testes proved that current kwboot version supports also Avanta SoCs. It looks like that Avanta SoCs are using same kwbimage format as Armada.
Signed-off-by Pali Rohár <[email protected]>Tested-by Tony Dinh <[email protected]>
Thanks,
Stefan
Quoted 33 lines
--- doc/kwboot.1 | 2 +- tools/kwboot.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)doc/kwboot.1 +1
-1@@ -11,7 +11,7 @@ kwboot \- Boot Marvell Kirkwood (and others 32-bit) SoCs over a serial link. .SH "DESCRIPTION" The \fBkwboot\fP program boots boards based on Marvell's 32-bit -platforms including Kirkwood, Dove, A370, AXP, A375, A38x +platforms including Kirkwood, Dove, Avanta, A370, AXP, A375, A38x and A39x over their integrated UART. Boot image files will typically contain a second stage boot loader, such as U-Boot. The image file must conform to Marvell's BootROM firmware image formattools/kwboot.c +2
-2@@ -1,7 +1,7 @@/* * Boot a Marvell SoC, with Xmodem over UART0. -* supports Kirkwood, Dove, Armada 370, Armada XP, Armada 375, Armada 38x and -* Armada 39x +* supports Kirkwood, Dove, Avanta, Armada 370, Armada XP, Armada 375, +* Armada 38x and Armada 39x. * * (c) 2012 Daniel Stodden <[email protected]> * (c) 2021 Pali Rohár <[email protected]>
tools/kwboot.c kwboot_usage(FILE *stream, char *progname) · line 1996
Quoted 8 lines
tools/kwboot.c +1
-1@@ -1990,7 +1990,7 @@ kwboot_usage(FILE *stream, char *progname) progname);fprintf (stream,"\n" );fprintf (stream, -" -b <image>: boot <image> with preamble (Kirkwood, Armada 370/XP/375/38x/39x)\n" ); +" -b <image>: boot <image> with preamble (Kirkwood, Avanta, Armada 370/XP/375/38x/39x)\n" );fprintf (stream," -D <image>: boot <image> without preamble (Dove)\n" );fprintf (stream," -b: enter xmodem boot mode\n" );
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]
Re: [PATCH u-boot-marvell 10/10] tools: kwboot: Update references with public links
In reply to Pali RohárQuoted 4 lines · Pali Rohár
Public documents about BootROM of some Marvell SoCs are available in the public Web Archive. Put this information into source code.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 36 lines
--- tools/kwboot.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)tools/kwboot.c +21
-3@@ -7,9 +7,34 @@* (c) 2021 Pali Rohár <[email protected]> * (c) 2021 Marek Behún <[email protected]> * -* References: marvell.com, "88F6180, 88F6190, 88F6192, and 88F6281 -* Integrated Controller: Functional Specifications" December 2, -* 2008. Chapter 24.2 "BootROM Firmware". +* References: +* - "88F6180, 88F6190, 88F6192, and 88F6281: Integrated Controller: Functional +* Specifications" December 2, 2008. Chapter 24.2 "BootROM Firmware". +* https://web.archive.org/web/20130730091033/https://www.marvell.com/embedded-processors/kirkwood/assets/FS_88F6180_9x_6281_OpenSource.pdf +* - "88AP510: High-Performance SoC with Integrated CPU, 2D/3D Graphics +* Processor, and High-Definition Video Decoder: Functional Specifications" +* August 3, 2011. Chapter 5 "BootROM Firmware" +* https://web.archive.org/web/20120130172443/https://www.marvell.com/application-processors/armada-500/assets/Armada-510-Functional-Spec.pdf +* - "88F6710, 88F6707, and 88F6W11: ARMADA(R) 370 SoC: Functional Specifications" +* May 26, 2014. Chapter 6 "BootROM Firmware". +* https://web.archive.org/web/20140617183701/https://www.marvell.com/embedded-processors/armada-300/assets/ARMADA370-FunctionalSpec-datasheet.pdf +* - "MV78230, MV78260, and MV78460: ARMADA(R) XP Family of Highly Integrated +* Multi-Core ARMv7 Based SoC Processors: Functional Specifications" +* May 29, 2014. Chapter 6 "BootROM Firmware". +* https://web.archive.org/web/20180829171131/https://www.marvell.com/embedded-processors/armada-xp/assets/ARMADA-XP-Functional-SpecDatasheet.pdf +* - "ARMADA(R) 375 Value-Performance Dual Core CPU System on Chip: Functional +* Specifications" Doc. No. MV-S109377-00, Rev. A. September 18, 2013. +* Chapter 7 "Boot Sequence" +* CONFIDENTIAL, no public documentation available +* - "88F6810, 88F6811, 88F6821, 88F6W21, 88F6820, and 88F6828: ARMADA(R) 38x +* Family High-Performance Single/Dual CPU System on Chip: Functional
tools/kwboot.c line 40
Quoted 10 lines
tools/kwboot.c +7
-0+* Specifications" Doc. No. MV-S109094-00, Rev. C. August 2, 2015. +* Chapter 7 "Boot Flow" +* CONFIDENTIAL, no public documentation available +* - "88F6920, 88F6925 and 88F6928: ARMADA(R) 39x High-Performance Dual Core CPU +* System on Chip Functional Specifications" Doc. No. MV-S109896-00, Rev. B. +* December 22, 2015. Chapter 7 "Boot Flow" +* CONFIDENTIAL, no public documentation available */ #include "kwbimage.h"
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]
Quoted 24 lines · Pali Rohár
This patch series fixes sending boot and debug patterns by doing it in separate thread. Entering BootROM debug mode via '-d' option is now more stable and working fine on Armada 385. There is also support for backspace key and updated documentation.
Stefan and Tony, could you test this patch series on more Marvell boards which you have? Specially if '-d' option is working too.
*** BLURB HERE ***
Pali Rohár (10):
tools: kwboot: Check for return value ofkwboot_tty_send()and
tcflush()
tools: kwboot: Removemsg_req_delay
tools: kwboot: Cleanup bootmsg and debugmsg variables
tools: kwboot: Use separate thread for sending boot message pattern
tools: kwboot: Fix sending and processing debug message pattern (-d
option)
tools: kwboot: Add support for backspace key in mini terminal
tools: kwboot: Update usage
tools: kwboot: Update manpage
tools: kwboot: Update doc about Avanta
tools: kwboot: Update references with public links
Quoted 5 lines
doc/kwboot.1 | 105 ++++++++++- tools/Makefile | 3 + tools/kwboot.c | 462 ++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 483 insertions(+), 87 deletions(-)
Applied to u-boot-marvell/master
Thanks,
Stefan