From dd8b2eadab12965d232640449b1d1c9f2484238c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 30 Nov 2012 17:36:40 -0800 Subject: ao-tools: Add ao-sky-flash to update GPS firmware This uses a new feature of AltOS to directly connect the GPS chip to the USB link to reprogram the former. Signed-off-by: Keith Packard --- ao-tools/ao-sky-flash/sky_bin.c | 75 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 ao-tools/ao-sky-flash/sky_bin.c (limited to 'ao-tools/ao-sky-flash/sky_bin.c') diff --git a/ao-tools/ao-sky-flash/sky_bin.c b/ao-tools/ao-sky-flash/sky_bin.c new file mode 100644 index 00000000..e693c892 --- /dev/null +++ b/ao-tools/ao-sky-flash/sky_bin.c @@ -0,0 +1,75 @@ +/* + * Copyright © 2012 Keith Packard + * + * 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; version 2 of the License. + * + * 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. + */ + +#include "sky_flash.h" +#include +#include + +#define FLASHBYTES 8192 + +int +skytraq_send_bin(int fd, const char *filename) +{ + FILE *file; + char buf[FLASHBYTES]; + int count; + unsigned char cksum; + int c; + long size; + long pos; + char message[1024]; + int ret; + + file = fopen(filename, "r"); + if (!file) { + perror(filename); + return -1; + } + + printf ("computing checksum...\n"); fflush(stdout); + /* Compute checksum, figure out how long the file */ + cksum = 0; + while ((c = getc(file)) != EOF) + cksum += (unsigned char) c; + size = ftell(file); + rewind(file); + printf ("checksum: %d\n", cksum); fflush(stdout); + + sprintf(message, "BINSIZE = %d Checksum = %d Loopnumber = %d ", size, cksum, 1); + + ret = skytraq_cmd_wait(fd, message, strlen(message) + 1, "OK", 20000); + if (ret < 0) + printf ("waitstatus failed %d\n", ret); + + pos = 0; + for (;;) { + count = fread(buf, 1, sizeof (buf), file); + if (count < 0) { + perror("fread"); + fclose(file); + return -1; + } + if (count == 0) + break; + printf ("write %ld of %ld ", pos + count, size); fflush(stdout); + pos += count; + ret = skytraq_cmd_wait(fd, buf, count, "OK", 20000); + if (ret < 0) + return ret; + } + return skytraq_waitstatus(fd, "END", 30000); +} -- cgit v1.2.3 From d4d5d411679d074295d4722f4887fd1cf4f0906c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 4 Dec 2012 01:30:39 -0800 Subject: ao-sky-flash: Clean up debug printfs a bit This makes debugging output a bit cleaner Signed-off-by: Keith Packard --- ao-tools/ao-sky-flash/sky_bin.c | 4 +--- ao-tools/ao-sky-flash/sky_serial.c | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'ao-tools/ao-sky-flash/sky_bin.c') diff --git a/ao-tools/ao-sky-flash/sky_bin.c b/ao-tools/ao-sky-flash/sky_bin.c index e693c892..04cfec35 100644 --- a/ao-tools/ao-sky-flash/sky_bin.c +++ b/ao-tools/ao-sky-flash/sky_bin.c @@ -40,14 +40,12 @@ skytraq_send_bin(int fd, const char *filename) return -1; } - printf ("computing checksum...\n"); fflush(stdout); /* Compute checksum, figure out how long the file */ cksum = 0; while ((c = getc(file)) != EOF) cksum += (unsigned char) c; size = ftell(file); rewind(file); - printf ("checksum: %d\n", cksum); fflush(stdout); sprintf(message, "BINSIZE = %d Checksum = %d Loopnumber = %d ", size, cksum, 1); @@ -65,7 +63,7 @@ skytraq_send_bin(int fd, const char *filename) } if (count == 0) break; - printf ("write %ld of %ld ", pos + count, size); fflush(stdout); + skytraq_dbg_printf (0, "%7d of %7d ", pos + count, size); pos += count; ret = skytraq_cmd_wait(fd, buf, count, "OK", 20000); if (ret < 0) diff --git a/ao-tools/ao-sky-flash/sky_serial.c b/ao-tools/ao-sky-flash/sky_serial.c index 4aeb1458..7230bf8c 100644 --- a/ao-tools/ao-sky-flash/sky_serial.c +++ b/ao-tools/ao-sky-flash/sky_serial.c @@ -103,16 +103,14 @@ skytraq_write(int fd, const char *data, int len) int r; int us; + skytraq_dbg_printf (0, "%4d: ", len); + if (len < 70) + skytraq_dbg_buf(0, data, len); while (len) { int this_time = len; if (this_time > 128) this_time = 128; - if (this_time < 70) { - skytraq_dbg_printf (0, "%4d: ", this_time); - skytraq_dbg_buf(0, data, this_time); - } else { - skytraq_dbg_printf (0, "%d bytes (%d remain)", this_time, len); - } + skytraq_dbg_printf(0, "."); fflush(stdout); r = write(fd, data, this_time); if (r <= 0) -- cgit v1.2.3