[U-Boot-Users] [PATCH 1/6] binary upload tool

Robert Schwebel robert at pengutronix.de
Tue Dec 9 20:02:12 CET 2003


# 
# Author:	Robert Schwebel <r.schwebel at pengutronix.de>
# 
# Description:	Binary upload tool by Chris Hallinan
#
# State:	2003-12-09: submit
#


#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#

--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ u-boot-patches/tools/binupld.c	2003-12-09 18:59:59.000000000 +0100
@@ -0,0 +1,204 @@
+/* This utility downloads a binary file from Minicom to
+ * the serial port. It supports the Xon-Xoff software
+ * flow control protocol to use the highest possible speed
+ *
+ * (C) Copyright 2001, 2002 DS4.COM, Inc.
+ *     Chris Hallinan clh at net1plus.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * To use this utility with Minicom, add the entry in Minicom's
+ * File Transfer Protocol as follows:
+ * Type Ctl-A, O (enter Configuration menu)
+ * Select File transfer protocols from menu
+ * Add the entry for binupld to look like the following (Item K)
+ *
+ *      Name             Program                 Name U/D FullScr IO-Red. Multi
+ *  A  zmodem     /usr/bin/sz -vv -b              Y    U    N       Y       Y
+ *  B  ymodem     /usr/bin/sb -vv                 Y    U    N       Y       Y
+ *  C  xmodem     /usr/bin/sx -vv                 Y    U    N       Y       N
+ *  D  zmodem     /usr/bin/rz -vv -b -E           N    D    N       Y       Y
+ *  E  ymodem     /usr/bin/rb -vv                 N    D    N       Y       Y
+ *  F  xmodem     /usr/bin/rx -vv                 Y    D    N       Y       N
+ *  G  kermit     /usr/bin/kermit -i -l %l -s     Y    U    Y       N       N
+ *  H  kermit     /usr/bin/kermit -i -l %l -r     N    D    Y       N       N
+ *  I  ascii      /usr/bin/ascii-xfr -dsv         Y    U    N       Y       N
+ *  J  srecdnld   /usr/bin/srecdnl                Y    U    N       Y       N
+ *  K  binupld    /usr/bin/binupld                Y    U    N       Y       N
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <asm/errno.h>
+
+#define BUFSZ 1024
+#define TXBLK_SIZE 32
+#define XON 0x11		/* ASCII DC1 character */
+#define XOFF  0x13		/* ASCII DC3 character */
+
+#define USE_STDERR
+#undef USE_STDOUT
+
+#ifdef USE_STDERR
+#define ERR_OUT stderr
+#else
+#define ERR_OUT err_fp
+#define ERR_DEVICE "/dev/pts/0"
+#endif
+
+#ifdef USE_STDOUT
+#define LINE_OUT stdout
+#else
+#define LINE_OUT tty_fp
+#endif
+
+int
+main(int argc, char **argv)
+{
+	int bin_fd, i, fsize, nResult, count;
+	struct stat fst;
+	char lbuf;
+	int stepval, done, xoff, msgbidx = 0;
+	fd_set rfds;
+	struct timeval tv;
+	static char msgbuf[2048];
+	static int got_xoff = 0;
+
+#ifndef USE_STDOUT
+	int LINE_OUT;
+#endif
+
+#ifndef USE_STDERR
+	FILE *ERR_OUT;
+
+	ERR_OUT = fopen(ERR_DEVICE, "w");
+	if (ERR_OUT == NULL) {
+		perror("Error opening error output device");
+		return -1;
+	}
+#endif
+
+#ifndef USE_STDOUT
+	LINE_OUT = open("/dev/ttyS0", O_RDWR);
+	if (LINE_OUT == 1) {
+		perror("Error opening serial output device");
+		return -1;
+	}
+#endif
+
+	if (argc != 2) {
+		fprintf(ERR_OUT, "Bad args\n");
+		return -1;
+	}
+
+	if (strlen(argv[1]) < 1) {
+		fprintf(ERR_OUT, "Bad file name\n");
+		return -1;
+	}
+
+	bin_fd = open(argv[1], O_RDONLY);
+	if (bin_fd == 1) {
+		perror("Open failed");
+		return -1;
+	}
+
+	/* Get file size */
+	i = fstat(bin_fd, &fst);
+	if (i == -1) {
+		perror("stat failed");
+		close(bin_fd);
+		return -1;
+	}
+	fsize = fst.st_size;
+	stepval = 100;
+
+	/* Now ready for the file transfer! */
+	fprintf(ERR_OUT, "\nUploading from %s --- xxxxxxx", argv[1]);
+
+	i = 0;
+	done = 0;
+	xoff = 0;
+	while (!done) {
+		if (!xoff) {
+			count = read(bin_fd, &lbuf, TXBLK_SIZE);
+			if (count == 0) {
+				done = 1;
+				break;
+			}
+
+			/* Write the output byte to tty port */
+			if (write(LINE_OUT, &lbuf, count) != count) {
+				fprintf(ERR_OUT,
+					"Aw shit, binary write failed\n");
+				return -1;
+			}
+		}
+
+#if 1		/* Delete if you don't need XON/XOFF spt */
+		/* Setup for watching serial line input */
+		FD_ZERO(&rfds);
+		FD_SET(LINE_OUT, &rfds);
+		/* Wait up to five hundred microseconds. */
+		tv.tv_sec = 0;
+		tv.tv_usec = 500;
+		nResult = select(LINE_OUT + 1, &rfds, NULL, NULL, &tv);
+		if (nResult == -1) {
+			perror("Select failed");
+			return -1;
+		}
+
+		if (nResult && FD_ISSET(LINE_OUT, &rfds)) {
+			char c = getchar();
+			/* Character received from serial port */
+			switch (c) {
+			case XOFF:
+				xoff = 1;
+				got_xoff = 1;
+				break;
+			case XON:
+				xoff = 0;
+				break;
+			default:
+				msgbuf[msgbidx++] = c;
+				/* fprintf(ERR_OUT, "                    Data [%02x]\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", c); */
+				break;
+			}
+		}
+#endif
+
+		/* Display download progress */
+		i += count;
+		fprintf(ERR_OUT, "\b\b\b\b\b\b\b%07d", i);
+	}
+
+	fprintf(ERR_OUT, " - Done\n");
+	msgbuf[msgbidx] = '\0';
+	if (strlen(msgbuf))
+		fprintf(ERR_OUT, "Msgbuf: %s\n", msgbuf);
+
+	/* Report if we got an XOFF */
+	if (got_xoff)
+		fprintf(ERR_OUT, "Got XOFF\n");
+
+	close(bin_fd);
+	return 0;
+}




More information about the U-Boot mailing list