# HG changeset patch # User Michael Spacefalcon # Date 1367643125 0 # Node ID aca1948e9713341fd3b02d937601fdc135e59b06 # Parent e658a84b37df365446e05f180168250e39a2d7fb loadtool: initial version compiles and links diff -r e658a84b37df -r aca1948e9713 loadtools/Makefile --- a/loadtools/Makefile Sat May 04 04:36:29 2013 +0000 +++ b/loadtools/Makefile Sat May 04 04:52:05 2013 +0000 @@ -1,17 +1,20 @@ CC= gcc CFLAGS= -O2 -PROGS= fc-sertool +PROGS= fc-loadtool fc-sertool SERTOOL_OBJS= defpath.o hexdecode.o hwparam.o romload.o sercomm.o sertool.o \ srecreader.o ttypassthru.o LOADTOOL_OBJS= defpath.o hexdecode.o hwparam.o ltdispatch.o ltmain.o \ - romload.o sercomm.o srecreader.o tpinterf.o + ltpassthru.o romload.o sercomm.o srecreader.o tpinterf.o -all: ${PROGS} ${LOADTOOL_OBJS} +all: ${PROGS} fc-sertool: ${SERTOOL_OBJS} ${CC} -o $@ ${SERTOOL_OBJS} +fc-loadtool: ${LOADTOOL_OBJS} + ${CC} -o $@ ${LOADTOOL_OBJS} + clean: rm -f *.o *.out *errs ${PROGS} diff -r e658a84b37df -r aca1948e9713 loadtools/ltmain.c --- a/loadtools/ltmain.c Sat May 04 04:36:29 2013 +0000 +++ b/loadtools/ltmain.c Sat May 04 04:52:05 2013 +0000 @@ -51,11 +51,8 @@ open_target_serial(); perform_romload(); putchar('\n'); - if (tpinterf_pass_output() < 0) { - fprintf(stderr, - "loadtool error: no '=' prompt received from target\n"); + if (tpinterf_pass_output(1) < 0) exit(1); - } for (;;) { if (isatty(0)) { fputs("loadtool> ", stdout); diff -r e658a84b37df -r aca1948e9713 loadtools/ltpassthru.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/loadtools/ltpassthru.c Sat May 04 04:52:05 2013 +0000 @@ -0,0 +1,19 @@ +/* + * This module contains the loadtool_cmd_passthru() function, + * which implements the simplest commands that pass directly + * through to loadagent. + */ + +#include + +loadtool_cmd_passthru(argc, argv) + char **argv; +{ + if (tpinterf_make_cmd(argv) < 0) { + fprintf(stderr, "error: unable to form target command\n"); + return(-1); + } + if (tpinterf_send_cmd() < 0) + return(-1); + return tpinterf_pass_output(1); +} diff -r e658a84b37df -r aca1948e9713 loadtools/tpinterf.c --- a/loadtools/tpinterf.c Sat May 04 04:36:29 2013 +0000 +++ b/loadtools/tpinterf.c Sat May 04 04:52:05 2013 +0000 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -102,20 +103,24 @@ if (errno == EINTR) continue; perror("select"); - exit(1); + return(-1); } - if (cc < 1) + if (cc < 1) { + fprintf(stderr, + "error: timeout waiting for command echo\n"); return(-1); + } cc = read(target_fd, echobuf + rcvd, cmdlen + 2 - rcvd); if (cc <= 0) { perror("read after successful select"); - exit(1); + return(-1); } rcvd += cc; } - if (bcmp(echobuf, cmdbuf, cmdlen + 2)) + if (bcmp(echobuf, cmdbuf, cmdlen + 2)) { + fprintf(stderr, "error: command echo mismatch\n"); return(-1); - else + } else return(0); } @@ -124,39 +129,45 @@ * '=' prompt is received. All intermediate output is passed to * stdout. * - * Return value: 0 if '=' prompt received, -1 otherwise (timeout) + * Return value: 0 if '=' prompt received immediately, + * positive if some scribble came before the prompt, -1 on errors + * (timeout, read errors, etc). */ -tpinterf_pass_output() +tpinterf_pass_output(timeout) { char buf[512], *cp; fd_set fds; struct timeval tv; - int cc, newline = 1; + int cc, newline = 1, totout = 0; for (;;) { FD_ZERO(&fds); FD_SET(target_fd, &fds); - tv.tv_sec = 1; + tv.tv_sec = timeout; tv.tv_usec = 0; cc = select(target_fd+1, &fds, NULL, NULL, &tv); if (cc < 0) { if (errno == EINTR) continue; perror("select"); - exit(1); + return(-1); } - if (cc < 1) + if (cc < 1) { + fprintf(stderr, + "error: timeout waiting for \'=\' prompt from target\n"); return(-1); + } cc = read(target_fd, buf, sizeof buf); if (cc <= 0) { perror("read after successful select"); - exit(1); + return(-1); } for (cp = buf; cc; cp++) { cc--; if (*cp == '=' && newline && !cc) - return(0); + return(totout); putchar(*cp); + totout++; if (*cp == '\n') newline = 1; else