Yet another kwboot improvements
cover Yet another kwboot improvements
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1
The main improvement is in patch 5, which changes where we inject the code for changing baudrate back to 115200 Baud after fast upload. Instead of injecting it before the main data image, we now inject it after.
This is because there are some kwb images that upload at address 0, and injecting the code before that doesn't work, since there is no RAM mapped at 0xfffff000.
Marek & Pali
Pali Rohár (13):
tools: kwboot: Initialize rfds to zero
tools: kwboot: Fix initialization of tty device
tools: kwboot: Reserve enough space for patching kwbimage in memory
tools: kwboot: Validate 4-byte image data checksum
tools: kwboot: Inject baudrate change back code after data part
tools: kwboot: Recalculate 4-byte data checksum after injecting
baudrate code
tools: kwboot: Correctly set configuration of UART for BootROM
messages
tools: kwboot: Show verbose message when waiting for baudrate change
magic
tools: kwboot: Simplify code for aligning image header
tools: kwboot: Do not modify kwbimage header before increasing its
size
tools: kwboot: Calculate real used space in kwbimage header when
calling kwboot_img_grow_hdr()
tools: kwboot: Change retry loop from decreasing to increasing
tools: kwboot: Resend first 3 xmodem retry packets immediately
tools/kwboot.c | 178 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 120 insertions(+), 58 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/13 tools: kwboot: Initialize rfds to zero
From: Pali Rohár <[email protected]>
Explicitly zero out the rfds fd_set with FD_ZERO() before using it.
--- tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)
tools/kwboot.c +1 -0
@@ -1151,6 +1151,7 @@ kwboot_terminal(int tty)fd_set rfds;int nfds =0 ; +FD_ZERO (&rfds);FD_SET (tty, &rfds); nfds = nfds < tty ? tty : nfds;
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 01/13] tools: kwboot: Initialize rfds to zero
Quoted 6 lines · Marek Behún
From: Pali Rohár <[email protected]>
Explicitly zero out the rfds
fd_setwithFD_ZERO()before using it.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 10 lines
--- tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)tools/kwboot.c +0
-0
tools/kwboot.c kwboot_terminal(int tty) · line 1157
Quoted 7 lines
tools/kwboot.c +1
-0@@ -1151,6 +1151,7 @@ kwboot_terminal(int tty)fd_set rfds;int nfds =0 ; +FD_ZERO (&rfds);FD_SET (tty, &rfds); nfds = nfds < tty ? tty : nfds;
Viele Grüße,
Stefan
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]
PATCH 2/13 tools: kwboot: Fix initialization of tty device
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Explicitly disable 2 stop bits by clearing CSTOPB flag, disable modem control flow by clearing CRTSCTS flag and do not send hangup after closing device by clearing HUPCL flag.
--- tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)
tools/kwboot.c +1 -0
@@ -657,6 +657,7 @@ kwboot_open_tty(const char *path, int baudrate)cfmakeraw (&tio); tio.c_cflag |=CREAD |CLOCAL ; + tio.c_cflag &= ~(CSTOPB |HUPCL |CRTSCTS ); tio.c_cc[VMIN ] =1 ; tio.c_cc[VTIME ] =0 ;
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 02/13] tools: kwboot: Fix initialization of tty device
Quoted 8 lines · Marek Behún
From: Pali Rohár <[email protected]>
Explicitly disable 2 stop bits by clearing CSTOPB flag, disable modem control flow by clearing CRTSCTS flag and do not send hangup after closing device by clearing HUPCL flag.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 10 lines
--- tools/kwboot.c | 1 + 1 file changed, 1 insertion(+)tools/kwboot.c +0
-0
tools/kwboot.c kwboot_open_tty(const char *path, int baudrate) · line 663
Quoted 7 lines
tools/kwboot.c +1
-0@@ -657,6 +657,7 @@ kwboot_open_tty(const char *path, int baudrate)cfmakeraw (&tio); tio.c_cflag |=CREAD |CLOCAL ; + tio.c_cflag &= ~(CSTOPB |HUPCL |CRTSCTS ); tio.c_cc[VMIN ] =1 ; tio.c_cc[VTIME ] =0 ;
Viele Grüße,
Stefan
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]
PATCH 3/13 tools: kwboot: Reserve enough space for patching kwbimage in memory
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
SPI image header and data parts do not have to be aligned to 128 byte xmodem block size. So reserve additional memory for aligning header part and additional memory for aligning data part.
--- tools/kwboot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/kwboot.c +3 -1
@@ -1672,8 +1672,10 @@ main(int argc, char **argv)else /* ensure we have enough space for baudrate change code */ after_img_rsv +=KWBOOT_BAUDRATE_BIN_HEADER_SZ + +KWBOOT_XM_BLKSZ +sizeof (kwboot_pre_baud_code) + -sizeof (kwboot_baud_code); +sizeof (kwboot_baud_code) + +KWBOOT_XM_BLKSZ ;if (imgpath) { img =kwboot_read_image (imgpath, &size, after_img_rsv);
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 03/13] tools: kwboot: Reserve enough space for patching kwbimage in memory
Quoted 8 lines · Marek Behún
From: Pali Rohár <[email protected]>
SPI image header and data parts do not have to be aligned to 128 byte xmodem block size. So reserve additional memory for aligning header part and additional memory for aligning data part.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 11 lines
--- tools/kwboot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)tools/kwboot.c +0
-0@@ -1672,8 +1672,10 @@ main(int argc, char **argv)else
tools/kwboot.c main(int argc, char **argv) · line 1681
Quoted 10 lines
tools/kwboot.c +3
-1/* ensure we have enough space for baudrate change code */ after_img_rsv +=KWBOOT_BAUDRATE_BIN_HEADER_SZ + +KWBOOT_XM_BLKSZ +sizeof (kwboot_pre_baud_code) + -sizeof (kwboot_baud_code); +sizeof (kwboot_baud_code) + +KWBOOT_XM_BLKSZ ;if (imgpath) { img =kwboot_read_image (imgpath, &size, after_img_rsv);
Viele Grüße,
Stefan
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]
PATCH 4/13 tools: kwboot: Validate 4-byte image data checksum
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Data part of the image contains 4-byte checksum. Validate it when processing the image.
--- tools/kwboot.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
tools/kwboot.c +34 -0
@@ -1251,6 +1251,37 @@ kwboot_hdr_csum8(const void *hdr)return csum; } +static uint32_t * +kwboot_img_csum32_ptr (void *img) +{ +struct main_hdr_v1 *hdr = img; +uint32_t datasz; + + datasz =le32_to_cpu (hdr->blocksize) -sizeof (uint32_t ); + +return img +le32_to_cpu (hdr->srcaddr) + datasz; +} + +static uint32_t +kwboot_img_csum32 (const void *img) +{ +const struct main_hdr_v1 *hdr = img; +uint32_t datasz, csum =0 ; +const uint32_t *data; + + datasz =le32_to_cpu (hdr->blocksize) -sizeof (csum); +if (datasz %sizeof (uint32_t )) +return 0 ; + + data = img +le32_to_cpu (hdr->srcaddr); +while (datasz >0 ) { + csum +=le32_to_cpu (*data++); + datasz -=4 ; + } + +return cpu_to_le32 (csum); +} +static int kwboot_img_is_secure (void *img) {
@@ -1462,6 +1493,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) *size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize)) goto err; +if (kwboot_img_csum32 (img) != *kwboot_img_csum32_ptr (img)) + goto err; + is_secure =kwboot_img_is_secure (img);if (hdr->blockid !=IBR_HDR_UART_ID ) {
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 04/13] tools: kwboot: Validate 4-byte image data checksum
Quoted 8 lines · Marek Behún
From: Pali Rohár <[email protected]>
Data part of the image contains 4-byte checksum. Validate it when processing the image.
Signed-off-by Pali Rohár <[email protected]>[ refactored ]Signed-off-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 48 lines
--- tools/kwboot.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)tools/kwboot.c +31
-0@@ -1251,6 +1251,37 @@ kwboot_hdr_csum8(const void *hdr)return csum; } +static uint32_t * +kwboot_img_csum32_ptr (void *img) +{ +struct main_hdr_v1 *hdr = img; +uint32_t datasz; + + datasz =le32_to_cpu (hdr->blocksize) -sizeof (uint32_t ); + +return img +le32_to_cpu (hdr->srcaddr) + datasz; +} + +static uint32_t +kwboot_img_csum32 (const void *img) +{ +const struct main_hdr_v1 *hdr = img; +uint32_t datasz, csum =0 ; +const uint32_t *data; + + datasz =le32_to_cpu (hdr->blocksize) -sizeof (csum); +if (datasz %sizeof (uint32_t )) +return 0 ; + + data = img +le32_to_cpu (hdr->srcaddr); +while (datasz >0 ) { + csum +=le32_to_cpu (*data++); + datasz -=4 ; + } + +return cpu_to_le32 (csum); +} +static int kwboot_img_is_secure (void *img) {
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1501
Quoted 9 lines
tools/kwboot.c +3
-0@@ -1462,6 +1493,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) *size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize)) goto err; +if (kwboot_img_csum32 (img) != *kwboot_img_csum32_ptr (img)) + goto err; + is_secure =kwboot_img_is_secure (img);if (hdr->blockid !=IBR_HDR_UART_ID ) {
Viele Grüße,
Stefan
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]
PATCH 5/13 tools: kwboot: Inject baudrate change back code after data part
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Some vendor U-Boot kwbimage binaries (e.g. those for A375) have load address set to zero. Therefore it is not possible to inject code which changes baudrate back to 115200 Bd before the data part.
So instead inject it after the data part and change kwbimage execution address to that offset. Also store original execution address into baudrate change code, so after it changes baudrate back to 115200 Bd, it can jump to orignal address.
--- tools/kwboot.c | 72 ++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 41 deletions(-)
tools/kwboot.c +31 -41
@@ -1295,34 +1295,22 @@ kwboot_img_is_secure(void *img) }static void * -kwboot_img_grow_data_left (void *img,size_t *size,size_t grow) +kwboot_img_grow_data_right (void *img,size_t *size,size_t grow) { -uint32_t hdrsz, datasz, srcaddr;struct main_hdr_v1 *hdr = img; -uint8_t *data; - - srcaddr =le32_to_cpu (hdr->srcaddr); - - hdrsz =kwbheader_size (hdr); - data = (uint8_t *)img + srcaddr; - datasz = *size - srcaddr; - -/* only move data if there is not enough space */ -if (hdrsz + grow > srcaddr) { -size_t need = hdrsz + grow - srcaddr; - -/* move data by enough bytes */ -memmove (data + need, data, datasz); - *size += need; - srcaddr += need; - } +void *result; - srcaddr -= grow; - hdr->srcaddr =cpu_to_le32 (srcaddr); - hdr->destaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) - grow); +/* +* 32-bit checksum comes after end of image code, so we will be putting +* new code there. So we get this pointer and then increase data size +* (since increasing data size changes kwboot_img_csum32_ptr() return +* value). +*/ + result =kwboot_img_csum32_ptr (img); hdr->blocksize =cpu_to_le32 (le32_to_cpu (hdr->blocksize) + grow); + *size += grow; -return (uint8_t *)img + srcaddr; +return result; } static void
@@ -1400,14 +1388,20 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) }static void -_copy_baudrate_change_code (struct main_hdr_v1 *hdr,void *dst,int pre, -int old_baud,int new_baud) +_inject_baudrate_change_code (void *img,size_t *size,int pre, +int old_baud,int new_baud) { -size_t codesz =sizeof (kwboot_baud_code); -uint8_t *code = dst; +uint32_t codesz =sizeof (kwboot_baud_code); +struct main_hdr_v1 *hdr = img; +uint8_t *code;if (pre) { -size_t presz =sizeof (kwboot_pre_baud_code); +uint32_t presz =sizeof (kwboot_pre_baud_code); +uint32_t orig_datasz; + + orig_datasz =le32_to_cpu (hdr->blocksize) -sizeof (uint32_t ); + + code =kwboot_img_grow_data_right (img, size, presz + codesz);/* * We need to prepend code that loads lr register with original
@@ -1421,9 +1415,12 @@ _copy_baudrate_change_code(struct main_hdr_v1 *hdr, void *dst, int pre,memcpy (code, kwboot_pre_baud_code, presz); *(uint32_t *)code = hdr->execaddr; - hdr->execaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) +4 ); + hdr->execaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) + + orig_datasz +4 ); code += presz; + }else { + code =kwboot_add_bin_ohdr_v1 (img, size, codesz); }memcpy (code, kwboot_baud_code, codesz -8 );
@@ -1516,9 +1513,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (baudrate) { -uint32_t codesz =sizeof (kwboot_baud_code); -void *code; -if (image_ver ==0 ) {fprintf (stderr,"Cannot inject code for changing baudrate into v0 image header\n" );
@@ -1539,20 +1533,16 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)*/ kwboot_printv ("Injecting binary header code for changing baudrate to %d Bd\n" , baudrate); - - code =kwboot_add_bin_ohdr_v1 (img, size, codesz); -_copy_baudrate_change_code (hdr, code,0 ,115200 , baudrate); +_inject_baudrate_change_code (img, size,0 ,115200 , baudrate);/* * Now inject code that changes the baudrate back to 115200 Bd. -* This code is prepended to the data part of the image, so it -* is executed before U-Boot proper. +* This code is appended after the data part of the image, and +* execaddr is changed so that it is executed before U-Boot +* proper. */ kwboot_printv ("Injecting code for changing baudrate back\n" ); - - codesz +=sizeof (kwboot_pre_baud_code); - code =kwboot_img_grow_data_left (img, size, codesz); -_copy_baudrate_change_code (hdr, code,1 , baudrate,115200 ); +_inject_baudrate_change_code (img, size,1 , baudrate,115200 );/* recompute header size */ hdrsz =kwbheader_size (hdr);
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 05/13] tools: kwboot: Inject baudrate change back code after data part
Quoted 6 lines · Marek Behún
From: Pali Rohár <[email protected]>
Some vendor U-Boot kwbimage binaries (e.g. those for A375) have load address set to zero. Therefore it is not possible to inject code which changes baudrate back to 115200 Bd before the data part.
Quoted 8 lines
So instead inject it after the data part and change kwbimage execution address to that offset. Also store original execution address into baudrate change code, so after it changes baudrate back to 115200 Bd, it can jump to orignal address.
Signed-off-by Pali Rohár <[email protected]>[ refactored ]Signed-off-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 121 lines
--- tools/kwboot.c | 72 ++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 41 deletions(-)tools/kwboot.c +30
-37@@ -1295,34 +1295,22 @@ kwboot_img_is_secure(void *img) }static void * -kwboot_img_grow_data_left (void *img,size_t *size,size_t grow) +kwboot_img_grow_data_right (void *img,size_t *size,size_t grow) { -uint32_t hdrsz, datasz, srcaddr;struct main_hdr_v1 *hdr = img; -uint8_t *data; - - srcaddr =le32_to_cpu (hdr->srcaddr); - - hdrsz =kwbheader_size (hdr); - data = (uint8_t *)img + srcaddr; - datasz = *size - srcaddr; - -/* only move data if there is not enough space */ -if (hdrsz + grow > srcaddr) { -size_t need = hdrsz + grow - srcaddr; - -/* move data by enough bytes */ -memmove (data + need, data, datasz); - *size += need; - srcaddr += need; - } +void *result; - srcaddr -= grow; - hdr->srcaddr =cpu_to_le32 (srcaddr); - hdr->destaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) - grow); +/* +* 32-bit checksum comes after end of image code, so we will be putting +* new code there. So we get this pointer and then increase data size +* (since increasing data size changes kwboot_img_csum32_ptr() return +* value). +*/ + result =kwboot_img_csum32_ptr (img); hdr->blocksize =cpu_to_le32 (le32_to_cpu (hdr->blocksize) + grow); + *size += grow; -return (uint8_t *)img + srcaddr; +return result; } static void@@ -1400,14 +1388,20 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) }static void -_copy_baudrate_change_code (struct main_hdr_v1 *hdr,void *dst,int pre, -int old_baud,int new_baud) +_inject_baudrate_change_code (void *img,size_t *size,int pre, +int old_baud,int new_baud) { -size_t codesz =sizeof (kwboot_baud_code); -uint8_t *code = dst; +uint32_t codesz =sizeof (kwboot_baud_code); +struct main_hdr_v1 *hdr = img; +uint8_t *code;if (pre) { -size_t presz =sizeof (kwboot_pre_baud_code); +uint32_t presz =sizeof (kwboot_pre_baud_code); +uint32_t orig_datasz; + + orig_datasz =le32_to_cpu (hdr->blocksize) -sizeof (uint32_t ); + + code =kwboot_img_grow_data_right (img, size, presz + codesz);/* * We need to prepend code that loads lr register with original @@ -1421,9 +1415,12 @@ _copy_baudrate_change_code(struct main_hdr_v1 *hdr, void *dst, int pre,memcpy (code, kwboot_pre_baud_code, presz); *(uint32_t *)code = hdr->execaddr; - hdr->execaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) +4 ); + hdr->execaddr =cpu_to_le32 (le32_to_cpu (hdr->destaddr) + + orig_datasz +4 ); code += presz; + }else { + code =kwboot_add_bin_ohdr_v1 (img, size, codesz); }memcpy (code, kwboot_baud_code, codesz -8 );@@ -1516,9 +1513,6 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (baudrate) { -uint32_t codesz =sizeof (kwboot_baud_code); -void *code; -if (image_ver ==0 ) {fprintf (stderr,"Cannot inject code for changing baudrate into v0 image header\n" );@@ -1539,20 +1533,16 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)*/ kwboot_printv ("Injecting binary header code for changing baudrate to %d Bd\n" , baudrate); - - code =kwboot_add_bin_ohdr_v1 (img, size, codesz); -_copy_baudrate_change_code (hdr, code,0 ,115200 , baudrate); +_inject_baudrate_change_code (img, size,0 ,115200 , baudrate);/* * Now inject code that changes the baudrate back to 115200 Bd. -* This code is prepended to the data part of the image, so it -* is executed before U-Boot proper. +* This code is appended after the data part of the image, and +* execaddr is changed so that it is executed before U-Boot +* proper.
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1548
Quoted 10 lines
tools/kwboot.c +1
-4*/ kwboot_printv ("Injecting code for changing baudrate back\n" ); - - codesz +=sizeof (kwboot_pre_baud_code); - code =kwboot_img_grow_data_left (img, size, codesz); -_copy_baudrate_change_code (hdr, code,1 , baudrate,115200 ); +_inject_baudrate_change_code (img, size,1 , baudrate,115200 );/* recompute header size */ hdrsz =kwbheader_size (hdr);
Viele Grüße,
Stefan
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]
PATCH 6/13 tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
If data part of image is modified, update 4-byte data checksum.
It looks like A385 BootROM does not verify this checksum for image loaded via UART, but we do not know if other BootROMs are also ignoring it. It is always better to provide correct checksum.
--- tools/kwboot.c | 3 +++ 1 file changed, 3 insertions(+)
tools/kwboot.c +3 -0
@@ -1544,6 +1544,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)kwboot_printv ("Injecting code for changing baudrate back\n" );_inject_baudrate_change_code (img, size,1 , baudrate,115200 ); +/* Update the 32-bit data checksum */ + *kwboot_img_csum32_ptr (img) =kwboot_img_csum32 (img); +/* recompute header size */ hdrsz =kwbheader_size (hdr); }
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 06/13] tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Quoted 11 lines · Marek Behún
From: Pali Rohár <[email protected]>
If data part of image is modified, update 4-byte data checksum.
It looks like A385 BootROM does not verify this checksum for image loaded via UART, but we do not know if other BootROMs are also ignoring it. It is always better to provide correct checksum.
Signed-off-by Pali Rohár <[email protected]>[ refactored ]Signed-off-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 10 lines
--- tools/kwboot.c | 3 +++ 1 file changed, 3 insertions(+)tools/kwboot.c +0
-0
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1552
Quoted 9 lines
tools/kwboot.c +3
-0@@ -1544,6 +1544,9 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)kwboot_printv ("Injecting code for changing baudrate back\n" );_inject_baudrate_change_code (img, size,1 , baudrate,115200 ); +/* Update the 32-bit data checksum */ + *kwboot_img_csum32_ptr (img) =kwboot_img_csum32 (img); +/* recompute header size */ hdrsz =kwbheader_size (hdr); }
Viele Grüße,
Stefan
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]
PATCH 7/13 tools: kwboot: Correctly set configuration of UART for BootROM messages
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
For kwbimage v1, tell BootROM to send BootROM messages to UART port number 0 (used also for UART booting) with default baudrate (which should be 115200) and do not touch UART MPP configuration.
--- tools/kwboot.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/kwboot.c +11 -0
@@ -1507,6 +1507,17 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (!is_secure) { +if (image_ver ==1 ) { +/* +* Tell BootROM to send BootROM messages to UART port +* number 0 (used also for UART booting) with default +* baudrate (which should be 115200) and do not touch +* UART MPP configuration. +*/ + hdr->options &= ~0x1F ; + hdr->options |=MAIN_HDR_V1_OPT_BAUD_DEFAULT ; + hdr->options |=0 <<3 ; + }if (image_ver ==0 ) ((struct main_hdr_v0 *)img)->nandeccmode =IBR_HDR_ECC_DISABLED ; hdr->nandpagesize =0 ;
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 07/13] tools: kwboot: Correctly set configuration of UART for BootROM messages
Quoted 8 lines · Marek Behún
From: Pali Rohár <[email protected]>
For kwbimage v1, tell BootROM to send BootROM messages to UART port number 0 (used also for UART booting) with default baudrate (which should be 115200) and do not touch UART MPP configuration.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 17 lines
--- tools/kwboot.c | 11 +++++++++++ 1 file changed, 11 insertions(+)tools/kwboot.c +4
-0@@ -1507,6 +1507,17 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (!is_secure) { +if (image_ver ==1 ) { +/* +* Tell BootROM to send BootROM messages to UART port +* number 0 (used also for UART booting) with default
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1523
Quoted 10 lines
tools/kwboot.c +7
-0+* baudrate (which should be 115200) and do not touch +* UART MPP configuration. +*/ + hdr->options &= ~0x1F ; + hdr->options |=MAIN_HDR_V1_OPT_BAUD_DEFAULT ; + hdr->options |=0 <<3 ; + }if (image_ver ==0 ) ((struct main_hdr_v0 *)img)->nandeccmode =IBR_HDR_ECC_DISABLED ; hdr->nandpagesize =0 ;
Viele Grüße,
Stefan
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]
PATCH 8/13 tools: kwboot: Show verbose message when waiting for baudrate change magic
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
It is hard to debug why kwboot is failing when the last message is 'Finishing transfer' and no additional output. So show verbose message when kwboot finished transfer and is waiting for baudrate change magic sequence.
--- tools/kwboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/kwboot.c +1 -1
@@ -1065,7 +1065,7 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)if (baudrate) {char buf[sizeof (kwb_baud_magic)]; -/* Wait 1s for baudrate change magic */ +kwboot_printv ("Waiting 1s for baudrate change magic\n" ); rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 );if (rc)return rc;
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 08/13] tools: kwboot: Show verbose message when waiting for baudrate change magic
Quoted 8 lines · Marek Behún
From: Pali Rohár <[email protected]>
It is hard to debug why kwboot is failing when the last message is 'Finishing transfer' and no additional output. So show verbose message when kwboot finished transfer and is waiting for baudrate change magic sequence.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 10 lines
--- tools/kwboot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/kwboot.c +0
-0
tools/kwboot.c kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate) · line 1071
Quoted 8 lines
tools/kwboot.c +1
-1@@ -1065,7 +1065,7 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)if (baudrate) {char buf[sizeof (kwb_baud_magic)]; -/* Wait 1s for baudrate change magic */ +kwboot_printv ("Waiting 1s for baudrate change magic\n" ); rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 );if (rc)return rc;
Viele Grüße,
Stefan
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]
PATCH 9/13 tools: kwboot: Simplify code for aligning image header
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Expression (hdrsz % KWBOOT_XM_BLKSZ) is non-zero therefore expression (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) is always less than value KWBOOT_XM_BLKSZ. So there is no need to add another modulo. Also rename variable offset to grow which better describes what is stored in this variable.
--- tools/kwboot.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
tools/kwboot.c +2 -3
@@ -1563,8 +1563,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (hdrsz %KWBOOT_XM_BLKSZ ) { -size_t offset = (KWBOOT_XM_BLKSZ - hdrsz %KWBOOT_XM_BLKSZ ) % -KWBOOT_XM_BLKSZ ; +size_t grow =KWBOOT_XM_BLKSZ - hdrsz %KWBOOT_XM_BLKSZ ;if (is_secure) {fprintf (stderr,"Cannot align image with secure header\n" );
@@ -1572,7 +1571,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }kwboot_printv ("Aligning image header to Xmodem block size\n" ); -kwboot_img_grow_hdr (img, size, offset); +kwboot_img_grow_hdr (img, size, grow); } hdr->checksum =kwboot_hdr_csum8 (hdr) - csum;
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 09/13] tools: kwboot: Simplify code for aligning image header
Quoted 10 lines · Marek Behún
From: Pali Rohár <[email protected]>
Expression (hdrsz %
KWBOOT_XM_BLKSZ) is non-zero therefore expression (KWBOOT_XM_BLKSZ- hdrsz %KWBOOT_XM_BLKSZ) is always less than valueKWBOOT_XM_BLKSZ. So there is no need to add another modulo. Also rename variableoffsettogrowwhich better describes what is stored in this variable.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 20 lines
--- tools/kwboot.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)tools/kwboot.c +1
-2@@ -1563,8 +1563,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }if (hdrsz %KWBOOT_XM_BLKSZ ) { -size_t offset = (KWBOOT_XM_BLKSZ - hdrsz %KWBOOT_XM_BLKSZ ) % -KWBOOT_XM_BLKSZ ; +size_t grow =KWBOOT_XM_BLKSZ - hdrsz %KWBOOT_XM_BLKSZ ;if (is_secure) {fprintf (stderr,"Cannot align image with secure header\n" );
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1577
Quoted 8 lines
tools/kwboot.c +1
-1@@ -1572,7 +1571,7 @@ kwboot_img_patch(void *img, size_t *size, int baudrate) }kwboot_printv ("Aligning image header to Xmodem block size\n" ); -kwboot_img_grow_hdr (img, size, offset); +kwboot_img_grow_hdr (img, size, grow); } hdr->checksum =kwboot_hdr_csum8 (hdr) - csum;
Viele Grüße,
Stefan
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]
PATCH 10/13 tools: kwboot: Do not modify kwbimage header before increasing its size
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
This ensures that kwboot_img_grow_hdr() function still sees valid kwbimage header.
--- tools/kwboot.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
tools/kwboot.c +6 -3
@@ -1352,17 +1352,18 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)uint32_t num_args;uint32_t offset;uint32_t ohdrsz; +uint8_t *prev_ext;if (hdr->ext &0x1 ) { for_each_opt_hdr_v1 (ohdr, img)if (opt_hdr_v1_next (ohdr) ==NULL )break ; - *opt_hdr_v1_ext (ohdr) |=1 ; - ohdr =opt_hdr_v1_next (ohdr); + prev_ext =opt_hdr_v1_ext (ohdr); + ohdr =_opt_hdr_v1_next (ohdr); }else { - hdr->ext |=1 ; ohdr = (void *)(hdr +1 ); + prev_ext = &hdr->ext; }/*
@@ -1377,6 +1378,8 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) ohdrsz =sizeof (*ohdr) +4 +4 * num_args + binsz +4 ;kwboot_img_grow_hdr (hdr, size, ohdrsz); + *prev_ext |=1 ; + ohdr->headertype =OPT_HDR_V1_BINARY_TYPE ; ohdr->headersz_msb = ohdrsz >>16 ; ohdr->headersz_lsb =cpu_to_le16 (ohdrsz &0xffff );
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 10/13] tools: kwboot: Do not modify kwbimage header before increasing its size
Quoted 7 lines · Marek Behún
From: Pali Rohár <[email protected]>
This ensures that
kwboot_img_grow_hdr()function still sees valid kwbimage header.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 32 lines
--- tools/kwboot.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)tools/kwboot.c +4
-3@@ -1352,17 +1352,18 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)uint32_t num_args;uint32_t offset;uint32_t ohdrsz; +uint8_t *prev_ext;if (hdr->ext &0x1 ) { for_each_opt_hdr_v1 (ohdr, img)if (opt_hdr_v1_next (ohdr) ==NULL )break ; - *opt_hdr_v1_ext (ohdr) |=1 ; - ohdr =opt_hdr_v1_next (ohdr); + prev_ext =opt_hdr_v1_ext (ohdr); + ohdr =_opt_hdr_v1_next (ohdr); }else { - hdr->ext |=1 ; ohdr = (void *)(hdr +1 ); + prev_ext = &hdr->ext; }/*
tools/kwboot.c kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) · line 1385
Quoted 8 lines
tools/kwboot.c +2
-0@@ -1377,6 +1378,8 @@ kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz) ohdrsz =sizeof (*ohdr) +4 +4 * num_args + binsz +4 ;kwboot_img_grow_hdr (hdr, size, ohdrsz); + *prev_ext |=1 ; + ohdr->headertype =OPT_HDR_V1_BINARY_TYPE ; ohdr->headersz_msb = ohdrsz >>16 ; ohdr->headersz_lsb =cpu_to_le16 (ohdrsz &0xffff );
Viele Grüße,
Stefan
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]
PATCH 11/13 tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Size of the header stored in kwbimage may be larger than real used size in the kwbimage header. If there is unused space in kwbimage header then use it for growing it. So update code to calculate used space of kwbimage header.
--- tools/kwboot.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
tools/kwboot.c +14 -3
@@ -1318,11 +1318,20 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow) {uint32_t hdrsz, datasz, srcaddr;struct main_hdr_v1 *hdr = img; +struct opt_hdr_v1 *ohdr;uint8_t *data; srcaddr =le32_to_cpu (hdr->srcaddr); - hdrsz =kwbheader_size (img); +/* calculate real used space in kwbimage header */ +if (kwbimage_version (img) ==0 ) { + hdrsz =kwbheader_size (img); + }else { + hdrsz =sizeof (*hdr); +for_each_opt_hdr_v1 (ohdr, hdr) + hdrsz += opt_hdr_v1_size(ohdr); + } + data = (uint8_t *)img + srcaddr; datasz = *size - srcaddr;
@@ -1339,8 +1348,10 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)if (kwbimage_version (img) ==1 ) { hdrsz += grow; - hdr->headersz_msb = hdrsz >>16 ; - hdr->headersz_lsb =cpu_to_le16 (hdrsz &0xffff ); +if (hdrsz >kwbheader_size (img)) { + hdr->headersz_msb = hdrsz >>16 ; + hdr->headersz_lsb =cpu_to_le16 (hdrsz &0xffff ); + } } }
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 11/13] tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()
Quoted 9 lines · Marek Behún
From: Pali Rohár <[email protected]>
Size of the header stored in kwbimage may be larger than real used size in the kwbimage header. If there is unused space in kwbimage header then use it for growing it. So update code to calculate used space of kwbimage header.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 34 lines
--- tools/kwboot.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)tools/kwboot.c +10
-1@@ -1318,11 +1318,20 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow) {uint32_t hdrsz, datasz, srcaddr;struct main_hdr_v1 *hdr = img; +struct opt_hdr_v1 *ohdr;uint8_t *data; srcaddr =le32_to_cpu (hdr->srcaddr); - hdrsz =kwbheader_size (img); +/* calculate real used space in kwbimage header */ +if (kwbimage_version (img) ==0 ) { + hdrsz =kwbheader_size (img); + }else { + hdrsz =sizeof (*hdr); +for_each_opt_hdr_v1 (ohdr, hdr) + hdrsz += opt_hdr_v1_size(ohdr); + } + data = (uint8_t *)img + srcaddr; datasz = *size - srcaddr;@@ -1339,8 +1348,10 @@ kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)if (kwbimage_version (img) ==1 ) {
tools/kwboot.c kwboot_img_grow_hdr(void *img, size_t *size, size_t grow) · line 1357
Quoted 10 lines
tools/kwboot.c +4
-2hdrsz += grow; - hdr->headersz_msb = hdrsz >>16 ; - hdr->headersz_lsb =cpu_to_le16 (hdrsz &0xffff ); +if (hdrsz >kwbheader_size (img)) { + hdr->headersz_msb = hdrsz >>16 ; + hdr->headersz_lsb =cpu_to_le16 (hdrsz &0xffff ); + } } }
Viele Grüße,
Stefan
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]
PATCH 12/13 tools: kwboot: Change retry loop from decreasing to increasing
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
This patch does not change behavior of the code, just allows to implement new changes more easily.
--- tools/kwboot.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/kwboot.c +4 -4
@@ -925,7 +925,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, *done_print =0 ; - retries =16 ; + retries =0 ; do { rc = kwboot_tty_send(fd, block, sizeof(*block)); if (rc)
@@ -944,7 +944,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,if (!allow_non_xm && c !=ACK )kwboot_progress (-1 ,'+' ); - }while (c ==NAK && retries-- >0 ); + }while (c ==NAK && retries++ <16 );if (non_xm_print)kwboot_printv ("\n" );
@@ -973,7 +973,7 @@ kwboot_xm_finish(int fd)kwboot_printv ("Finishing transfer\n" ); - retries =16 ; + retries =0 ; do { rc = kwboot_tty_send_char(fd, EOT); if (rc)
@@ -982,7 +982,7 @@ kwboot_xm_finish(int fd) rc =kwboot_xm_recv_reply (fd, &c,0 ,NULL ,0 ,NULL );if (rc)return rc; - }while (c ==NAK && retries-- >0 ); + }while (c ==NAK && retries++ <16 );return _xm_reply_to_error (c); }
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 12/13] tools: kwboot: Change retry loop from decreasing to increasing
Quoted 7 lines · Marek Behún
From: Pali Rohár <[email protected]>
This patch does not change behavior of the code, just allows to implement new changes more easily.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 37 lines
--- tools/kwboot.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)tools/kwboot.c +3
-3@@ -925,7 +925,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, *done_print =0 ; - retries =16 ; + retries =0 ; do { rc = kwboot_tty_send(fd, block, sizeof(*block)); if (rc)@@ -944,7 +944,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,if (!allow_non_xm && c !=ACK )kwboot_progress (-1 ,'+' ); - }while (c ==NAK && retries-- >0 ); + }while (c ==NAK && retries++ <16 );if (non_xm_print)kwboot_printv ("\n" );@@ -973,7 +973,7 @@ kwboot_xm_finish(int fd)kwboot_printv ("Finishing transfer\n" ); - retries =16 ; + retries =0 ; do { rc = kwboot_tty_send_char(fd, EOT); if (rc)
tools/kwboot.c kwboot_xm_finish(int fd) · line 988
Quoted 8 lines
tools/kwboot.c +1
-1@@ -982,7 +982,7 @@ kwboot_xm_finish(int fd) rc =kwboot_xm_recv_reply (fd, &c,0 ,NULL ,0 ,NULL );if (rc)return rc; - }while (c ==NAK && retries-- >0 ); + }while (c ==NAK && retries++ <16 );return _xm_reply_to_error (c); }
Viele Grüße,
Stefan
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]
PATCH 13/13 tools: kwboot: Resend first 3 xmodem retry packets immediately
In reply to Marek BehúnFrom: Pali Rohár <[email protected]>
Currently when kwboot receive some garbage reply which does not understand, it waits 1s before it tries to resend packet again.
The most common error on UART is that receiver sees some bit flipped which results in invalid reply.
This behavior slows down xmodem transfer over UART as basically on every error kwboot is waiting one second.
To fix this, try to resend xmodem packet for first 3 attempts immediately without any delay. If broken reply is received also after the 3 attempts, continue retrying with 1s delay like it was before.
--- tools/kwboot.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/kwboot.c +10 -3
@@ -851,7 +851,8 @@ kwboot_baud_magic_handle(int fd, char c, int baudrate) }static int -kwboot_xm_recv_reply (int fd,char *c,int allow_non_xm,int *non_xm_print, +kwboot_xm_recv_reply (int fd,char *c,int nak_on_non_xm, +int allow_non_xm,int *non_xm_print,int baudrate,int *baud_changed) {int timeout = allow_non_xm ?KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;
@@ -904,6 +905,10 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print, *non_xm_print =1 ; } }else { +if (nak_on_non_xm) { + *c =NAK ; +break ; + } timeout = recv_until -_now ();if (timeout <0 ) { errno =ETIMEDOUT ;
@@ -937,7 +942,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, *done_print =1 ; } - rc =kwboot_xm_recv_reply (fd, &c, allow_non_xm, &non_xm_print, + rc =kwboot_xm_recv_reply (fd, &c, retries <3 , + allow_non_xm, &non_xm_print, baudrate, &baud_changed);if (rc) goto can;
@@ -979,7 +985,8 @@ kwboot_xm_finish(int fd)if (rc)return rc; - rc =kwboot_xm_recv_reply (fd, &c,0 ,NULL ,0 ,NULL ); + rc =kwboot_xm_recv_reply (fd, &c, retries <3 , +0 ,NULL ,0 ,NULL );if (rc)return rc; }while (c ==NAK && retries++ <16 );
Signature · 1 line
2.32.0
Re: [PATCH u-boot-marvell 13/13] tools: kwboot: Resend first 3 xmodem retry packets immediately
Quoted 11 lines · Marek Behún
From: Pali Rohár <[email protected]>
Currently when kwboot receive some garbage reply which does not understand, it waits 1s before it tries to resend packet again.
The most common error on UART is that receiver sees some bit flipped which results in invalid reply.
This behavior slows down xmodem transfer over UART as basically on every error kwboot is waiting one second.
Quoted 6 lines
To fix this, try to resend xmodem packet for first 3 attempts immediately without any delay. If broken reply is received also after the 3 attempts, continue retrying with 1s delay like it was before.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Marek Behún <[email protected]>
Thanks,
Stefan
Quoted 41 lines
--- tools/kwboot.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)tools/kwboot.c +8
-2@@ -851,7 +851,8 @@ kwboot_baud_magic_handle(int fd, char c, int baudrate) }static int -kwboot_xm_recv_reply (int fd,char *c,int allow_non_xm,int *non_xm_print, +kwboot_xm_recv_reply (int fd,char *c,int nak_on_non_xm, +int allow_non_xm,int *non_xm_print,int baudrate,int *baud_changed) {int timeout = allow_non_xm ?KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;@@ -904,6 +905,10 @@ kwboot_xm_recv_reply(int fd, char *c, int allow_non_xm, int *non_xm_print, *non_xm_print =1 ; } }else { +if (nak_on_non_xm) { + *c =NAK ; +break ; + } timeout = recv_until -_now ();if (timeout <0 ) { errno =ETIMEDOUT ;@@ -937,7 +942,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, *done_print =1 ; } - rc =kwboot_xm_recv_reply (fd, &c, allow_non_xm, &non_xm_print, + rc =kwboot_xm_recv_reply (fd, &c, retries <3 , + allow_non_xm, &non_xm_print, baudrate, &baud_changed);if (rc) goto can;
tools/kwboot.c kwboot_xm_finish(int fd) · line 992
Quoted 9 lines
tools/kwboot.c +2
-1@@ -979,7 +985,8 @@ kwboot_xm_finish(int fd)if (rc)return rc; - rc =kwboot_xm_recv_reply (fd, &c,0 ,NULL ,0 ,NULL ); + rc =kwboot_xm_recv_reply (fd, &c, retries <3 , +0 ,NULL ,0 ,NULL );if (rc)return rc; }while (c ==NAK && retries++ <16 );
Viele Grüße,
Stefan
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]
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1
I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Any idea what's missing here?
Thanks,
Stefan
Quoted 30 lines
The main improvement is in patch 5, which changes where we inject the code for changing baudrate back to 115200 Baud after fast upload. Instead of injecting it before the main data image, we now inject it after.
This is because there are some kwb images that upload at address 0, and injecting the code before that doesn't work, since there is no RAM mapped at
0xfffff000.Marek & Pali
Pali Rohár (13):
tools: kwboot: Initialize rfds to zero
tools: kwboot: Fix initialization of tty device
tools: kwboot: Reserve enough space for patching kwbimage in memory
tools: kwboot: Validate 4-byte image data checksum
tools: kwboot: Inject baudrate change back code after data part
tools: kwboot: Recalculate 4-byte data checksum after injecting
baudrate code
tools: kwboot: Correctly set configuration of UART for BootROM
messages
tools: kwboot: Show verbose message when waiting for baudrate change
magic
tools: kwboot: Simplify code for aligning image header
tools: kwboot: Do not modify kwbimage header before increasing its
size
tools: kwboot: Calculate real used space in kwbimage header when
callingkwboot_img_grow_hdr()
tools: kwboot: Change retry loop from decreasing to increasing
tools: kwboot: Resend first 3 xmodem retry packets immediately
Quoted 3 lines
tools/kwboot.c | 178 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 120 insertions(+), 58 deletions(-)
Viele Grüße,
Stefan
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 40 lines · On Monday 25 October 2021 16:39:44 Stefan Roese wrote:
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Quoted 1 line
Any idea what's missing here?
Hello! I'm using also this patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Quoted 45 lines
Thanks,
StefanQuoted 30 lines
The main improvement is in patch 5, which changes where we inject the code for changing baudrate back to 115200 Baud after fast upload. Instead of injecting it before the main data image, we now inject it after.
This is because there are some kwb images that upload at address 0, and injecting the code before that doesn't work, since there is no RAM mapped at
0xfffff000.Marek & Pali
Pali Rohár (13):
tools: kwboot: Initialize rfds to zero
tools: kwboot: Fix initialization of tty device
tools: kwboot: Reserve enough space for patching kwbimage in memory
tools: kwboot: Validate 4-byte image data checksum
tools: kwboot: Inject baudrate change back code after data part
tools: kwboot: Recalculate 4-byte data checksum after injecting
baudrate code
tools: kwboot: Correctly set configuration of UART for BootROM
messages
tools: kwboot: Show verbose message when waiting for baudrate change
magic
tools: kwboot: Simplify code for aligning image header
tools: kwboot: Do not modify kwbimage header before increasing its
size
tools: kwboot: Calculate real used space in kwbimage header when
callingkwboot_img_grow_hdr()
tools: kwboot: Change retry loop from decreasing to increasing
tools: kwboot: Resend first 3 xmodem retry packets immediatelyQuoted 3 lines
tools/kwboot.c | 178 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 120 insertions(+), 58 deletions(-)Viele Grüße,
StefanSignature · 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]
Hi Pali,
Quoted 41 lines · Pali Rohár
Quoted 40 lines · On Monday 25 October 2021 16:39:44 Stefan Roese wrote:
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Quoted 4 lines
Quoted 1 line
Any idea what's missing here?
Hello! I'm using also this patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Ah, yes. That does the trick. Now all patches apply clean. Thanks.
Testing with all these patches on my AXP target does show, it still does not work with baudrate > 115k:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ ./tools/kwboot -B 230400 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd
Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [....
]
Done
U-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 25 2021 - 17:10:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address 0xffff0aa0)...
Changing baudrate to 230400 Bd
Baudrate was not changed
xmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
Not changing the baudrate still works. Any idea what I should test? Or do you have further changes in the queue that I should wait upon?
Thanks,
Stefan
Quoted 98 lines · On Monday 25 October 2021 17:15:14 Stefan Roese wrote:
Hi Pali,
Quoted 41 lines · Pali Rohár
Quoted 40 lines · On Monday 25 October 2021 16:39:44 Stefan Roese wrote:
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".Quoted 4 lines
Quoted 1 line
Any idea what's missing here?
Hello! I'm using also this patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Ah, yes. That does the trick. Now all patches apply clean. Thanks.
Testing with all these patches on my AXP target does show, it still does not work with baudrate > 115k:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 25 2021 - 17:10:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Baudrate was not changed
Quoted 6 lines
xmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$Not changing the baudrate still works. Any idea what I should test? Or do you have further changes in the queue that I should wait upon?
Could you try to boot with baudrate 115201? This value would trigger to use baudrate change code and because it is too close to standard 115200 there would be no real change.
And what is the output of following command immediately after kwboot?
stty -F /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0
Also, could try to catch whole strace log and send it to me?
Quoted 103 lines · Pali Rohár
Quoted 102 lines · On Monday 25 October 2021 17:15:14 Stefan Roese wrote:
Hi Pali,
Quoted 41 lines · Pali Rohár
Quoted 40 lines · On Monday 25 October 2021 16:39:44 Stefan Roese wrote:
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".Quoted 4 lines
Quoted 1 line
Any idea what's missing here?
Hello! I'm using also this patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Ah, yes. That does the trick. Now all patches apply clean. Thanks.
Testing with all these patches on my AXP target does show, it still does not work with baudrate > 115k:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 25 2021 - 17:10:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
Quoted 6 lines
Quoted 2 lines
Not changing the baudrate still works. Any idea what I should test? Or do you have further changes in the queue that I should wait upon?
Could you try to boot with baudrate 115201? This value would trigger to use baudrate change code and because it is too close to standard 115200 there would be no real change.
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ ./tools/kwboot -B 115201 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd
Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [....
]
Done
U-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address 0xffff0aa0)...
Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]
1 %
[......................................................................]
...
97 %
[......................................................................]
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
Changing baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flash
So the CPU has run through a reset here.
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0
Changing baudrate to 230400 Bd
Baudrate was not changed
xmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 speed 230400 baud; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
Thanks,
Stefan
Quoted 104 lines · On Tuesday 26 October 2021 10:45:09 Stefan Roese wrote:
Quoted 103 lines · Pali Rohár
Quoted 102 lines · On Monday 25 October 2021 17:15:14 Stefan Roese wrote:
Hi Pali,
Quoted 41 lines · Pali Rohár
Quoted 40 lines · On Monday 25 October 2021 16:39:44 Stefan Roese wrote:
Hi Marek,
Quoted 6 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1I'm checking right now and have applied the 3 NAND patches on current master. But this patchset fails at this one:
tools: kwboot: Do not modify kwbimage header before increasing its size
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ git am -3 ~/tmp/kwboot2/*
Applying: tools: kwboot: Initialize rfds to zero
Applying: tools: kwboot: Fix initialization of tty device
Applying: tools: kwboot: Reserve enough space for patching kwbimage in memory
Applying: tools: kwboot: Validate 4-byte image data checksum
Applying: tools: kwboot: Inject baudrate change back code after data part
Applying: tools: kwboot: Recalculate 4-byte data checksum after injecting baudrate code
Applying: tools: kwboot: Correctly set configuration of UART for BootROM messages
Applying: tools: kwboot: Show verbose message when waiting for baudrate change magic
Applying: tools: kwboot: Simplify code for aligning image header
Applying: tools: kwboot: Do not modify kwbimage header before increasing its size
error: sha1 information is lacking or useless (tools/kwboot.c).
error: could not build fake ancestor
Patch failed at 0010 tools: kwboot: Do not modify kwbimage header before increasing its size
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".Quoted 4 lines
Quoted 1 line
Any idea what's missing here?
Hello! I'm using also this patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/Ah, yes. That does the trick. Now all patches apply clean. Thanks.
Testing with all these patches on my AXP target does show, it still does not work with baudrate > 115k:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 25 2021 - 17:10:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Not changing the baudrate still works. Any idea what I should test? Or do you have further changes in the queue that I should wait upon?
Could you try to boot with baudrate 115201? This value would trigger to use baudrate change code and because it is too close to standard 115200 there would be no real change.
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +2 -5
@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {
@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {
Quoted 59 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]
1 %
[......................................................................]
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
Quoted 7 lines
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flashSo the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0
Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;
... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 10 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echokeQuoted 2 lines
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Quoted 2 lines
Thanks,
Stefan
On 26.10.21 11:06, Pali Rohár wrote:
<snip>
Quoted 22 lines
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +0
-5@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {
tools/kwboot.c kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, · line 931
Quoted 8 lines
tools/kwboot.c +2
-0@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {
This definitely helps (a bit). Now I get this:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ ./tools/kwboot -B 230400 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd
Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [....
]
Done
U-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 12:48:11 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address 0xffff0aa0)...
Changing baudrate to 230400 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]
...
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
BTW: The baudrate change does not seem to work or have any effect on the image download speed. Comparing 230400 and 921600 baud speeds, I can spot no real time difference here:
230400 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time ./tools/kwboot -B 230400 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd
...
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
[2]+ Done emacs tools/kwboot.c
real 1m27,279s user 0m2,313s sys 0m0,337s
921600 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time ./tools/kwboot -B 921600 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 921600 Bd
...
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
real 1m27,839s user 0m0,224s sys 0m0,194s
Any idea why this is the case?
Quoted 65 lines
Quoted 65 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]
1 %
[......................................................................]
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flash
Quoted 5 lines
Quoted 1 line
So the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
AXP stands for Armada XP, which is ARM v7 AFAIK.
Quoted 2 lines
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
I'm currently using a kernel.org toolchain:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ set | grep CROSS CROSS_COMPILE=/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ /opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc --version arm-linux-gnueabi-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Here my commands to generate the U-Boot binary:
make mrproper
make theadorable_debug_defconfig
make -s -j20
Quoted 26 lines
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 7 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Okay, will follow in the next privatze mail.
Thanks,
Stefan
Quoted 25 lines · On Tuesday 26 October 2021 13:09:42 Stefan Roese wrote:
On 26.10.21 11:06, Pali Rohár wrote:
<snip>
Quoted 21 lines
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +0
-5@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,
Quoted 8 lines
tools/kwboot.c kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, · line 929
Quoted 6 lines
tools/kwboot.c +2
-0char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {This definitely helps (a bit). Now I get this:
Perfect! So this fixes issue with retransmission of the last header packet.
But there is still issue with starting main U-Boot binary.
Quoted 94 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 12:48:11 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outBTW: The baudrate change does not seem to work or have any effect on the image download speed. Comparing 230400 and 921600 baud speeds, I can spot no real time difference here:
230400 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
[2]+ Done emacstools/kwboot.creal 1m27,279s user 0m2,313s sys 0m0,337s921600 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 921600 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 921600 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
Quoted 5 lines
real 1m27,839s user 0m0,224s sys 0m0,194sAny idea why this is the case?
UARTs at both sides must be configured to 921600 speed, otherwise they would not be able to communicate.
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.
Maybe kernel is not filling next byte into USB-UART hw queue? Or USB-UART cannot send more bytes faster and inserts those long idle pauses?
Could you try following diff which disables calling tcdrain() for xmodem packets, to remove any waits between individual bytes?
tools/kwboot.c +8 -5
@@ -404,7 +404,7 @@ out: }static int -kwboot_tty_send (int fd,const void *buf,size_t len) +kwboot_tty_send (int fd,const void *buf,size_t len,int nodrain) {if (!buf)return 0 ;
@@ -412,13 +412,16 @@ kwboot_tty_send(int fd, const void *buf, size_t len)if (kwboot_write (fd, buf, len) <0 )return -1 ; +if (nodrain) +return 0 ; +return tcdrain (fd); }static int kwboot_tty_send_char (int fd,unsigned char c) { -return kwboot_tty_send (fd, &c,1 ); +return kwboot_tty_send (fd, &c,1 ,0 ); } static speed_t
@@ -705,7 +708,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;
@@ -737,7 +740,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;
@@ -929,7 +932,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, retries =0 ; do { - rc = kwboot_tty_send(fd, block, sizeof(*block)); + rc = kwboot_tty_send(fd, block, sizeof(*block), 1); if (rc) return rc;
If it is kernel who does not fill next bytes into hw UART queue as it waits for tcdrain then above patch should fix it.
Or if you have other USB-UART cables, try another. I have good experience with pl2303-based.
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]
1 %
[......................................................................]
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flash
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
So the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
AXP stands for Armada XP, which is ARM v7 AFAIK.
I remember that older Marvell Armada SoCs used custom designed ARM cores, so there could be some differences what is supported by licensed ARM core and custom ARM core.
Anyway, as changing baudrate after execution of SPL is working fine, it should mean that there is no undefined/unsupported instruction.
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Quoted 15 lines
Quoted 2 lines
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
I'm currently using a kernel.org toolchain:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ set | grep CROSS CROSS_COMPILE=/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi- [stefan@ryzen u-boot-marvell (kwboot-test1)]$
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc--version
arm-linux-gnueabi-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Quoted 5 lines
Here my commands to generate the U-Boot binary:
make mrproper
maketheadorable_debug_defconfig
make -s -j20
Ok.
Quoted 26 lines
Quoted 26 lines
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 7 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Okay, will follow in the next privatze mail.
Received. I have looked at it. And there are two interesting parts:
1) Both parts of transfer (header at default speed 115200 and main at high speed 921600) were transferred without any error, except for the error indication of the last header packet. Error indication was sent after the execution of header itself (SPL and baudrate change), it means that there was no error and bootrom did not sent any error indication. kwboot did retransmission of this one packet and it succeeded (thanks to that fixup which I have sent).
So this error must have been just fluctuation on UART and probably caused by changing UART speed. I guess that your USB-UART chip needs more time to stabilize new speed and so USB-UART receiver lost/damaged reply byte sent by bootrom.
Maybe you could increase delay in arm baudrate change code, so CPU waits longer time before it returns to bootrom?
Replacing code in kwboot_baud_code[] array:
/* ; Sleep 1ms ~~ 600000 cycles at 1200 MHz */ /* ; r1 = 600000 */ 0x9f, 0x1d, 0xa0, 0xe3, /* mov r1, #0x27c0 */ 0x09, 0x10, 0x40, 0xe3, /* movt r1, #0x0009 */
by:
/* ; Sleep 10ms ~~ 6M cycles at 1200 MHz */ /* ; r1 = 6000000 */ 0x80, 0x1d, 0x08, 0xe3, /* mov r1, #0x8d80 */ 0x5b, 0x10, 0x40, 0xe3, /* movt r1, #0x005b */
should do it.
2) Transfer was successful (EOT was ACKed) but there is absolutely no output on UART after the transfer. Which should indicate that bootrom should have started execution of the main image, but something crashed and board reset... Maybe it is really due to usage of stack...
Quoted 2 lines
Thanks,
Stefan
Quoted 6 lines · On Tue, 26 Oct 2021 14:40:48 +0200 Pali Rohár <[email protected]> wrote:
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.
Yes, my FT232RL USB-UART converters do not send at higher speeds, although they report baudrate change.
I do not really know what is going on. Maybe the ftdi-sio driver needs to be looked at. (It definitely needs to be looked at, because of other things. Last I looked into it the baudrate change code seemed okay.)
Using pl2303 converter works like a charm.
Note that I have another FT232RL converter for MOX, which works at 1.8V, and on MOX higher speeds work correctly.
Maybe some of the FT232RL chips are those fake ones?
Stefan, could you check in a different way whether your converter can transfer at higher speed? For example with another device, or in U-Boot via kermit / ymodem, or whatnot.
Marek
Quoted 17 lines · Marek Behún
Quoted 6 lines · On Tue, 26 Oct 2021 14:40:48 +0200 Pali Rohár <[email protected]> wrote:
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.Yes, my FT232RL USB-UART converters do not send at higher speeds, although they report baudrate change.
I do not really know what is going on. Maybe the ftdi-sio driver needs to be looked at. (It definitely needs to be looked at, because of other things. Last I looked into it the baudrate change code seemed okay.)
Quoted 6 lines
Using pl2303 converter works like a charm.
Note that I have another FT232RL converter for MOX, which works at 1.8V, and on MOX higher speeds work correctly.
Maybe some of the FT232RL chips are those fake ones?
Maybe. Unfortunately, on this Armada XP board this FTDI chip is soldered on the target, so I can't easily switch adapters.
Quoted 3 lines
Stefan, could you check in a different way whether your converter can transfer at higher speed? For example with another device, or in U-Boot via kermit / ymodem, or whatnot.
Connecting with 230400 baud and booting into U-Boot etc shows this:
$ cu -s 230400 -l /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Connected. �������������▒�����`�▒3������▒�▒�▒�▒30�▒0����`f憞~�▒���������f�`
So it seems, that baudrate change seems to work fine with the chip.
Thanks,
Stefan
Quoted 134 lines · Pali Rohár
Quoted 25 lines · On Tuesday 26 October 2021 13:09:42 Stefan Roese wrote:
On 26.10.21 11:06, Pali Rohár wrote:
<snip>
Quoted 21 lines
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +0
-5@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,Quoted 8 lines
tools/kwboot.c kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, · line 929
Quoted 6 lines
tools/kwboot.c +2
-0char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {This definitely helps (a bit). Now I get this:
Perfect! So this fixes issue with retransmission of the last header packet.
But there is still issue with starting main U-Boot binary.
Quoted 94 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 12:48:11 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outBTW: The baudrate change does not seem to work or have any effect on the image download speed. Comparing 230400 and 921600 baud speeds, I can spot no real time difference here:
230400 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
[2]+ Done emacstools/kwboot.creal 1m27,279s user 0m2,313s sys 0m0,337s921600 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 921600 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 921600 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
Quoted 8 lines
Quoted 5 lines
real 1m27,839s user 0m0,224s sys 0m0,194sAny idea why this is the case?
UARTs at both sides must be configured to 921600 speed, otherwise they would not be able to communicate.
I'm also surpised here.
Quoted 72 lines
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.Maybe kernel is not filling next byte into USB-UART hw queue? Or USB-UART cannot send more bytes faster and inserts those long idle pauses?
Could you try following diff which disables calling
tcdrain()for xmodem packets, to remove any waits between individual bytes?tools/kwboot.c +8
-5@@ -404,7 +404,7 @@ out: }static int -kwboot_tty_send (int fd,const void *buf,size_t len) +kwboot_tty_send (int fd,const void *buf,size_t len,int nodrain) {if (!buf)return 0 ;@@ -412,13 +412,16 @@ kwboot_tty_send(int fd, const void *buf, size_t len)if (kwboot_write (fd, buf, len) <0 )return -1 ; +if (nodrain) +return 0 ; +return tcdrain (fd); }static int kwboot_tty_send_char (int fd,unsigned char c) { -return kwboot_tty_send (fd, &c,1 ); +return kwboot_tty_send (fd, &c,1 ,0 ); } static speed_t@@ -705,7 +708,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -737,7 +740,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -929,7 +932,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, retries =0 ; do { - rc = kwboot_tty_send(fd, block, sizeof(*block)); + rc = kwboot_tty_send(fd, block, sizeof(*block), 1); if (rc) return rc;
Quoted 2 lines
If it is kernel who does not fill next bytes into hw UART queue as it waits for tcdrain then above patch should fix it.
Still no ciguar. Here the end of the log with "-B 921600":
97 %
[......................................................................]
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
Quoted 2 lines
Or if you have other USB-UART cables, try another. I have good experience with pl2303-based.
I have tons of USB-UART adapters / cables. But as mentioned in the other mail, I can't connect them, as the FTDI chip is soldered on the target.
Still it should work at least with 115201 baud, even if baudrate changing does not work. Right? So we have at least one other problem here AFAICT.
Quoted 80 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...0 %[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 % [......................................................................] 1 %[......................................................................]
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flashQuoted 7 lines
Quoted 5 lines
Quoted 1 line
So the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
AXP stands for Armada XP, which is ARM v7 AFAIK.
I remember that older Marvell Armada SoCs used custom designed ARM cores, so there could be some differences what is supported by licensed ARM core and custom ARM core.
Anyway, as changing baudrate after execution of SPL is working fine, it should mean that there is no undefined/unsupported instruction.
Quoted 7 lines
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Quoted 82 lines
Quoted 15 lines
Quoted 2 lines
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
I'm currently using a kernel.org toolchain:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ set | grep CROSS CROSS_COMPILE=/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi- [stefan@ryzen u-boot-marvell (kwboot-test1)]$
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc--version
arm-linux-gnueabi-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Quoted 5 lines
Here my commands to generate the U-Boot binary:
make mrproper
maketheadorable_debug_defconfig
make -s -j20Ok.
Quoted 26 lines
Quoted 26 lines
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 7 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echokeQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Okay, will follow in the next privatze mail.
Received. I have looked at it. And there are two interesting parts:
1) Both parts of transfer (header at default speed 115200 and main at high speed 921600) were transferred without any error, except for the error indication of the last header packet. Error indication was sent after the execution of header itself (SPL and baudrate change), it means that there was no error and bootrom did not sent any error indication. kwboot did retransmission of this one packet and it succeeded (thanks to that fixup which I have sent).
So this error must have been just fluctuation on UART and probably caused by changing UART speed. I guess that your USB-UART chip needs more time to stabilize new speed and so USB-UART receiver lost/damaged reply byte sent by bootrom.
Maybe you could increase delay in arm baudrate change code, so CPU waits longer time before it returns to bootrom?
Replacing code in kwboot_baud_code[] array:
/* ; Sleep 1ms ~~ 600000 cycles at 1200 MHz */ /* ; r1 = 600000 */ 0x9f, 0x1d, 0xa0, 0xe3, /* mov r1, #0x27c0 */ 0x09, 0x10, 0x40, 0xe3, /* movt r1, #0x0009 */
Quoted 8 lines
by:
/* ; Sleep 10ms ~~ 6M cycles at 1200 MHz */ /* ; r1 = 6000000 */ 0x80, 0x1d, 0x08, 0xe3, /* mov r1, #0x8d80 */ 0x5b, 0x10, 0x40, 0xe3, /* movt r1, #0x005b */should do it.
Still no change. Also not in the download speed AFAICT.
...
97 %
[......................................................................]
99 % [...........................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
Changing baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
BTW: There is a external watchdog on the target, which might be the root cause for the reset I'm seeing here. It kicks in at around 2-3 minutes after power-up AFAIR.
Quoted 4 lines
2) Transfer was successful (EOT was ACKed) but there is absolutely no output on UART after the transfer. Which should indicate that bootrom should have started execution of the main image, but something crashed and board reset... Maybe it is really due to usage of stack...
Yep.
Thanks,
Stefan
Quoted 210 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 134 lines · Pali Rohár
Quoted 25 lines · On Tuesday 26 October 2021 13:09:42 Stefan Roese wrote:
On 26.10.21 11:06, Pali Rohár wrote:
<snip>
Quoted 21 lines
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +0
-5@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,Quoted 8 lines
tools/kwboot.c kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, · line 929
Quoted 6 lines
tools/kwboot.c +2
-0char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {This definitely helps (a bit). Now I get this:
Perfect! So this fixes issue with retransmission of the last header packet.
But there is still issue with starting main U-Boot binary.
Quoted 94 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 12:48:11 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Sending boot image data (549892 bytes)...
0 %
[......................................................................]...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outBTW: The baudrate change does not seem to work or have any effect on the image download speed. Comparing 230400 and 921600 baud speeds, I can spot no real time difference here:
230400 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
[2]+ Done emacstools/kwboot.creal 1m27,279s user 0m2,313s sys 0m0,337s921600 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 921600 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 921600 Bd...
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outQuoted 8 lines
Quoted 5 lines
real 1m27,839s user 0m0,224s sys 0m0,194sAny idea why this is the case?
UARTs at both sides must be configured to 921600 speed, otherwise they would not be able to communicate.
I'm also surpised here.
Quoted 64 lines
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.Maybe kernel is not filling next byte into USB-UART hw queue? Or USB-UART cannot send more bytes faster and inserts those long idle pauses?
Could you try following diff which disables calling
tcdrain()for xmodem packets, to remove any waits between individual bytes?tools/kwboot.c +8
-5@@ -404,7 +404,7 @@ out: }static int -kwboot_tty_send (int fd,const void *buf,size_t len) +kwboot_tty_send (int fd,const void *buf,size_t len,int nodrain) {if (!buf)return 0 ;@@ -412,13 +412,16 @@ kwboot_tty_send(int fd, const void *buf, size_t len)if (kwboot_write (fd, buf, len) <0 )return -1 ; +if (nodrain) +return 0 ; +return tcdrain (fd); }static int kwboot_tty_send_char (int fd,unsigned char c) { -return kwboot_tty_send (fd, &c,1 ); +return kwboot_tty_send (fd, &c,1 ,0 ); } static speed_t@@ -705,7 +708,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -737,7 +740,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -929,7 +932,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, retries =0 ; do { - rc = kwboot_tty_send(fd, block, sizeof(*block)); + rc = kwboot_tty_send(fd, block, sizeof(*block), 1); if (rc) return rc;
Quoted 4 lines
Quoted 2 lines
If it is kernel who does not fill next bytes into hw UART queue as it waits for tcdrain then above patch should fix it.
Still no ciguar. Here the end of the log with "-B 921600":
So no change in total transfer time with above patch?
Quoted 9 lines
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
Quoted 6 lines
Quoted 2 lines
Or if you have other USB-UART cables, try another. I have good experience with pl2303-based.
I have tons of USB-UART adapters / cables. But as mentioned in the other mail, I can't connect them, as the FTDI chip is soldered on the target.
Understood.
Quoted 3 lines
Still it should work at least with 115201 baud, even if baudrate changing does not work. Right? So we have at least one other problem here AFAICT.
Baudrate change must work. Using 115201 baud could just show output from board/bootrom if CPU prematurely resets (which resets baudrate to default 115200).
Quoted 193 lines
Quoted 80 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...0 %[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 % [......................................................................] 1 %[......................................................................]
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flashQuoted 7 lines
Quoted 5 lines
Quoted 1 line
So the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
AXP stands for Armada XP, which is ARM v7 AFAIK.
I remember that older Marvell Armada SoCs used custom designed ARM cores, so there could be some differences what is supported by licensed ARM core and custom ARM core.
Anyway, as changing baudrate after execution of SPL is working fine, it should mean that there is no undefined/unsupported instruction.
Quoted 7 lines
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Quoted 82 lines
Quoted 15 lines
Quoted 2 lines
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
I'm currently using a kernel.org toolchain:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ set | grep CROSS CROSS_COMPILE=/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi- [stefan@ryzen u-boot-marvell (kwboot-test1)]$
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc--version
arm-linux-gnueabi-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Quoted 5 lines
Here my commands to generate the U-Boot binary:
make mrproper
maketheadorable_debug_defconfig
make -s -j20Ok.
Quoted 26 lines
Quoted 26 lines
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 7 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echokeQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Okay, will follow in the next privatze mail.
Received. I have looked at it. And there are two interesting parts:
1) Both parts of transfer (header at default speed 115200 and main at high speed 921600) were transferred without any error, except for the error indication of the last header packet. Error indication was sent after the execution of header itself (SPL and baudrate change), it means that there was no error and bootrom did not sent any error indication. kwboot did retransmission of this one packet and it succeeded (thanks to that fixup which I have sent).
So this error must have been just fluctuation on UART and probably caused by changing UART speed. I guess that your USB-UART chip needs more time to stabilize new speed and so USB-UART receiver lost/damaged reply byte sent by bootrom.
Maybe you could increase delay in arm baudrate change code, so CPU waits longer time before it returns to bootrom?
Replacing code in kwboot_baud_code[] array:
/* ; Sleep 1ms ~~ 600000 cycles at 1200 MHz */ /* ; r1 = 600000 */ 0x9f, 0x1d, 0xa0, 0xe3, /* mov r1, #0x27c0 */ 0x09, 0x10, 0x40, 0xe3, /* movt r1, #0x0009 */Quoted 8 lines
by:
/* ; Sleep 10ms ~~ 6M cycles at 1200 MHz */ /* ; r1 = 6000000 */ 0x80, 0x1d, 0x08, 0xe3, /* mov r1, #0x8d80 */ 0x5b, 0x10, 0x40, 0xe3, /* movt r1, #0x005b */should do it.
Still no change. Also not in the download speed AFAICT.
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
Quoted 7 lines
[Type Ctrl-\ + c to quit]
BootROM 1.20
BTW: There is a external watchdog on the target, which might be the root cause for the reset I'm seeing here. It kicks in at around 2-3 minutes after power-up AFAIR.
But there is no more "xmodem: Connection timed out" error.
When that "BootROM 1.20" message was printed? Immediately after the "Changing baudrate back to 115200 Bd"? Or it was e.g. minute later? I would like to know if board reset relates to watchdog or if it relates to baudrate change code.
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
Quoted 9 lines
Quoted 4 lines
2) Transfer was successful (EOT was ACKed) but there is absolutely no output on UART after the transfer. Which should indicate that bootrom should have started execution of the main image, but something crashed and board reset... Maybe it is really due to usage of stack...
Yep.
Thanks,
Stefan
Quoted 211 lines · Pali Rohár
Quoted 210 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 134 lines · Pali Rohár
Quoted 25 lines · On Tuesday 26 October 2021 13:09:42 Stefan Roese wrote:
On 26.10.21 11:06, Pali Rohár wrote:
<snip>
Quoted 21 lines
Now I found logical error in kwboot code which handles retransmission of the last header packet. State of "baudrate change" is cleared on every retransmission. Please apply following diff, so state variables are initialized only once.
tools/kwboot.c +0
-5@@ -859,11 +859,6 @@ kwboot_xm_recv_reply(int fd, char *c, int nak_on_non_xm,uint64_t recv_until =_now () + timeout;int rc; -if (non_xm_print) - *non_xm_print =0 ; -if (baud_changed) - *baud_changed =0 ; -while (1 ) { rc =kwboot_tty_recv (fd, c,1 , timeout);if (rc) {@@ -929,6 +924,8 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,Quoted 8 lines
tools/kwboot.c kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, · line 929
Quoted 6 lines
tools/kwboot.c +2
-0char c; *done_print =0 ; + non_xm_print =0 ; + baud_changed =0 ; retries =0 ; do {This definitely helps (a bit). Now I get this:
Perfect! So this fixes issue with retransmission of the last header packet.
But there is still issue with starting main U-Boot binary.
Quoted 94 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...0 %[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [.... ]
DoneU-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 12:48:11 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 230400 Bd
Sending boot image data (549892 bytes)...
0 %[......................................................................]
...
99 % [........................... ]Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outBTW: The baudrate change does not seem to work or have any effect on the image download speed. Comparing 230400 and 921600 baud speeds, I can spot no real time difference here:
230400 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 230400 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd...
99 % [........................... ]Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed out
[2]+ Done emacstools/kwboot.creal 1m27,279s user 0m2,313s sys 0m0,337s921600 baud:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ time./tools/kwboot-B 921600 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 921600 Bd...
99 % [........................... ]Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outQuoted 8 lines
Quoted 5 lines
real 1m27,839s user 0m0,224s sys 0m0,194sAny idea why this is the case?
UARTs at both sides must be configured to 921600 speed, otherwise they would not be able to communicate.
I'm also surpised here.
Quoted 64 lines
What is happening here? I do not know. But as Marek told me that observed same issue and replacing USB-UART cable by another decreased transfer time. So I think that issue is somewhere in USB-UART transmitter. My guess is that USB-UART transmitter send at 921600 speed:
start bit, 8 bits of data, stop bit and then loooong idle pause (logical one). After that sends another 10 bits.Maybe kernel is not filling next byte into USB-UART hw queue? Or USB-UART cannot send more bytes faster and inserts those long idle pauses?
Could you try following diff which disables calling
tcdrain()for xmodem packets, to remove any waits between individual bytes?tools/kwboot.c +8
-5@@ -404,7 +404,7 @@ out: }static int -kwboot_tty_send (int fd,const void *buf,size_t len) +kwboot_tty_send (int fd,const void *buf,size_t len,int nodrain) {if (!buf)return 0 ;@@ -412,13 +412,16 @@ kwboot_tty_send(int fd, const void *buf, size_t len)if (kwboot_write (fd, buf, len) <0 )return -1 ; +if (nodrain) +return 0 ; +return tcdrain (fd); }static int kwboot_tty_send_char (int fd,unsigned char c) { -return kwboot_tty_send (fd, &c,1 ); +return kwboot_tty_send (fd, &c,1 ,0 ); } static speed_t@@ -705,7 +708,7 @@ kwboot_bootmsg(int tty, void *msg)break ;for (count =0 ; count <128 ; count++) { - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -737,7 +740,7 @@ kwboot_debugmsg(int tty, void *msg)if (rc)break ; - rc =kwboot_tty_send (tty, msg,8 ); + rc =kwboot_tty_send (tty, msg,8 ,0 );if (rc) {usleep (msg_req_delay *1000 );continue ;@@ -929,7 +932,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm, retries =0 ; do { - rc = kwboot_tty_send(fd, block, sizeof(*block)); + rc = kwboot_tty_send(fd, block, sizeof(*block), 1); if (rc) return rc;
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
If it is kernel who does not fill next bytes into hw UART queue as it waits for tcdrain then above patch should fix it.
Still no ciguar. Here the end of the log with "-B 921600":
So no change in total transfer time with above patch?
No. AFAICT, it's always the same time. Like ~1.5 minutes for the overall U-Boot image.
Quoted 227 lines
Quoted 9 lines
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magic
xmodem: Connection timed outQuoted 6 lines
Quoted 2 lines
Or if you have other USB-UART cables, try another. I have good experience with pl2303-based.
I have tons of USB-UART adapters / cables. But as mentioned in the other mail, I can't connect them, as the FTDI chip is soldered on the target.
Understood.
Quoted 3 lines
Still it should work at least with 115201 baud, even if baudrate changing does not work. Right? So we have at least one other problem here AFAICT.
Baudrate change must work. Using 115201 baud could just show output from board/bootrom if CPU prematurely resets (which resets baudrate to default 115200).
Quoted 193 lines
Quoted 80 lines
Quoted 65 lines
Quoted 65 lines
Quoted 65 lines
Ok. This seems to work at least partly (SPL):
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/kwboot-B 115201 -b u-boot-spl.kwb -t/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Patching image boot signature to UART
Injecting binary header code for changing baudrate to 115201 Bd Injecting code for changing baudrate back
Sending boot message. Please reboot the target...|
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...0 % [......................................................................] 10 % [......................................................................] 20 % [......................................................................] 29 % [......................................................................] 39 % [......................................................................] 49 % [......................................................................] 59 % [......................................................................] 69 % [......................................................................] 79 % [......................................................................] 89 % [......................................................................] 99 % [.... ]Done
U-Boot SPL 2021.10-00908-gc129aa2f173a (Oct 26 2021 - 10:39:55 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address0xffff0aa0)...Changing baudrate to 115201 Bd
Sending boot image data (549892 bytes)...
0 % [......................................................................] 1 % [......................................................................] ... 97 % [......................................................................] 99 % [........................... ]Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
BootROM 1.20
Booting from SPI flashQuoted 7 lines
Quoted 5 lines
Quoted 1 line
So the CPU has run through a reset here.
What kind of CPU core has your AXP board? Maybe there is some arm instruction in kwboot_baud_code[] array which is not supported by that core (and so reset occurs)?
AXP stands for Armada XP, which is ARM v7 AFAIK.
I remember that older Marvell Armada SoCs used custom designed ARM cores, so there could be some differences what is supported by licensed ARM core and custom ARM core.
Anyway, as changing baudrate after execution of SPL is working fine, it should mean that there is no undefined/unsupported instruction.
Quoted 7 lines
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Quoted 82 lines
Quoted 15 lines
Quoted 2 lines
And could you send me commands which you are using for compiling U-Boot for that your AXP board? I would like to examine resulted binary.
I'm currently using a kernel.org toolchain:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ set | grep CROSS CROSS_COMPILE=/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi- [stefan@ryzen u-boot-marvell (kwboot-test1)]$
/opt/kernel.org/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc--version
arm-linux-gnueabi-gcc (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Quoted 5 lines
Here my commands to generate the U-Boot binary:
make mrproper
maketheadorable_debug_defconfig
make -s -j20Ok.
Quoted 26 lines
Quoted 26 lines
Quoted 4 lines
Quoted 3 lines
And what is the output of following command immediately after kwboot?
stty -F
/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0Quoted 8 lines
Changing baudrate to 230400 Bd
Baudrate was not changedxmodem: Protocol error
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ stty -F/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0speed 230400 baud; line = 0;... but baudrate _was_ changed.
So it looks like a bug in kwboot code. Try to apply above diff, it is really possible that you hit that logical error. (Interesting that neither Marek nor me saw it)
Quoted 7 lines
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>; discard = <undef>; min = 1; time = 0;
(quoted diff) +0
-3-brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echokeQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Also, could try to catch whole strace log and send it to me?
I'll try to do this later today.
'strace kwboot ... 1>log 2>&1' should do it...
Okay, will follow in the next privatze mail.
Received. I have looked at it. And there are two interesting parts:
1) Both parts of transfer (header at default speed 115200 and main at high speed 921600) were transferred without any error, except for the error indication of the last header packet. Error indication was sent after the execution of header itself (SPL and baudrate change), it means that there was no error and bootrom did not sent any error indication. kwboot did retransmission of this one packet and it succeeded (thanks to that fixup which I have sent).
So this error must have been just fluctuation on UART and probably caused by changing UART speed. I guess that your USB-UART chip needs more time to stabilize new speed and so USB-UART receiver lost/damaged reply byte sent by bootrom.
Maybe you could increase delay in arm baudrate change code, so CPU waits longer time before it returns to bootrom?
Replacing code in kwboot_baud_code[] array:
/* ; Sleep 1ms ~~ 600000 cycles at 1200 MHz */ /* ; r1 = 600000 */ 0x9f, 0x1d, 0xa0, 0xe3, /* mov r1, #0x27c0 */ 0x09, 0x10, 0x40, 0xe3, /* movt r1, #0x0009 */Quoted 8 lines
by:
/* ; Sleep 10ms ~~ 6M cycles at 1200 MHz */ /* ; r1 = 6000000 */ 0x80, 0x1d, 0x08, 0xe3, /* mov r1, #0x8d80 */ 0x5b, 0x10, 0x40, 0xe3, /* movt r1, #0x005b */should do it.
Still no change. Also not in the download speed AFAICT.
...
97 %
[......................................................................]
99 % [........................... ]
Done
Finishing transfer
Waiting 1s for baudrate change magicChanging baudrate back to 115200 Bd
Quoted 7 lines
[Type Ctrl-\ + c to quit]
BootROM 1.20
BTW: There is a external watchdog on the target, which might be the root cause for the reset I'm seeing here. It kicks in at around 2-3 minutes after power-up AFAIR.
Quoted 6 lines
But there is no more "xmodem: Connection timed out" error.
When that "BootROM 1.20" message was printed? Immediately after the "Changing baudrate back to 115200 Bd"? Or it was e.g. minute later? I would like to know if board reset relates to watchdog or if it relates to baudrate change code.
I've disabled the watchdog now. So it will not interfere with these tests and confuse us any more.
I've not seen the reset any more now. So it's most likely only related to the watchdog. Here the latest log with all your suggested changes:
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ ./tools/kwboot -B 230400 -b u-boot-spl.kwb -t /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 Patching image boot signature to UART
Injecting binary header code for changing baudrate to 230400 Bd
Injecting code for changing baudrate back
Sending boot message. Please reboot the target...\
Waiting 2s and flushing tty
Sending boot image header (90112 bytes)...
0 %
[......................................................................]
10 %
[......................................................................]
20 %
[......................................................................]
29 %
[......................................................................]
39 %
[......................................................................]
49 %
[......................................................................]
59 %
[......................................................................]
69 %
[......................................................................]
79 %
[......................................................................]
89 %
[......................................................................]
99 % [....
]
Done
U-Boot SPL 2021.10-00908-gc129aa2f173a-dirty (Oct 26 2021 - 17:02:40 +0200) High speed PHY - Version: 2.1.5 (COM-PHY-V20)
High speed PHY - Ended Successfully
DDR3 Training Sequence - Ver 5.7.4
DDR3 Training Sequence - Ended Successfully
Trying to boot from BOOTROM
Returning to BootROM (return address 0xffff0aa0)...
Changing baudrate to 230400 Bd
Sending boot image data (548868 bytes)...
0 %
[......................................................................]
1 %
[......................................................................]
3 %
[......................................................................]
4 %
[......................................................................]
6 %
[......................................................................]
8 %
[......................................................................]
9 %
[......................................................................]
11 %
[......................................................................]
13 %
[......................................................................]
14 %
[......................................................................]
16 %
[......................................................................]
17 %
[......................................................................]
19 %
[......................................................................]
21 %
[......................................................................]
22 %
[......................................................................]
24 %
[......................................................................]
26 %
[......................................................................]
27 %
[......................................................................]
29 %
[......................................................................]
31 %
[......................................................................]
32 %
[......................................................................]
34 %
[......................................................................]
35 %
[......................................................................]
37 %
[......................................................................]
39 %
[......................................................................]
40 %
[......................................................................]
42 %
[......................................................................]
44 %
[......................................................................]
45 %
[......................................................................]
47 %
[......................................................................]
48 %
[......................................................................]
50 %
[......................................................................]
52 %
[......................................................................]
53 %
[......................................................................]
55 %
[......................................................................]
57 %
[......................................................................]
58 %
[......................................................................]
60 %
[......................................................................]
62 %
[......................................................................]
63 %
[......................................................................]
65 %
[......................................................................]
66 %
[......................................................................]
68 %
[......................................................................]
70 %
[......................................................................]
71 %
[......................................................................]
73 %
[......................................................................]
75 %
[......................................................................]
76 %
[......................................................................]
78 %
[......................................................................]
80 %
[......................................................................]
81 %
[......................................................................]
83 %
[......................................................................]
84 %
[......................................................................]
86 %
[......................................................................]
88 %
[......................................................................]
89 %
[......................................................................]
91 %
[......................................................................]
93 %
[......................................................................]
94 %
[......................................................................]
96 %
[......................................................................]
97 %
[......................................................................]
99 % [...................
]
Done
Finishing transfer
Waiting 1s for baudrate change magic
Changing baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
Here is now just hangs forever. No output from main U-Boot proper at all. This happed every time, when the baudrate is changed, meaning a non 115200 -B is passed to kwboot. I checked with 115201 and here no U-Boot proper output is printed as well.
Quoted 2 lines
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
I changed the timeout to 10s without any change. It did not help.
Thanks,
Stefan
Quoted 9 lines · On Tue, 26 Oct 2021 17:13:05 +0200 Stefan Roese <[email protected]> wrote:
Here is now just hangs forever. No output from main U-Boot proper at all. This happed every time, when the baudrate is changed, meaning a non 115200 -B is passed to kwboot. I checked with 115201 and here no U-Boot proper output is printed as well.
Quoted 2 lines
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
I changed the timeout to 10s without any change. It did not help.
At what address is the image being sent to? Please send dumpimage output for the kwb image.
Is it possible to connect JTAG to the board?
Marek
Quoted 8 lines · Marek Behún
Quoted 5 lines · On Tue, 26 Oct 2021 17:13:05 +0200 Stefan Roese <[email protected]> wrote:
Here is now just hangs forever. No output from main U-Boot proper at all. This happed every time, when the baudrate is changed, meaning a non 115200 -B is passed to kwboot. I checked with 115201 and here no U-Boot proper output is printed as well.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
I changed the timeout to 10s without any change. It did not help.
At what address is the image being sent to? Please send dumpimage output for the kwb image.
[stefan@ryzen u-boot-marvell (kwboot-test1)]$ ./tools/dumpimage -l u-boot-spl.kwb
Image Type: MVEBU Boot from spi Image
Image version:1
BIN Hdr Size: 89196 Bytes = 87.11 KiB = 0.09 MiB Data Size: 548604 Bytes = 535.75 KiB = 0.52 MiB Load Address: 00800000 Entry Point: 00800000
Quoted 1 line
Is it possible to connect JTAG to the board?
It is. But this would be a bit difficult for me, to dig all these old tools out and find the correct configuration of the BDI.
Thanks,
Stefan
Quoted 17 lines · On Tue, 26 Oct 2021 17:25:10 +0200 Stefan Roese <[email protected]> wrote:
Quoted 8 lines · Marek Behún
Quoted 5 lines · On Tue, 26 Oct 2021 17:13:05 +0200 Stefan Roese <[email protected]> wrote:
Here is now just hangs forever. No output from main U-Boot proper at all. This happed every time, when the baudrate is changed, meaning a non 115200 -B is passed to kwboot. I checked with 115201 and here no U-Boot proper output is printed as well.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
I changed the timeout to 10s without any change. It did not help.
At what address is the image being sent to? Please send dumpimage output for the kwb image.
Quoted 8 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/dumpimage-l u-boot-spl.kwb
Image Type: MVEBU Boot from spi Image
Image version:1BIN Hdr Size: 89196 Bytes = 87.11 KiB = 0.09 MiB Data Size: 548604 Bytes = 535.75 KiB = 0.52 MiB Load Address: 00800000 Entry Point: 00800000
I think the baudrate changing code is not the problem, because it executes correctly in the binhdr when increasing the baudrate. Otherwise
Changing baudrate to 230400 Bd
wouldn't be printed.
Stefan, did it previously work on this board? I mean at the time the patches were first merged into u-boot-marvell Did the problem start occuring only now, when the code is merged in u-boot master?
Quoted 4 lines
Quoted 1 line
Is it possible to connect JTAG to the board?
It is. But this would be a bit difficult for me, to dig all these old tools out and find the correct configuration of the BDI.
Yes, lets keep that as last resort.
Marek
Quoted 29 lines · Marek Behún
Quoted 17 lines · On Tue, 26 Oct 2021 17:25:10 +0200 Stefan Roese <[email protected]> wrote:
Quoted 8 lines · Marek Behún
Quoted 5 lines · On Tue, 26 Oct 2021 17:13:05 +0200 Stefan Roese <[email protected]> wrote:
Here is now just hangs forever. No output from main U-Boot proper at all. This happed every time, when the baudrate is changed, meaning a non 115200 -B is passed to kwboot. I checked with 115201 and here no U-Boot proper output is printed as well.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
If there are timeout errors related to "Waiting 1s for baudrate change magic" then increasing 1s (1000 ms value) to e.g. 10s could help.
I changed the timeout to 10s without any change. It did not help.
At what address is the image being sent to? Please send dumpimage output for the kwb image.
Quoted 8 lines
[stefan@ryzen u-boot-marvell (kwboot-test1)]$
./tools/dumpimage-l u-boot-spl.kwb
Image Type: MVEBU Boot from spi Image
Image version:1BIN Hdr Size: 89196 Bytes = 87.11 KiB = 0.09 MiB Data Size: 548604 Bytes = 535.75 KiB = 0.52 MiB Load Address: 00800000 Entry Point: 00800000
Quoted 5 lines
I think the baudrate changing code is not the problem, because it executes correctly in the binhdr when increasing the baudrate. Otherwise
Changing baudrate to 230400 Bd
wouldn't be printed.
Okay. Still it's unclear, why I don't see any speedup in the download time here.
Quoted 1 line
Stefan, did it previously work on this board?
No...
Quoted 3 lines
I mean at the time the
patches were first merged into u-boot-marvell Did the problem start occuring only now, when the code is merged in u-boot master?
... Meaning, it still works when the baudrate is not changed at all. I never tried with a baudrate != 115200 until your work in this area here.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Is it possible to connect JTAG to the board?
It is. But this would be a bit difficult for me, to dig all these old tools out and find the correct configuration of the BDI.
Yes, lets keep that as last resort.
Agreed.
Thanks,
Stefan
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +13 -13
@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );
@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200); /* recompute header size */ hdrsz =kwbheader_size (hdr);
As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Quoted 49 lines · Pali Rohár
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +11
-11@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );
tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1555
Quoted 7 lines
tools/kwboot.c +2
-2@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200);
I do have this here in my version as well:
/* Update the 32-bit data checksum */ *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img); /* recompute header size */ hdrsz = kwbheader_size(hdr);
So I'm using the newer version, just to be sure.
Quoted 9 lines
tools/kwboot.c +0
-0/* recompute header size */ hdrsz =kwbheader_size (hdr);As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Okay, applied this patch and and booting with different baudrates works on this board again (tested with 230400):
96 %
[......................................................................]
98 %
[......................................................................]
99 % [................
]
Done
Finishing transfer
Changing baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00908-gc129aa2f173a-dirty (Oct 27 2021 - 07:05:39 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)
Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB OK
Model: Marvell Armada XP theadorable
...
Thanks,
Stefan
Quoted 58 lines · On Wednesday 27 October 2021 07:09:42 Stefan Roese wrote:
Quoted 47 lines · Pali Rohár
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +11
-11@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1555
Quoted 7 lines
tools/kwboot.c +2
-2@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200); I do have this here in my version as well:
Quoted 7 lines
/* Update the 32-bit data checksum */ *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img); /* recompute header size */ hdrsz = kwbheader_size(hdr);So I'm using the newer version, just to be sure.
Ok, I probably generated diff against older version, but you have figured out how to apply it.
Quoted 37 lines
Quoted 8 lines
tools/kwboot.c +0
-0/* recompute header size */ hdrsz =kwbheader_size (hdr);As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Okay, applied this patch and and booting with different baudrates works on this board again (tested with 230400):
96 %
[......................................................................]
98 %
[......................................................................]
99 % [................ ]
Done
Finishing transferChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00908-gc129aa2f173a-dirty (Oct 27 2021 - 07:05:39 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB
OK
Model: Marvell Armada XP theadorable
...
Quoted 2 lines
Thanks,
Stefan
Perfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +5 -0
@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) { + *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + } } static int
Could you try to apply this change instead of my previous one?
Quoted 121 lines · On Wednesday 27 October 2021 15:52:47 Pali Rohár wrote:
Quoted 58 lines · On Wednesday 27 October 2021 07:09:42 Stefan Roese wrote:
Quoted 47 lines · Pali Rohár
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +11
-11@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1555
Quoted 7 lines
tools/kwboot.c +2
-2@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200); I do have this here in my version as well:
Quoted 7 lines
/* Update the 32-bit data checksum */ *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img); /* recompute header size */ hdrsz = kwbheader_size(hdr);So I'm using the newer version, just to be sure.
Ok, I probably generated diff against older version, but you have figured out how to apply it.
Quoted 37 lines
Quoted 8 lines
tools/kwboot.c +0
-0/* recompute header size */ hdrsz =kwbheader_size (hdr);As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Okay, applied this patch and and booting with different baudrates works on this board again (tested with 230400):
96 %
[......................................................................]
98 %
[......................................................................]
99 % [................ ]
Done
Finishing transferChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00908-gc129aa2f173a-dirty (Oct 27 2021 - 07:05:39 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB
OK
Model: Marvell Armada XP theadorable
...Quoted 2 lines
Thanks,
StefanPerfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +0
-0
tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1448
Quoted 5 lines
tools/kwboot.c +2
-0@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) {
Ou, there is a mistake, it should be "if (pre) {"
Quoted 8 lines
tools/kwboot.c +3
-0+ *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + } } static intCould you try to apply this change instead of my previous one?
Quoted 130 lines · On Wed, 27 Oct 2021 16:10:21 +0200 Pali Rohár <[email protected]> wrote:
Quoted 121 lines · On Wednesday 27 October 2021 15:52:47 Pali Rohár wrote:
Quoted 58 lines · On Wednesday 27 October 2021 07:09:42 Stefan Roese wrote:
Quoted 47 lines · Pali Rohár
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +11
-11@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1555
Quoted 7 lines
tools/kwboot.c +2
-2@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200); I do have this here in my version as well:
Quoted 7 lines
/* Update the 32-bit data checksum */ *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img); /* recompute header size */ hdrsz = kwbheader_size(hdr);So I'm using the newer version, just to be sure.
Ok, I probably generated diff against older version, but you have figured out how to apply it.
Quoted 37 lines
Quoted 8 lines
tools/kwboot.c +0
-0/* recompute header size */ hdrsz =kwbheader_size (hdr);As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Okay, applied this patch and and booting with different baudrates works on this board again (tested with 230400):
96 %
[......................................................................]
98 %
[......................................................................]
99 % [................ ]
Done
Finishing transferChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00908-gc129aa2f173a-dirty (Oct 27 2021 - 07:05:39 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB
OK
Model: Marvell Armada XP theadorable
...Quoted 2 lines
Thanks,
StefanPerfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +0
-0tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1448
Quoted 5 lines
tools/kwboot.c +2
-0@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) {Ou, there is a mistake, it should be "if (pre) {"
Quoted 3 lines
tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1451
Quoted 3 lines
tools/kwboot.c +3
-0+ *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + }
This fixes it for me as well, for that one Omnia which didn't work which I was debugging a few days ago.
I guess this can't be done in the binhdr? So we need 2 different versions? I don't quite like this ad-hoc change, but I also don't like two copies with just a small change between them...
Marek
Quoted 140 lines · On Wednesday 27 October 2021 17:08:35 Marek Behún wrote:
Quoted 130 lines · On Wed, 27 Oct 2021 16:10:21 +0200 Pali Rohár <[email protected]> wrote:
Quoted 121 lines · On Wednesday 27 October 2021 15:52:47 Pali Rohár wrote:
Quoted 58 lines · On Wednesday 27 October 2021 07:09:42 Stefan Roese wrote:
Quoted 47 lines · Pali Rohár
Quoted 10 lines · On Tuesday 26 October 2021 16:21:02 Stefan Roese wrote:
Quoted 7 lines · Pali Rohár
My another guess there could be a problem is usage of stack. Maybe it is possible that register with stack pointer is not initialized after the full transfer when going to execute main image. Same arm baudrate change code is used after the SPL and before main U-Boot, and the first instruction is "push". Maybe modifying the arm code to not use stack when switching the baudrate back to 115200 could also help. I will look at it.
Thanks.
Here is dirty hack patch which completely disable calling code for changing baudrate back to 115200 on ARM side:
tools/kwboot.c +11
-11@@ -1070,17 +1070,17 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)return rc;if (baudrate) { -char buf[sizeof (kwb_baud_magic)]; - -kwboot_printv ("Waiting 1s for baudrate change magic\n" ); - rc =kwboot_tty_recv (tty, buf,sizeof (buf),1000 ); -if (rc) -return rc; - -if (memcmp (buf, kwb_baud_magic,sizeof (buf))) { - errno =EPROTO ; -return -1 ; - } +// char buf[sizeof(kwb_baud_magic)]; +// +// kwboot_printv("Waiting 1s for baudrate change magic\n"); +// rc = kwboot_tty_recv(tty, buf, sizeof(buf), 1000); +// if (rc) +// return rc; +// +// if (memcmp(buf, kwb_baud_magic, sizeof(buf))) { +// errno = EPROTO; +// return -1; +// } kwboot_printv ("\nChanging baudrate back to 115200 Bd\n\n" ); rc =kwboot_tty_change_baudrate (tty,115200 );tools/kwboot.c kwboot_img_patch(void *img, size_t *size, int baudrate) · line 1555
Quoted 7 lines
tools/kwboot.c +2
-2@@ -1551,8 +1551,8 @@ kwboot_img_patch(void *img, size_t *size, int baudrate)* This code is appended after the data part of the image and * execaddr is changed to execute this code before U-Boot proper. */ -kwboot_printv ("Injecting code for changing baudrate back\n" ); -_copy_baudrate_change_code (hdr, size,1 , baudrate,115200 ); +// kwboot_printv("Injecting code for changing baudrate back\n"); +// _copy_baudrate_change_code(hdr, size, 1, baudrate, 115200); I do have this here in my version as well:
Quoted 7 lines
/* Update the 32-bit data checksum */ *kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img); /* recompute header size */ hdrsz = kwbheader_size(hdr);So I'm using the newer version, just to be sure.
Ok, I probably generated diff against older version, but you have figured out how to apply it.
Quoted 37 lines
Quoted 8 lines
tools/kwboot.c +0
-0/* recompute header size */ hdrsz =kwbheader_size (hdr);As main U-Boot binary on ARM resets UART, it means that baudrate is properly set to 115200. Probably beginning of the U-Boot output could be lost but at least console should start.
Could you try this patch if it starts working now?
Okay, applied this patch and and booting with different baudrates works on this board again (tested with 230400):
96 %
[......................................................................]
98 %
[......................................................................]
99 % [................ ]
Done
Finishing transferChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00908-gc129aa2f173a-dirty (Oct 27 2021 - 07:05:39 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB
OK
Model: Marvell Armada XP theadorable
...Quoted 2 lines
Thanks,
StefanPerfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +0
-0tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1448
Quoted 5 lines
tools/kwboot.c +2
-0@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) {Ou, there is a mistake, it should be "if (pre) {"
Quoted 3 lines
tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1451
Quoted 3 lines
tools/kwboot.c +3
-0+ *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + }This fixes it for me as well, for that one Omnia which didn't work which I was debugging a few days ago.
Quoted 5 lines
I guess this can't be done in the binhdr? So we need 2 different versions? I don't quite like this ad-hoc change, but I also don't like two copies with just a small change between them...
Marek
I will prepare cleanup / proper patch with one (configurable) version. Just I need to know if this change fixes issue also for AXP.
On 27.10.21 16:10, Pali Rohár wrote:
<snip>
Quoted 19 lines
Quoted 11 lines
Perfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +0
-0tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1448
Quoted 5 lines
tools/kwboot.c +2
-0@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) {Ou, there is a mistake, it should be "if (pre) {"
Quoted 8 lines
Quoted 8 lines
tools/kwboot.c +3
-0+ *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + } } static intCould you try to apply this change instead of my previous one?
Tested with this corrected patch:
97 %
[......................................................................]
99 % [...................
]
Done
Finishing transfer
Waiting 2s for baudrate change magic
Changing baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00916-gc6142e537e88-dirty (Oct 27 2021 - 17:23:24 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)
Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB OK
Model: Marvell Armada XP theadorable
...
Perfect. This works on Armada XP. :)
Still I see no speed change. But this is a different story...
Thanks,
Stefan
Quoted 50 lines · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
On 27.10.21 16:10, Pali Rohár wrote:
<snip>
Quoted 19 lines
Quoted 11 lines
Perfect! So it really looks like that issue is in the code which resets baudrate back to the value 115200.
I have there another diff which removes usage of the stack in code which resets baudrate back to default value:
tools/kwboot.c +0
-0tools/kwboot.c _inject_baudrate_change_code(void *img, size_t *size, int pre, · line 1448
Quoted 5 lines
tools/kwboot.c +2
-0@@ -1444,6 +1444,11 @@ _inject_baudrate_change_code(void *img, size_t *size, int pre,memcpy (code, kwboot_baud_code, codesz -8 ); *(uint32_t *)(code + codesz -8 ) =cpu_to_le32 (old_baud); *(uint32_t *)(code + codesz -4 ) =cpu_to_le32 (new_baud); + +if (!pre) {Ou, there is a mistake, it should be "if (pre) {"
Quoted 7 lines
Quoted 7 lines
tools/kwboot.c +3
-0+ *(uint32_t *)code =cpu_to_le32 (0xe1a00000 );/* arm nop */ + *(uint32_t *)(code + codesz -4 *7 ) =cpu_to_le32 (0xe12fff1e );/* bx lr */ + } } static intCould you try to apply this change instead of my previous one?
Tested with this corrected patch:
97 %
[......................................................................]
99 % [................... ]
Done
Finishing transfer
Waiting 2s for baudrate change magicChanging baudrate back to 115200 Bd
[Type Ctrl-\ + c to quit]
U-Boot 2021.10-00916-gc6142e537e88-dirty (Oct 27 2021 - 17:23:24 +0200)
SoC: MV78260-B0 at 1333 MHz I2C: ready DRAM: 2 GiB (667 MHz, 64-bit, ECC not enabled)
Quoted 7 lines
Loading Environment from SPIFlash... SF: Detected m25p128 with page size 256 Bytes, erase size 256 KiB, total 16 MiB
OK
Model: Marvell Armada XP theadorable
...Perfect. This works on Armada XP. :)
Nice! Therefore I will prepare proper patch for removing stack usage.
Quoted 4 lines
Still I see no speed change. But this is a different story...
Thanks,
Stefan
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
loadx <addr> 921600
and
loadx <addr> 115200
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
This could verify if issue is in kwboot or in USB-UART/kernel.
Quoted 11 lines · Pali Rohár
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
loadx <addr> 921600
and
loadx <addr> 115200
loadx & loady are producing nearly the same numbers on my Armada XP target for download (slow of cause). This is really strange.
I also tested with "normal" console actions (logging) with higher baudrates. Here these numbers:
time md 2000000 10000:
115200 baud:
time: 1 minutes, 32.694 seconds
921600 baud:
time: 11.587 seconds
92.7s vs 11.6s -> factor ~8. Which is exactly the baudrate difference. So at least here I see a speed difference, which means that the USB UART converter must be working in general. I really have no idea right now to explain, why this does not any speed differences while downloading.
Quoted 3 lines
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
I'm currently struggling to get gkermit working on my Ubuntu machine - so no numbers here yet, sorry.
Quoted 1 line
This could verify if issue is in kwboot or in USB-UART/kernel.
Makes sense.
Thanks,
Stefan
Quoted 7 lines · On Thursday 28 October 2021 08:16:24 Stefan Roese wrote:
Quoted 6 lines · Pali Rohár
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
Quoted 8 lines
Quoted 5 lines
loadx <addr> 921600
and
loadx <addr> 115200
loadx & loady are producing nearly the same numbers on my Armada XP target for download (slow of cause). This is really strange.
Ok. So it means that the issue should not be in kwboot, if also U-Boot xmodem implementation is affected.
Quoted 8 lines
I also tested with "normal" console actions (logging) with higher baudrates. Here these numbers:
time md 2000000 10000:
115200 baud:
time: 1 minutes, 32.694 seconds
Quoted 8 lines
921600 baud:
time: 11.587 seconds92.7s vs 11.6s -> factor ~8. Which is exactly the baudrate difference. So at least here I see a speed difference, which means that the USB UART converter must be working in general. I really have no idea right now to explain, why this does not any speed differences while downloading.
So this means that USB-UART converter must work also on higher speeds.
My idea is that there is some significant overhead on USB-UART when accessing either RX or TX queue. xmodem protocol is: send 132 bytes, wait for 1 byte reply, send another 132 bytes, wait again for 1 byte reply, ... So if USB-UART has internal overhead which cause that every byte is postponed by some delay then it would mean that xmodem is most time just waiting, meaning overhead is applied for every one 132-byte long packet. Test with md cause continuous stream of data, therefore such overhead is applied only at beginning of the md transfer.
Similar issues with can observed also on high speed networks were is very big latency when using protocols where each small packet has to be acknowledged. TCP is using windowing to prevent such kind of issues.
And kermit protocol too via its streaming mode. So kermit transfer could prove if this is really that issue.
Anyway, I have looked at your strace output again and I saw that there is a long gap after tcdrain() and end of the read(). So if kernel implements tcdrain() for your USB-UART hw it means that it take too much time to receive reply byte from USB-UART hw to the kernel. So it could be another indication of that overhead.
Quoted 6 lines
Quoted 3 lines
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
I'm currently struggling to get gkermit working on my Ubuntu machine - so no numbers here yet, sorry.
In U-Boot console call:
loadb _addr_
And then quit terminal emulator used for U-Boot /dev/ttyUSBX device. Then run gkermit with following arguments:
gkermit -i -X -s _file_to_send_ < /dev/ttyUSBX > /dev/ttyUSBX
(redirecting both stdin and stdout is required)
After successful transfer gkermit exit. BEWARE that gkermit does not print any progress information and neither any error. So do not kill gkermit via CTRL+C prematurely. You can use "time gkermit ..." for measuring total transfer time.
If you are going to use different speed than 115200 in u-boot run:
loadb _addr_ _speed_
And then on host start gkermit with more commands around:
stty -F /dev/ttyUSBX _speed_
printf '\015' > /dev/ttyUSBX
gkermit -i -X -s _file_to_send < /dev/ttyUSBX > /dev/ttyUSBX sleep 0.5
stty -F /dev/ttyUSBX 115200
printf '\033' > /dev/ttyUSBX
Due to absence of progress bar and error information I'm using ckermit application for kermit file transfers. But for testing purposes is gkermit application here also fine.
Quoted 6 lines
Quoted 1 line
This could verify if issue is in kwboot or in USB-UART/kernel.
Makes sense.
Thanks,
Stefan
Quoted 12 lines · Pali Rohár
Quoted 11 lines · On Thursday 28 October 2021 08:16:24 Stefan Roese wrote:
Quoted 10 lines · Pali Rohár
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
loadx <addr> 921600
and
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
loadx <addr> 115200
loadx & loady are producing nearly the same numbers on my Armada XP target for download (slow of cause). This is really strange.
Ok. So it means that the issue should not be in kwboot, if also U-Boot xmodem implementation is affected.
Agreed.
Quoted 32 lines
Quoted 8 lines
I also tested with "normal" console actions (logging) with higher baudrates. Here these numbers:
time md 2000000 10000:
115200 baud:
time: 1 minutes, 32.694 secondsQuoted 8 lines
921600 baud:
time: 11.587 seconds92.7s vs 11.6s -> factor ~8. Which is exactly the baudrate difference. So at least here I see a speed difference, which means that the USB UART converter must be working in general. I really have no idea right now to explain, why this does not any speed differences while downloading.
So this means that USB-UART converter must work also on higher speeds.
My idea is that there is some significant overhead on USB-UART when accessing either RX or TX queue. xmodem protocol is: send 132 bytes, wait for 1 byte reply, send another 132 bytes, wait again for 1 byte reply, ... So if USB-UART has internal overhead which cause that every byte is postponed by some delay then it would mean that xmodem is most time just waiting, meaning overhead is applied for every one 132-byte long packet. Test with md cause continuous stream of data, therefore such overhead is applied only at beginning of the md transfer.
Similar issues with can observed also on high speed networks were is very big latency when using protocols where each small packet has to be acknowledged. TCP is using windowing to prevent such kind of issues.
Quoted 8 lines
And kermit protocol too via its streaming mode. So kermit transfer could prove if this is really that issue.
Anyway, I have looked at your strace output again and I saw that there is a long gap after
tcdrain()and end of theread(). So if kernel implementstcdrain()for your USB-UART hw it means that it take too much time to receive reply byte from USB-UART hw to the kernel. So it could be another indication of that overhead.
Thanks for the input here.
Quoted 36 lines
Quoted 6 lines
Quoted 3 lines
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
I'm currently struggling to get gkermit working on my Ubuntu machine - so no numbers here yet, sorry.
In U-Boot console call:
loadb _addr_
And then quit terminal emulator used for U-Boot
/dev/ttyUSBXdevice. Then run gkermit with following arguments:gkermit -i -X -s _file_to_send_ <
/dev/ttyUSBX>/dev/ttyUSBX(redirecting both stdin and stdout is required)
After successful transfer gkermit exit. BEWARE that gkermit does not print any progress information and neither any error. So do not kill gkermit via CTRL+C prematurely. You can use "time gkermit ..." for measuring total transfer time.
If you are going to use different speed than 115200 in u-boot run:
loadb _addr_ _speed_
And then on host start gkermit with more commands around:
stty -F /dev/ttyUSBX _speed_ printf '\015' > /dev/ttyUSBX gkermit -i -X -s _file_to_send < /dev/ttyUSBX > /dev/ttyUSBX sleep 0.5 stty -F /dev/ttyUSBX 115200 printf '\033' > /dev/ttyUSBX
Quoted 3 lines
Due to absence of progress bar and error information I'm using ckermit application for kermit file transfers. But for testing purposes is gkermit application here also fine.
Ah, perfect. Here my number now using these steps and gkermit, with a file size of 549373 bytes:
115200 baud: ~72 sec
921600 baud: ~11 sec
But:
I see this on my PC on the first use of a baudrate change:
$ stty -F /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 921600 stty: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0: unable to perform all requested operations
The 2nd call succeeds. Not sure what this means. Perhaps this has something to do with the speed problem, I'm seeing here on my AXP target with the FTDI USB-UART controller.
Thanks,
Stefan
Quoted 106 lines · On Thursday 28 October 2021 16:20:11 Stefan Roese wrote:
Quoted 12 lines · Pali Rohár
Quoted 11 lines · On Thursday 28 October 2021 08:16:24 Stefan Roese wrote:
Quoted 10 lines · Pali Rohár
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
loadx <addr> 921600
and
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
loadx <addr> 115200
loadx & loady are producing nearly the same numbers on my Armada XP target for download (slow of cause). This is really strange.
Ok. So it means that the issue should not be in kwboot, if also U-Boot xmodem implementation is affected.
Agreed.
Quoted 32 lines
Quoted 8 lines
I also tested with "normal" console actions (logging) with higher baudrates. Here these numbers:
time md 2000000 10000:
115200 baud:
time: 1 minutes, 32.694 secondsQuoted 8 lines
921600 baud:
time: 11.587 seconds92.7s vs 11.6s -> factor ~8. Which is exactly the baudrate difference. So at least here I see a speed difference, which means that the USB UART converter must be working in general. I really have no idea right now to explain, why this does not any speed differences while downloading.
So this means that USB-UART converter must work also on higher speeds.
My idea is that there is some significant overhead on USB-UART when accessing either RX or TX queue. xmodem protocol is: send 132 bytes, wait for 1 byte reply, send another 132 bytes, wait again for 1 byte reply, ... So if USB-UART has internal overhead which cause that every byte is postponed by some delay then it would mean that xmodem is most time just waiting, meaning overhead is applied for every one 132-byte long packet. Test with md cause continuous stream of data, therefore such overhead is applied only at beginning of the md transfer.
Similar issues with can observed also on high speed networks were is very big latency when using protocols where each small packet has to be acknowledged. TCP is using windowing to prevent such kind of issues.
Quoted 8 lines
And kermit protocol too via its streaming mode. So kermit transfer could prove if this is really that issue.
Anyway, I have looked at your strace output again and I saw that there is a long gap after
tcdrain()and end of theread(). So if kernel implementstcdrain()for your USB-UART hw it means that it take too much time to receive reply byte from USB-UART hw to the kernel. So it could be another indication of that overhead.Thanks for the input here.
Quoted 36 lines
Quoted 6 lines
Quoted 3 lines
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
I'm currently struggling to get gkermit working on my Ubuntu machine - so no numbers here yet, sorry.
In U-Boot console call:
loadb _addr_
And then quit terminal emulator used for U-Boot
/dev/ttyUSBXdevice. Then run gkermit with following arguments:gkermit -i -X -s _file_to_send_ <
/dev/ttyUSBX>/dev/ttyUSBX(redirecting both stdin and stdout is required)
After successful transfer gkermit exit. BEWARE that gkermit does not print any progress information and neither any error. So do not kill gkermit via CTRL+C prematurely. You can use "time gkermit ..." for measuring total transfer time.
If you are going to use different speed than 115200 in u-boot run:
loadb _addr_ _speed_
And then on host start gkermit with more commands around:
stty -F /dev/ttyUSBX _speed_ printf '\015' > /dev/ttyUSBX gkermit -i -X -s _file_to_send < /dev/ttyUSBX > /dev/ttyUSBX sleep 0.5 stty -F /dev/ttyUSBX 115200 printf '\033' > /dev/ttyUSBXQuoted 3 lines
Due to absence of progress bar and error information I'm using ckermit application for kermit file transfers. But for testing purposes is gkermit application here also fine.
Quoted 5 lines
Ah, perfect. Here my number now using these steps and gkermit, with a file size of 549373 bytes:
115200 baud: ~72 sec
921600 baud: ~11 sec
So I think it is clear now. Either USB-UART HW or kernel driver for it has some big overhead for any protocol which needs acknowledgement of received data. So xmodem protocol is not suitable for it.
It would require to debug kernel driver and ideally monitor traffic on oscilloscope to see where exactly is the issue.
And because bootrom supports only xmodem protocol we cannot do more in kwboot.
For other cases it is a good idea to use kermit protocol instead of xmodem.
Quoted 10 lines
But:
I see this on my PC on the first use of a baudrate change:$ stty -F /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0 921600 stty: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A1019EGY-if00-port0: unable to perform all requested operationsThe 2nd call succeeds. Not sure what this means. Perhaps this has something to do with the speed problem, I'm seeing here on my AXP target with the FTDI USB-UART controller.
Maybe this could indicate bugs in kernel driver.
Quoted 2 lines
Thanks,
Stefan
Quoted 117 lines · Pali Rohár
Quoted 106 lines · On Thursday 28 October 2021 16:20:11 Stefan Roese wrote:
Quoted 12 lines · Pali Rohár
Quoted 11 lines · On Thursday 28 October 2021 08:16:24 Stefan Roese wrote:
Quoted 10 lines · Pali Rohár
Quoted 1 line · On Wednesday 27 October 2021 17:27:41 Stefan Roese wrote:
Still I see no speed change. But this is a different story...
Could you try to upload some file in u-boot via xmodem at different speeds? E.g. via loadx command:
loadx <addr> 921600
and
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
loadx <addr> 115200
loadx & loady are producing nearly the same numbers on my Armada XP target for download (slow of cause). This is really strange.
Ok. So it means that the issue should not be in kwboot, if also U-Boot xmodem implementation is affected.
Agreed.
Quoted 32 lines
Quoted 8 lines
I also tested with "normal" console actions (logging) with higher baudrates. Here these numbers:
time md 2000000 10000:
115200 baud:
time: 1 minutes, 32.694 secondsQuoted 8 lines
921600 baud:
time: 11.587 seconds92.7s vs 11.6s -> factor ~8. Which is exactly the baudrate difference. So at least here I see a speed difference, which means that the USB UART converter must be working in general. I really have no idea right now to explain, why this does not any speed differences while downloading.
So this means that USB-UART converter must work also on higher speeds.
My idea is that there is some significant overhead on USB-UART when accessing either RX or TX queue. xmodem protocol is: send 132 bytes, wait for 1 byte reply, send another 132 bytes, wait again for 1 byte reply, ... So if USB-UART has internal overhead which cause that every byte is postponed by some delay then it would mean that xmodem is most time just waiting, meaning overhead is applied for every one 132-byte long packet. Test with md cause continuous stream of data, therefore such overhead is applied only at beginning of the md transfer.
Similar issues with can observed also on high speed networks were is very big latency when using protocols where each small packet has to be acknowledged. TCP is using windowing to prevent such kind of issues.
Quoted 8 lines
And kermit protocol too via its streaming mode. So kermit transfer could prove if this is really that issue.
Anyway, I have looked at your strace output again and I saw that there is a long gap after
tcdrain()and end of theread(). So if kernel implementstcdrain()for your USB-UART hw it means that it take too much time to receive reply byte from USB-UART hw to the kernel. So it could be another indication of that overhead.Thanks for the input here.
Quoted 36 lines
Quoted 6 lines
Quoted 3 lines
And compare if xmodem transfer is in U-Boot faster or not. Ideally also try via kermit protocol at different speeds as kernel supports streaming.
I'm currently struggling to get gkermit working on my Ubuntu machine - so no numbers here yet, sorry.
In U-Boot console call:
loadb _addr_
And then quit terminal emulator used for U-Boot
/dev/ttyUSBXdevice. Then run gkermit with following arguments:gkermit -i -X -s _file_to_send_ <
/dev/ttyUSBX>/dev/ttyUSBX(redirecting both stdin and stdout is required)
After successful transfer gkermit exit. BEWARE that gkermit does not print any progress information and neither any error. So do not kill gkermit via CTRL+C prematurely. You can use "time gkermit ..." for measuring total transfer time.
If you are going to use different speed than 115200 in u-boot run:
loadb _addr_ _speed_
And then on host start gkermit with more commands around:
stty -F /dev/ttyUSBX _speed_ printf '\015' > /dev/ttyUSBX gkermit -i -X -s _file_to_send < /dev/ttyUSBX > /dev/ttyUSBX sleep 0.5 stty -F /dev/ttyUSBX 115200 printf '\033' > /dev/ttyUSBXQuoted 3 lines
Due to absence of progress bar and error information I'm using ckermit application for kermit file transfers. But for testing purposes is gkermit application here also fine.
Quoted 5 lines
Ah, perfect. Here my number now using these steps and gkermit, with a file size of 549373 bytes:
115200 baud: ~72 sec
921600 baud: ~11 secSo I think it is clear now. Either USB-UART HW or kernel driver for it has some big overhead for any protocol which needs acknowledgement of received data. So xmodem protocol is not suitable for it.
Quoted 5 lines
It would require to debug kernel driver and ideally monitor traffic on oscilloscope to see where exactly is the issue.
And because bootrom supports only xmodem protocol we cannot do more in kwboot.
Agreed. Let's close this issue here. Important is, that kwboot still works on all supported SoC's - even if the speedup improvements may not be available for all boards.
Thanks for all your work here,
Stefan
Quoted 37 lines · Marek Behún
From: Marek Behún <[email protected]>
Hello Stefan,
these are another improvements for kwboot, please apply only after series
arm: mvebu: nandpagesize support for kwbimage v1The main improvement is in patch 5, which changes where we inject the code for changing baudrate back to 115200 Baud after fast upload. Instead of injecting it before the main data image, we now inject it after.
This is because there are some kwb images that upload at address 0, and injecting the code before that doesn't work, since there is no RAM mapped at
0xfffff000.Marek & Pali
Pali Rohár (13):
tools: kwboot: Initialize rfds to zero
tools: kwboot: Fix initialization of tty device
tools: kwboot: Reserve enough space for patching kwbimage in memory
tools: kwboot: Validate 4-byte image data checksum
tools: kwboot: Inject baudrate change back code after data part
tools: kwboot: Recalculate 4-byte data checksum after injecting
baudrate code
tools: kwboot: Correctly set configuration of UART for BootROM
messages
tools: kwboot: Show verbose message when waiting for baudrate change
magic
tools: kwboot: Simplify code for aligning image header
tools: kwboot: Do not modify kwbimage header before increasing its
size
tools: kwboot: Calculate real used space in kwbimage header when
callingkwboot_img_grow_hdr()
tools: kwboot: Change retry loop from decreasing to increasing
tools: kwboot: Resend first 3 xmodem retry packets immediately
Quoted 3 lines
tools/kwboot.c | 178 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 120 insertions(+), 58 deletions(-)
Applied to u-boot-marvell/master
Thanks,
Stefan