# HG changeset patch # User Mychaela Falconia # Date 1583024232 0 # Node ID 4dca8542f569bf0089e100d84a017642bf4350e5 # Parent ae4330d86029c0dbe78d52d15e89b48dff43675d loadtools/romload.c: collect additional response bytes after >p and >c diff -r ae4330d86029 -r 4dca8542f569 loadtools/romload.c --- 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("

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("