changeset 23:aca1948e9713

loadtool: initial version compiles and links
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 04 May 2013 04:52:05 +0000
parents e658a84b37df
children 9ee91bc6057c
files loadtools/Makefile loadtools/ltmain.c loadtools/ltpassthru.c loadtools/tpinterf.c
diffstat 4 files changed, 50 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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}
--- 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);
--- /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 <stdio.h>
+
+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);
+}
--- 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 <sys/types.h>
 #include <sys/time.h>
 #include <sys/errno.h>
+#include <stdio.h>
 #include <string.h>
 #include <strings.h>
 #include <stdlib.h>
@@ -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