changeset 278:f77480d3dd21

fc-fsio: first ffs2ver command implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 24 Feb 2014 04:41:57 +0000
parents e23fc1228efd
children 36ad667341fc
files rvinterf/etmsync/Makefile rvinterf/etmsync/fsbasics.c rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/interf.c
diffstat 4 files changed, 73 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile	Mon Feb 24 03:42:47 2014 +0000
+++ b/rvinterf/etmsync/Makefile	Mon Feb 24 04:41:57 2014 +0000
@@ -3,7 +3,8 @@
 PROGS=	fc-fsio
 INSTBIN=/usr/local/bin
 
-FSIO_OBJS=	connect.o dispatch.o fscmdtab.o fsiomain.o interf.o launchrvif.o
+FSIO_OBJS=	connect.o dispatch.o fsbasics.o fscmdtab.o fsiomain.o interf.o \
+		launchrvif.o
 
 all:	${PROGS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fsbasics.c	Mon Feb 24 04:41:57 2014 +0000
@@ -0,0 +1,36 @@
+/*
+ * Basic FFS2 operations
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "etm.h"
+#include "ffs.h"
+#include "tmffs2.h"
+#include "exitcodes.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+cmd_ffs2ver()
+{
+	u_char cmdpkt[4];
+	int rc;
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_VERSION;
+	rc = etm_pkt_exch(cmdpkt, 2);
+	if (rc)
+		return(rc);
+	if (rvi_msg[3]) {
+		printf("FFS2 error %d\n", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len != 7) {
+		printf("error: FFS2 version response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	printf("FFS2 version: %02X.%02X\n", rvi_msg[5], rvi_msg[4]);
+	return(0);
+}
--- a/rvinterf/etmsync/fscmdtab.c	Mon Feb 24 03:42:47 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Mon Feb 24 04:41:57 2014 +0000
@@ -6,9 +6,11 @@
 
 extern int cmd_exec();
 extern int cmd_exit();
+extern int cmd_ffs2ver();
 
 struct cmdtab cmdtab[] = {
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, cmd_exit},
+	{"ffs2ver", 0, 0, cmd_ffs2ver},
 	{0, 0, 0, 0}
 };
--- a/rvinterf/etmsync/interf.c	Mon Feb 24 03:42:47 2014 +0000
+++ b/rvinterf/etmsync/interf.c	Mon Feb 24 04:41:57 2014 +0000
@@ -121,3 +121,36 @@
 	}
 	return(0);
 }
+
+etm_pkt_exch(outbuf, outlen)
+	u_char *outbuf;
+{
+	int i, c;
+
+	outbuf[0] = RVT_TM_HEADER;
+	c = 0;
+	for (i = 1; i <= outlen; i++)
+		c ^= outbuf[i];
+	outbuf[i] = c;
+	target_pkt_exch(outbuf, outlen + 2);
+	if (rvi_msg[1] != RVT_TM_HEADER) {
+		printf("error: packet from target is not ETM!\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len < 5) {
+		printf("error: ETM response packet is too short\n");
+		return(ERROR_TARGET);
+	}
+	c = 0;
+	for (i = 2; i < rvi_msg_len; i++)
+		c ^= rvi_msg[i];
+	if (c) {
+		printf("ETM response checksum error!\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[2] != outbuf[1]) {
+		printf("error: target response is from wrong ETM component\n");
+		return(ERROR_TARGET);
+	}
+	return(0);
+}