changeset 638:6562364b2033

loadagent: BINDUMP command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 01 Mar 2020 18:14:56 +0000
parents fa8e197a1d9b
children 963d15a808eb
files target-utils/loadagent/Makefile target-utils/loadagent/bindump.c target-utils/loadagent/cmdtab.c
diffstat 3 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/loadagent/Makefile	Sun Mar 01 05:51:45 2020 +0000
+++ b/target-utils/loadagent/Makefile	Sun Mar 01 18:14:56 2020 +0000
@@ -7,7 +7,7 @@
 INSTDIR=/opt/freecalypso/target-bin
 
 PROG=	loadagent
-OBJS=	crt0.o cmdtab.o main.o
+OBJS=	crt0.o bindump.o cmdtab.o main.o
 LIBS=	../libload/libload.a ../libcommon/libcommon.a ../libprintf/libprintf.a \
 	../libbase/libbase.a ../libc/libc.a
 LIBGCC=	`${CC} -print-file-name=libgcc.a`
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/bindump.c	Sun Mar 01 18:14:56 2020 +0000
@@ -0,0 +1,56 @@
+/*
+ * Here we are going to implement a new memory dump command for use by
+ * fc-loadtool, sending the dump stream to the host in binary instead of hex
+ * S-records.
+ *
+ * We could send the entire stream continuously without any structure or
+ * breaks, but if we did that, fc-loadtool would not be able to detect a slip
+ * (byte loss error) in the serial stream until the end of the dump,
+ * potentially minutes long.  For this reason we are taking a different
+ * approach: we are going to send the dump stream in blocks of 8192 bytes,
+ * with each block preceded by an 8-byte binary header.  Loadtool will know
+ * and expect the same block structure, and seeing our block headers in the
+ * right positions in the stream will provide assurance of synchronization.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+void
+cmd_memdump_binary(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long addr, remlen, blklen;
+	int i;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 8, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	addr = start;
+	for (remlen = length; remlen; remlen -= blklen) {
+		blklen = 8192;
+		if (remlen < blklen)
+			blklen = remlen;
+		serial_out(0x55);
+		serial_out(0xAA);
+		serial_out(addr >> 24);
+		serial_out(addr >> 16);
+		serial_out(addr >> 8);
+		serial_out(addr);
+		serial_out(blklen >> 8);
+		serial_out(blklen);
+		for (; blklen; blklen--) {
+			serial_out(*(volatile u8 *)addr);
+			addr++;
+		}
+	}
+}
--- a/target-utils/loadagent/cmdtab.c	Sun Mar 01 05:51:45 2020 +0000
+++ b/target-utils/loadagent/cmdtab.c	Sun Mar 01 18:14:56 2020 +0000
@@ -18,6 +18,7 @@
 
 extern void cmd_baud_switch();
 extern void cmd_intel_rewrite_sector();
+extern void cmd_memdump_binary();
 extern void cmd_memdump_human();
 extern void cmd_memdump_machine();
 extern void cmd_memload();
@@ -29,6 +30,7 @@
 const struct cmdtab cmdtab[] = {
 	{"AMFB", cmd_AMFB},
 	{"AMFW", cmd_AMFW},
+	{"BINDUMP", cmd_memdump_binary},
 	{"DUMP", cmd_memdump_machine},
 	{"INFB", cmd_INFB},
 	{"INFW", cmd_INFW},