changeset 650:bf840c984113

fc-xram reworked to use the new binary protocol
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 02 Mar 2020 03:21:41 +0000
parents 141372e0d28f
children 6bb41b4d39ed
files loadtools/Makefile loadtools/chainload.c
diffstat 2 files changed, 43 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/Makefile	Mon Mar 02 02:45:35 2020 +0000
+++ b/loadtools/Makefile	Mon Mar 02 03:21:41 2020 +0000
@@ -23,7 +23,8 @@
 
 XRAM_OBJS=	chainload.o clmain.o compalload.o defexitstub.o defpath.o \
 		flashstubs.o hexdecode.o hwparam.o initscript.o labaud.o \
-		romload.o secondprog.o srecreader.o tpinterf.o ttypassthru.o
+		romload.o secondprog.o srecreader.o tpinterf.o tpinterfb.o \
+		ttypassthru.o
 
 BUZPLAY_OBJS=	bpdispatch.o bpmain.o buzplay.o compalload.o defpath.o \
 		flashstubs.o hexdecode.o hwparam.o labaud.o ltexit.o \
--- a/loadtools/chainload.c	Mon Mar 02 02:45:35 2020 +0000
+++ b/loadtools/chainload.c	Mon Mar 02 03:21:41 2020 +0000
@@ -11,42 +11,33 @@
 #include <time.h>
 #include "srecreader.h"
 
+extern int target_fd;
+
 struct srecreader xramimage;
 
 extern struct baudrate *current_baud_rate;
 extern struct baudrate *xram_run_baudrate;
 extern int xram_jtag_mode;
 
-static void
-make_ml_arg(rec, buf)
-	u_char *rec;
-	char *buf;
-{
-	register int i, len;
-	register char *s;
-
-	len = rec[0] + 1;
-	s = buf;
-	for (i = 0; i < len; i++) {
-		sprintf(s, "%02X", rec[i]);
-		s += 2;
-	}
-	*s = '\0';
-}
-
 perform_chain_load()
 {
-	int resp;
+	int resp, reclen;
 	unsigned long rec_count;
-	char *argv[3], srecarg[516];
+	char *argv[3], jumparg[10];
+	u_char scratch[3], expect_conf[3];
 	time_t start_time, finish_time;
 	unsigned duration, mm, ss;
 
 	if (open_srec_file(&xramimage) < 0)
 		exit(1);
-	argv[0] = "ML";
-	argv[1] = srecarg;
-	argv[2] = 0;
+	/* enter binary RAM download mode */
+	argv[0] = "BINML";
+	argv[1] = 0;
+	tpinterf_make_cmd(argv);
+	if (tpinterf_send_cmd())
+		exit(1);
+	/* read and send S-record image */
+	expect_conf[0] = 0x06;
 	for (rec_count = 0; ; ) {
 		if (read_s_record(&xramimage) < 0)
 			exit(1);
@@ -70,10 +61,8 @@
 				xramimage.record_type);
 			exit(1);
 		}
-		if (xramimage.record_type == '7') {
-			time(&finish_time);
+		if (xramimage.record_type == '7')
 			break;
-		}
 		/* must be S3 */
 		if (xramimage.datalen < 1) {
 			fprintf(stderr,
@@ -85,14 +74,24 @@
 			printf("Each \'.\' is 100 S-records\n");
 			time(&start_time);
 		}
-		make_ml_arg(xramimage.record, srecarg);
-		tpinterf_make_cmd(argv);
-		if (tpinterf_send_cmd())
+		reclen = xramimage.datalen + 6;
+		if (write(target_fd, xramimage.record, reclen) != reclen) {
+			perror("binary write to target");
 			exit(1);
-		if (tpinterf_pass_output(1))
-			exit(1);
+		}
 		rec_count++;
 		if (rec_count % 100 == 0) {
+			scratch[0] = 0x05;	/* ENQ */
+			write(target_fd, scratch, 1);
+			if (collect_binblock_from_target(scratch, 3, 1))
+				exit(1);
+			expect_conf[1] = rec_count >> 8;
+			expect_conf[2] = rec_count;
+			if (bcmp(scratch, expect_conf, 3)) {
+				fprintf(stderr,
+					"error: expected sync mismatch\n");
+				exit(1);
+			}
 			putchar('.');
 			fflush(stdout);
 		}
@@ -106,6 +105,15 @@
 		exit(1);
 	}
 	putchar('\n');	/* newline after the dots */
+	scratch[0] = 0x04;	/* EOT */
+	write(target_fd, scratch, 1);
+	if (collect_binblock_from_target(scratch, 1, 1))
+		exit(1);
+	time(&finish_time);
+	if (scratch[0] != '=') {
+		fprintf(stderr, "error: \'=\' not received as expected\n");
+		exit(1);
+	}
 	duration = finish_time - start_time;
 	mm = duration / 60;
 	ss = duration - mm * 60;
@@ -122,8 +130,10 @@
 		exit(0);
 	}
 	printf("Sending jump command\n");
-	sprintf(srecarg, "%lX", (u_long) xramimage.addr);
+	sprintf(jumparg, "%lX", (u_long) xramimage.addr);
 	argv[0] = "jump";
+	argv[1] = jumparg;
+	argv[2] = 0;
 	tpinterf_make_cmd(argv);
 	if (tpinterf_send_cmd())
 		exit(1);