FreeCalypso > hg > freecalypso-tools
changeset 633:4dca8542f569
loadtools/romload.c: collect additional response bytes after >p and >c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 01 Mar 2020 00:57:12 +0000 |
parents | ae4330d86029 |
children | 82e9f2bd8f6e |
files | loadtools/romload.c |
diffstat | 1 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/loadtools/romload.c Sat Feb 29 23:53:33 2020 +0000 +++ b/loadtools/romload.c Sun Mar 01 00:57:12 2020 +0000 @@ -150,6 +150,38 @@ return 0; } +static int +expect_add_response(buf, expect_bytes, timeout) + u_char *buf; +{ + fd_set fds; + struct timeval tv; + int pass, cc; + + for (pass = 0; pass < expect_bytes; ) { + FD_ZERO(&fds); + FD_SET(target_fd, &fds); + tv.tv_sec = 0; + tv.tv_usec = timeout * 1000; + cc = select(target_fd+1, &fds, NULL, NULL, &tv); + if (cc < 0) { + if (errno == EINTR) + continue; + perror("select"); + exit(1); + } + if (cc < 1) + return(-1); + cc = read(target_fd, buf + pass, expect_bytes - pass); + if (cc <= 0) { + perror("read after successful select"); + exit(1); + } + pass += cc; + } + return(0); +} + static uint32_t compute_block_cksum() { @@ -168,6 +200,7 @@ int resp; uint16_t image_cksum; unsigned long rec_count; + u_char addresp[2]; static int zero = 0; if (open_srec_file(&iramimage) < 0) @@ -195,6 +228,12 @@ resp); exit(1); } + resp = expect_add_response(addresp, 2, INTERMEDIATE_TIMEOUT); + if (resp < 0 || addresp[0] != 0x00 || addresp[1] != 0x04) { + fprintf(stderr, + "error: extra bytes after >p not received as expected\n"); + exit(1); + } printf("<p command successful, switching to %s baud\n", romload_baud_rate->name); set_serial_baudrate(romload_baud_rate); @@ -290,6 +329,12 @@ resp); exit(1); } + resp = expect_add_response(addresp, 1, INTERMEDIATE_TIMEOUT); + if (resp < 0) { + fprintf(stderr, + "error: extra byte after >c not received as expected\n"); + exit(1); + } printf("<c command successful, sending <b\n"); bcopy(iramimage.record + 1, branch_cmd + 2, 4);