X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=tools%2Fkwboot.c;h=4be094c9c8d81ebca06170a386718527880a587e;hb=a3c31e98a118f78e06d87311b082e54854ff6537;hp=c5f4492b5f7ab3d4a3b1a609740316cebcb7dae5;hpb=4bbc08f2ecdd16d38f933f202fb1a711fb30d880;p=oweals%2Fu-boot.git diff --git a/tools/kwboot.c b/tools/kwboot.c index c5f4492b5f..4be094c9c8 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -9,10 +9,14 @@ * 2008. Chapter 24.2 "BootROM Firmware". */ +#include "kwbimage.h" +#include "mkimage.h" + #include #include #include #include +#include #include #include #include @@ -22,8 +26,6 @@ #include #include -#include "kwbimage.h" - #ifdef __GNUC__ #define PACKED __attribute((packed)) #else @@ -74,6 +76,7 @@ static int kwboot_verbose; static int msg_req_delay = KWBOOT_MSG_REQ_DELAY; static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO; +static int blk_rsp_timeo = KWBOOT_BLK_RSP_TIMEO; static void kwboot_printv(const char *fmt, ...) @@ -179,7 +182,7 @@ kwboot_tty_recv(int fd, void *buf, size_t len, int timeo) } n = read(fd, buf, len); - if (n < 0) + if (n <= 0) goto out; buf = (char *)buf + n; @@ -283,6 +286,7 @@ kwboot_bootmsg(int tty, void *msg) { int rc; char c; + int count; if (msg == NULL) kwboot_printv("Please reboot the target into UART boot mode..."); @@ -294,10 +298,12 @@ kwboot_bootmsg(int tty, void *msg) if (rc) break; - rc = kwboot_tty_send(tty, msg, 8); - if (rc) { - usleep(msg_req_delay * 1000); - continue; + for (count = 0; count < 128; count++) { + rc = kwboot_tty_send(tty, msg, 8); + if (rc) { + usleep(msg_req_delay * 1000); + continue; + } } rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo); @@ -378,7 +384,7 @@ kwboot_xm_sendblock(int fd, struct kwboot_block *block) break; do { - rc = kwboot_tty_recv(fd, &c, 1, KWBOOT_BLK_RSP_TIMEO); + rc = kwboot_tty_recv(fd, &c, 1, blk_rsp_timeo); if (rc) break; @@ -423,6 +429,9 @@ kwboot_xmodem(int tty, const void *_data, size_t size) kwboot_printv("Sending boot image...\n"); + sleep(2); /* flush isn't effective without it */ + tcflush(tty, TCIOFLUSH); + do { struct kwboot_block block; int n; @@ -463,7 +472,7 @@ kwboot_term_pipe(int in, int out, char *quit, int *s) char _buf[128], *buf = _buf; nin = read(in, buf, sizeof(buf)); - if (nin < 0) + if (nin <= 0) return -1; if (quit) { @@ -674,7 +683,7 @@ static void kwboot_usage(FILE *stream, char *progname) { fprintf(stream, - "Usage: %s [-d | -a | -q | -s | -b | -D ] [ -t ] [-B ] \n", + "Usage: %s [OPTIONS] [-b | -D ] [-B ] \n", progname); fprintf(stream, "\n"); fprintf(stream, @@ -686,6 +695,8 @@ kwboot_usage(FILE *stream, char *progname) fprintf(stream, " -a: use timings for Armada XP\n"); fprintf(stream, " -q : use specific request-delay\n"); fprintf(stream, " -s : use specific response-timeout\n"); + fprintf(stream, + " -o : use specific xmodem block timeout\n"); fprintf(stream, "\n"); fprintf(stream, " -t: mini terminal\n"); fprintf(stream, "\n"); @@ -718,7 +729,7 @@ main(int argc, char **argv) kwboot_verbose = isatty(STDOUT_FILENO); do { - int c = getopt(argc, argv, "hb:ptaB:dD:q:s:"); + int c = getopt(argc, argv, "hb:ptaB:dD:q:s:o:"); if (c < 0) break; @@ -758,6 +769,10 @@ main(int argc, char **argv) msg_rsp_timeo = atoi(optarg); break; + case 'o': + blk_rsp_timeo = atoi(optarg); + break; + case 'B': speed = kwboot_tty_speed(atoi(optarg)); if (speed == -1) @@ -812,7 +827,7 @@ main(int argc, char **argv) perror("debugmsg"); goto out; } - } else { + } else if (bootmsg) { rc = kwboot_bootmsg(tty, bootmsg); if (rc) { perror("bootmsg");