changeset 260:c146f38d2b5f

rvinterf subdir structure made a little more sensible
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 04:02:13 +0000
parents 35113b1964d3
children 7f14d7c789a7
files .hgignore rvinterf/Makefile rvinterf/etm/Makefile rvinterf/etm/abb.c rvinterf/etm/etm.h rvinterf/etm/etmbasic.c rvinterf/etm/ffs2.c rvinterf/etm/init.c rvinterf/etm/interf.c rvinterf/etm/launchrvif.c rvinterf/etm/localtypes.h rvinterf/etm/main.c rvinterf/etm/misc.c rvinterf/etm/pktsort.c rvinterf/etm/tmcore.c rvinterf/etm/tmffs1.h rvinterf/etm/tmffs2.h rvinterf/etm/ttymagic.c rvinterf/etm/usercmd.c rvinterf/include/etm.h rvinterf/include/localtypes.h rvinterf/include/tmffs1.h rvinterf/include/tmffs2.h rvinterf/tmsh/Makefile rvinterf/tmsh/abb.c rvinterf/tmsh/etmbasic.c rvinterf/tmsh/ffs2.c rvinterf/tmsh/init.c rvinterf/tmsh/interf.c rvinterf/tmsh/launchrvif.c rvinterf/tmsh/main.c rvinterf/tmsh/misc.c rvinterf/tmsh/pktsort.c rvinterf/tmsh/tmcore.c rvinterf/tmsh/ttymagic.c rvinterf/tmsh/usercmd.c
diffstat 36 files changed, 1678 insertions(+), 1678 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Feb 05 00:11:34 2014 +0000
+++ b/.hgignore	Wed Feb 05 04:02:13 2014 +0000
@@ -20,11 +20,11 @@
 ^loadtools/fc-loadtool$
 ^loadtools/fc-xram$
 
-^rvinterf/etm/fc-tmsh$
 ^rvinterf/lowlevel/rvinterf$
 ^rvinterf/lowlevel/rvtdump$
 ^rvinterf/old/etmsend$
 ^rvinterf/old/rvtdump$
+^rvinterf/tmsh/fc-tmsh$
 
 ^target-utils/.*/crt0\.S$
 
--- a/rvinterf/Makefile	Wed Feb 05 00:11:34 2014 +0000
+++ b/rvinterf/Makefile	Wed Feb 05 04:02:13 2014 +0000
@@ -1,4 +1,4 @@
-SUBDIR=	etm lowlevel
+SUBDIR=	lowlevel tmsh
 
 all:	${SUBDIR}
 
--- a/rvinterf/etm/Makefile	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-CC=	gcc
-CFLAGS=	-O2
-PROGS=	fc-tmsh
-INSTBIN=/usr/local/bin
-
-TMSH_OBJS=	abb.o etmbasic.o ffs2.o init.o interf.o launchrvif.o main.o \
-		misc.o pktsort.o tmcore.o ttymagic.o usercmd.o
-
-all:	${PROGS}
-
-fc-tmsh:	${TMSH_OBJS}
-	${CC} ${CFLAGS} -o $@ ${TMSH_OBJS}
-
-install:	${PROGS}
-	mkdir -p ${INSTBIN}
-	install -c ${PROGS} ${INSTBIN}
-
-clean:
-	rm -f *.o *.out *errs ${PROGS}
--- a/rvinterf/etm/abb.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * In this module we are going to implement commands dealing with the ABB.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "../include/limits.h"
-#include "localtypes.h"
-#include "etm.h"
-
-extern u_char rvi_msg[];
-extern int rvi_msg_len;
-
-void
-cmd_abbr(argc, argv)
-	char **argv;
-{
-	u32 page, reg;
-	u_char cmdpkt[5];
-
-	page = strtoul(argv[1], 0, 0);
-	reg = strtoul(argv[2], 0, 0);
-	if (page > 1 || reg > 31) {
-		printf("error: argument(s) out of range\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_CODEC_RD;
-	cmdpkt[3] = page << 5 | reg;
-	send_etm_cmd(cmdpkt, 3);
-}
-
-void
-abbr_response()
-{
-	unsigned pg, reg, val;
-	char buf[80];
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("abbr error");
-		return;
-	}
-	if (rvi_msg_len != 9) {
-		print_etm_pkt_raw("abbr malformed resp");
-		return;
-	}
-	pg = rvi_msg[5] >> 5;
-	reg = rvi_msg[5] & 0x1F;
-	val = rvi_msg[6] | rvi_msg[7] << 8;
-	sprintf(buf, "abbr %u %u: %03X", pg, reg, val);
-	async_msg_output(buf);
-}
-
-void
-cmd_abbw(argc, argv)
-	char **argv;
-{
-	u32 page, reg, val;
-	u_char cmdpkt[7];
-
-	page = strtoul(argv[1], 0, 0);
-	reg = strtoul(argv[2], 0, 0);
-	val = strtoul(argv[3], 0, 16);
-	if (page > 1 || reg > 31 || val > 0x3FF) {
-		printf("error: argument(s) out of range\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_CODEC_WR;
-	cmdpkt[3] = page << 5 | reg;
-	cmdpkt[4] = val;
-	cmdpkt[5] = val >> 8;
-	send_etm_cmd(cmdpkt, 5);
-}
-
-void
-abbw_response()
-{
-	unsigned pg, reg;
-	char buf[80];
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("abbw error");
-		return;
-	}
-	if (rvi_msg_len != 7) {
-		print_etm_pkt_raw("abbw malformed resp");
-		return;
-	}
-	pg = rvi_msg[5] >> 5;
-	reg = rvi_msg[5] & 0x1F;
-	sprintf(buf, "abbw %u %u OK", pg, reg);
-	async_msg_output(buf);
-}
--- a/rvinterf/etm/etm.h	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-/*
- * This header file contains various definitions for talking to ETM.
- */
-
-#define	ETM_USE_ID	0x001E0004
-
-/* ETM Module IDs */
-enum {
-    ETM_TM3        = 0x00, // Use of old TM3 protocol
-    ETM_CORE       = 0x01,
-    ETM_TMT        = 0x02, // Pseudo module
-    ETM_SH         = 0x03, // Pseudo module
-    ETM_TM3_MISC   = 0x04, // Pseudo module - Target side
-    ETM_RF         = 0x05, 
-    ETM_IMEI       = 0x06,
-    ETM_FFS2       = 0x07,
-    ETM_AUDIO      = 0x08,
-    ETM_TPU        = 0x09, // Not official part ETM
-    ETM_PWR        = 0x0A,
-    ETM_BT         = 0x0B,
-    ETM_L23        = 0x0C,
-    ETM_RESERVED10 = 0x0D,
-    ETM_RESERVED11 = 0x0E,
-    ETM_RESERVED12 = 0x0F,
-
-    ETM_CUST       = 0xC0, // Customize id
-    ETM_CUST1      = 0xC1, // Customize id
-    ETM_CUST2      = 0xC2, // Customize id
-    ETM_CUST3      = 0xC3, // Customize id
-    ETM_CUST4      = 0xC4, // Customize id
-    ETM_CUST5      = 0xC5, // Customize id
-    ETM_CUST6      = 0xC6, // Customize id
-    ETM_CUST7      = 0xC7, // Customize id
-    ETM_CUST8      = 0xC8, // Customize id
-
-    ETM_TEST       = 0xAA, // used for test of dll's
-    ETM_TASK       = 0xEE, // ETM TASK in Target
-
-    ETM_FFS1       = 0x70
-};
-
-/* ETM_CORE opcodes */
-#define	TMCORE_OPC_MEM		0x61
-#define	TMCORE_OPC_ECHO		0x62
-#define	TMCORE_OPC_RESET	0x63
-#define	TMCORE_OPC_DEBUG	0x64
-#define	TMCORE_OPC_VERSION	0x65
-#define	TMCORE_OPC_CODEC_RD	0x66
-#define	TMCORE_OPC_CODEC_WR	0x67
-#define	TMCORE_OPC_DIEID	0x68
--- a/rvinterf/etm/etmbasic.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-/*
- * Basic ETM interaction
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "../include/limits.h"
-#include "etm.h"
-
-extern u_char rvi_msg[];
-extern int rvi_msg_len;
-
-void
-print_etm_pkt_raw(err)
-	char *err;
-{
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
-	int i;
-
-	sprintf(buf, "%s:", err);
-	dp = index(buf, '\0');
-	for (i = 2; i < rvi_msg_len; i++) {
-		sprintf(dp, " %02X", rvi_msg[i]);
-		dp += 3;
-	}
-	async_msg_output(buf);
-}
-
-void
-etm_packet_rx()
-{
-	int i, c;
-
-	if (rvi_msg_len < 4) {
-runt:		print_etm_pkt_raw("ETM Runt");
-		return;
-	}
-	c = 0;
-	for (i = 2; i < rvi_msg_len; i++)
-		c ^= rvi_msg[i];
-	if (c) {
-		print_etm_pkt_raw("BAD CKSUM");
-		return;
-	}
-	switch (rvi_msg[2]) {
-	case ETM_CORE:
-		if (rvi_msg_len < 6)
-			goto runt;
-		tmcore_msg_rx();
-		return;
-	case ETM_FFS1:
-		print_etm_pkt_raw("FFS1");
-		return;
-	case ETM_FFS2:
-		print_etm_pkt_raw("FFS2");
-		return;
-	default:
-		print_etm_pkt_raw("ETM Unknown");
-	}
-}
-
-void
-cmd_etmpkt(argc, argv)
-	char **argv;
-{
-	u_char pkt[MAX_PKT_TO_TARGET];
-	int di, c, b;
-	char **ap;
-
-	pkt[0] = RVT_TM_HEADER;
-	di = 1;
-	c = 0;
-	for (ap = argv + 1; *ap; ap++) {
-		b = strtoul(*ap, 0, 16);
-		pkt[di++] = b;
-		c ^= b;
-	}
-	pkt[di++] = c;
-	send_pkt_to_target(pkt, di);
-}
-
-void
-send_etm_cmd(buf, len)
-	u_char *buf;
-{
-	int i, c;
-
-	buf[0] = RVT_TM_HEADER;
-	c = 0;
-	for (i = 1; i <= len; i++)
-		c ^= buf[i];
-	buf[i] = c;
-	send_pkt_to_target(buf, len + 2);
-}
--- a/rvinterf/etm/ffs2.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-/*
- * In this module we are going to implement TMFFS2 functionality.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "../include/limits.h"
-#include "localtypes.h"
-#include "etm.h"
-#include "tmffs2.h"
-
-void
-cmd_ffs2_close(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[5];
-
-	cmdpkt[1] = ETM_FFS2;
-	cmdpkt[2] = TMFFS_CLOSE;
-	cmdpkt[3] = strtoul(argv[1], 0, 0);
-	send_etm_cmd(cmdpkt, 3);
-}
-
-void
-cmd_ffs2_delete(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
-	int slen;
-
-	slen = strlen(argv[1]);
-	if (slen >= TMFFS_STRING_SIZE) {
-		printf("error: argument exceeds string length limit\n");
-		return;
-	}
-	dp = cmdpkt + 1;
-	*dp++ = ETM_FFS2;
-	*dp++ = TMFFS_REMOVE;
-	*dp++ = slen + 1;
-	strcpy(dp, argv[1]);
-	dp += slen + 1;
-	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
-}
-
-void
-cmd_ffs2_format(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
-	int slen;
-
-	slen = strlen(argv[1]);
-	if (slen >= TMFFS_STRING_SIZE) {
-		printf("error: argument exceeds string length limit\n");
-		return;
-	}
-	dp = cmdpkt + 1;
-	*dp++ = ETM_FFS2;
-	*dp++ = TMFFS_FORMAT;
-	*dp++ = slen + 1;
-	strcpy(dp, argv[1]);
-	dp += slen + 1;
-	/* magic is 0x2BAD, 16-bit little-endian */
-	*dp++ = 0xAD;
-	*dp++ = 0x2B;
-	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
-}
-
-void
-cmd_ffs2_open(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
-	int slen;
-
-	slen = strlen(argv[1]);
-	if (slen >= TMFFS_STRING_SIZE) {
-		printf("error: argument exceeds string length limit\n");
-		return;
-	}
-	dp = cmdpkt + 1;
-	*dp++ = ETM_FFS2;
-	*dp++ = TMFFS_OPEN;
-	*dp++ = slen + 1;
-	strcpy(dp, argv[1]);
-	dp += slen + 1;
-	*dp++ = strtoul(argv[2], 0, 16);
-	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
-}
-
-void
-cmd_ffs2_preformat()
-{
-	u_char cmdpkt[6];
-
-	cmdpkt[1] = ETM_FFS2;
-	cmdpkt[2] = TMFFS_PREFORMAT;
-	/* magic is 0xDEAD, 16-bit little-endian */
-	cmdpkt[3] = 0xAD;
-	cmdpkt[4] = 0xDE;
-	send_etm_cmd(cmdpkt, 4);
-}
-
-void
-cmd_ffs2_version()
-{
-	u_char cmdpkt[4];
-
-	cmdpkt[1] = ETM_FFS2;
-	cmdpkt[2] = TMFFS_VERSION;
-	send_etm_cmd(cmdpkt, 2);
-}
-
-static struct cmdtab {
-	char *cmd;
-	int minargs;
-	int maxargs;
-	void (*func)();
-} ffs2_cmds[] = {
-	{"close", 1, 1, cmd_ffs2_close},
-	{"delete", 1, 1, cmd_ffs2_delete},
-	{"format", 1, 1, cmd_ffs2_format},
-	{"open", 2, 2, cmd_ffs2_open},
-	{"preformat", 0, 0, cmd_ffs2_preformat},
-	{"version", 0, 0, cmd_ffs2_version},
-	{0, 0, 0, 0}
-};
-
-void
-cmd_ffs2(argc, argv)
-	char **argv;
-{
-	struct cmdtab *tp;
-	int extargs;
-
-	for (tp = ffs2_cmds; tp->cmd; tp++)
-		if (!strcmp(tp->cmd, argv[1]))
-			break;
-	if (!tp->func) {
-		printf("error: no such ffs2 command\n");
-		return;
-	}
-	extargs = argc - 2;
-	if (extargs > tp->maxargs) {
-		printf("error: too many arguments\n");
-		return;
-	}
-	if (extargs < tp->minargs) {
-		printf("error: too few arguments\n");
-		return;
-	}
-	tp->func(argc - 1, argv + 1);
-}
--- a/rvinterf/etm/init.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/*
- * This module contains the initialization code for fc-tmsh.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "../include/pktmux.h"
-#include "../include/localsock.h"
-
-extern char *socket_pathname;
-extern int sock;
-
-connect_local_socket()
-{
-	/* local socket binding voodoo copied from osmocon */
-	struct sockaddr_un local;
-	unsigned int namelen;
-	int rc;
-
-	sock = socket(AF_UNIX, SOCK_STREAM, 0);
-	if (sock < 0) {
-		perror("socket(AF_UNIX, SOCK_STREAM, 0)");
-		exit(1);
-	}
-
-	local.sun_family = AF_UNIX;
-	strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
-	local.sun_path[sizeof(local.sun_path) - 1] = '\0';
-
-	/* we use the same magic that X11 uses in Xtranssock.c for
-	 * calculating the proper length of the sockaddr */
-#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
-	local.sun_len = strlen(local.sun_path);
-#endif
-#if defined(BSD44SOCKETS) || defined(SUN_LEN)
-	namelen = SUN_LEN(&local);
-#else
-	namelen = strlen(local.sun_path) +
-		  offsetof(struct sockaddr_un, sun_path) + 1;
-#endif
-
-	rc = connect(sock, (struct sockaddr *) &local, namelen);
-	if (rc != 0) {
-		perror(socket_pathname);
-		exit(1);
-	}
-
-	return(0);
-}
-
-send_init_command(cmdpkt, cmdlen)
-	u_char *cmdpkt;
-{
-	u_char lenbuf[2];
-
-	lenbuf[0] = 0;
-	lenbuf[1] = cmdlen;
-	write(sock, lenbuf, 2);
-	write(sock, cmdpkt, cmdlen);
-}
-
-init()
-{
-	static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE,
-					  0xFF, 0xFF, 0xFF, 0xFF,
-					  0x00, 0x00, 0x00, 0x00};
-	static u_char want_rvt_etm[9]  = {CLI2RVI_WANT_RVTRACE,
-					  0xFF, 0xFF, 0xFF, 0xFF,
-					  0x00, 0x1E, 0x00, 0x04};
-	static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER};
-
-	if (!sock)
-		connect_local_socket();
-	localsock_prep_for_length_rx();
-	send_init_command(want_rvt_lost, 9);
-	send_init_command(want_rvt_etm, 9);
-	send_init_command(want_etm_mux, 2);
-}
--- a/rvinterf/etm/interf.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,106 +0,0 @@
-/*
- * This module implements the link to rvinterf.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "../include/localsock.h"
-
-extern int sock;
-
-u_char rvi_msg[LOCALSOCK_MAX_MSG];
-int rvi_msg_len;
-
-static int rx_state, rx_left;
-static u_char *rx_ptr;
-
-void
-localsock_prep_for_length_rx()
-{
-	rx_state = 0;
-	rx_ptr = rvi_msg;
-	rx_left = 2;
-}
-
-static void
-prep_for_message_rx()
-{
-	rx_state = 1;
-	rx_ptr = rvi_msg;
-	rx_left = rvi_msg_len;
-}
-
-void
-process_msg_from_rvinterf()
-{
-	switch (rvi_msg[0]) {
-	case RVI2CLI_PKT_FROM_TARGET:
-		process_pkt_from_target();
-		return;
-	case RVI2CLI_LOCAL_CMD_RESP:
-		if (rvi_msg_len < 2)
-			goto bad;
-		if (rvi_msg[1] == '+')
-			return;
-		tty_cleanup();
-		fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1,
-			rvi_msg + 1);
-		exit(1);
-	default:
-	bad:
-		tty_cleanup();
-		fprintf(stderr,
-			"Error: unexpected message type %02X from rvinterf\n",
-			rvi_msg[0]);
-		exit(1);
-	}
-}
-
-void
-handle_rvinterf_input()
-{
-	int cc;
-
-	cc = read(sock, rx_ptr, rx_left);
-	if (cc <= 0) {
-		tty_cleanup();
-		perror("read from rvinterf socket");
-		exit(1);
-	}
-	rx_ptr += cc;
-	rx_left -= cc;
-	if (rx_left)
-		return;
-	/* got the thing, process it */
-	if (rx_state) {
-		process_msg_from_rvinterf();
-		localsock_prep_for_length_rx();
-	} else {
-		rvi_msg_len = rvi_msg[0] << 8 | rvi_msg[1];
-		if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) {
-			tty_cleanup();
-			fprintf(stderr,
-				"Invalid length from rvinterf: %02X%02X\n",
-				rvi_msg[0], rvi_msg[1]);
-			exit(1);
-		}
-		prep_for_message_rx();
-	}
-}
-
-void
-send_pkt_to_target(pkt, pktlen)
-	u_char *pkt;
-{
-	u_char hdrbuf[3];
-	int len1;
-
-	len1 = pktlen + 1;
-	hdrbuf[0] = len1 >> 8;
-	hdrbuf[1] = len1 & 0xFF;
-	hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
-	write(sock, hdrbuf, 3);
-	write(sock, pkt, pktlen);
-}
--- a/rvinterf/etm/launchrvif.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-/*
- * This module implements the optional "behind the scenes" invokation
- * of rvinterf from fc-tmsh.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
-
-extern int sock;
-
-char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
-
-launch_rvinterf(ttyport)
-	char *ttyport;
-{
-	int sp[2], rc;
-	char *rvif_argv[11], Sarg[16], **ap;
-
-	rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
-	if (rc < 0) {
-		perror("socketpair");
-		exit(1);
-	}
-	sock = sp[0];
-	sprintf(Sarg, "-S%d", sp[1]);
-	ap = rvif_argv;
-	*ap++ = "rvinterf";
-	*ap++ = Sarg;
-	*ap++ = "-n";
-	if (rvinterf_Bopt) {
-		*ap++ = "-B";
-		*ap++ = rvinterf_Bopt;
-	}
-	if (rvinterf_lopt) {
-		*ap++ = "-l";
-		*ap++ = rvinterf_lopt;
-	}
-	if (rvinterf_wopt) {
-		*ap++ = "-w";
-		*ap++ = rvinterf_wopt;
-	}
-	*ap++ = ttyport;
-	*ap = 0;
-	rc = vfork();
-	if (rc < 0) {
-		perror("vfork for launching rvinterf");
-		exit(1);
-	}
-	if (!rc) {
-		/* we are in the child - do the exec */
-		close(sp[0]);
-		execv(rvinterf_pathname, rvif_argv);
-		perror(rvinterf_pathname);
-		_exit(1);
-	}
-	close(sp[1]);
-	return 0;
-}
--- a/rvinterf/etm/localtypes.h	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-/*
- * Our own definition of u8/u16/u32
- */
-
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
--- a/rvinterf/etm/main.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,86 +0,0 @@
-/*
- * This module contains the main() function for fc-tmsh.
- */
-
-#include <sys/types.h>
-#include <sys/errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-char *socket_pathname = "/tmp/rvinterf_socket";
-int ttyhacks, dflag;
-
-int sock;
-
-extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
-
-main(argc, argv)
-	char **argv;
-{
-	extern int optind;
-	extern char *optarg;
-	int c;
-	fd_set fds;
-
-	while ((c = getopt(argc, argv, "B:dl:s:w:")) != EOF)
-		switch (c) {
-		case 'B':
-			rvinterf_Bopt = optarg;
-			continue;
-		case 'd':
-			dflag++;
-			continue;
-		case 'l':
-			rvinterf_lopt = optarg;
-			continue;
-		case 's':
-			socket_pathname = optarg;
-			continue;
-		case 'w':
-			rvinterf_wopt = optarg;
-			continue;
-		case '?':
-		default:
-usage:			fprintf(stderr,
-				"usage: %s [options] [ttyport]\n", argv[0]);
-			exit(1);
-		}
-	switch (argc - optind) {
-	case 0:
-		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
-			fprintf(stderr,
-      "%s: -B, -l and -w options are meaningful only when launching rvinterf\n",
-				argv[0]);
-			exit(1);
-		}
-		break;
-	case 1:
-		launch_rvinterf(argv[optind]);
-		break;
-	default:
-		goto usage;
-	}
-
-	ttyhacks = isatty(0) && !dflag;
-	init();
-	tty_init();
-	for (;;) {
-		FD_ZERO(&fds);
-		FD_SET(0, &fds);
-		FD_SET(sock, &fds);
-		c = select(sock+1, &fds, 0, 0, 0);
-		if (c < 0) {
-			if (errno == EINTR)
-				continue;
-			tty_cleanup();
-			perror("select");
-			exit(1);
-		}
-		if (FD_ISSET(0, &fds))
-			handle_tty_input();
-		if (FD_ISSET(sock, &fds))
-			handle_rvinterf_input();
-		fflush(stdout);
-	}
-}
--- a/rvinterf/etm/misc.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-/*
- * Commands which don't belong anywhere else
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "etm.h"
-#include "tmffs1.h"
-
-void
-cmd_check_ffs1(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[5];
-
-	cmdpkt[1] = ETM_FFS1;
-	cmdpkt[2] = FPI_TMFFS_VERSION;
-	cmdpkt[3] = FPI_END;
-	send_etm_cmd(cmdpkt, 3);
-}
--- a/rvinterf/etm/pktsort.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,111 +0,0 @@
-/*
- * Here we sort out incoming packets from the target relayed via rvinterf.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "../include/limits.h"
-#include "../include/localsock.h"
-#include "localtypes.h"
-#include "etm.h"
-
-extern u_char rvi_msg[];
-extern int rvi_msg_len;
-
-void
-safe_print_trace(src, srclen, dest)
-	u_char *src;
-	char *dest;
-{
-	int i, c;
-	char *dp;
-
-	dp = dest;
-	for (i = 0; i < srclen; i++) {
-		c = src[i];
-		if (c & 0x80) {
-			*dp++ = 'M';
-			*dp++ = '-';
-			c &= 0x7F;
-		}
-		if (c < 0x20) {
-			*dp++ = '^';
-			*dp++ = c + '@';
-		} else if (c == 0x7F) {
-			*dp++ = '^';
-			*dp++ = '?';
-		} else
-			*dp++ = c;
-	}
-	*dp = '\0';
-}
-
-static void
-handle_useid_0()
-{
-	char buf[MAX_PKT_FROM_TARGET*4];
-
-	if (strncmp(rvi_msg + 7, "RVT: Lost Message", 17))
-		return;
-	safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf);
-	async_msg_output(buf);
-}
-
-static void
-print_etm_trace()
-{
-	char buf[MAX_PKT_FROM_TARGET*4];
-
-	strcpy(buf, "ETM Tr: ");
-	safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf + 9);
-	async_msg_output(buf);
-}
-
-static void
-process_rvt()
-{
-	u32 useid;
-
-	if (rvi_msg_len < 7) {
-		tty_cleanup();
-		fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
-		exit(1);
-	}
-	useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
-		| rvi_msg[5];
-	switch (useid) {
-	case 0:
-		handle_useid_0();
-		return;
-	case ETM_USE_ID:
-		print_etm_trace();
-		return;
-	default:
-		tty_cleanup();
-		fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
-			useid);
-		exit(1);
-	}
-}
-
-void
-process_pkt_from_target()
-{
-	switch (rvi_msg[1]) {
-	case RVT_RV_HEADER:
-		process_rvt();
-		return;
-	case RVT_TM_HEADER:
-		etm_packet_rx();
-		return;
-	default:
-		tty_cleanup();
-		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
-			rvi_msg[1]);
-		exit(1);
-	}
-}
--- a/rvinterf/etm/tmcore.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,448 +0,0 @@
-/*
- * In this module we are going to implement commands which send requests
- * to ETM_CORE and the handling of responses from that target module.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include "../include/pktmux.h"
-#include "../include/limits.h"
-#include "localtypes.h"
-#include "etm.h"
-
-extern u_char rvi_msg[];
-extern int rvi_msg_len;
-
-static void
-rw8_response()
-{
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
-	int num, i;
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("rw8 error");
-		return;
-	}
-	num = rvi_msg_len - 7;
-	if (!num) {
-		async_msg_output("w8 OK");
-		return;
-	}
-	strcpy(buf, "r8:");
-	dp = buf + 3;
-	for (i = 0; i < num; i++) {
-		sprintf(dp, " %02X", rvi_msg[i+6]);
-		dp += 3;
-	}
-	async_msg_output(buf);
-}
-
-static void
-rw16_response()
-{
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
-	int num, i, d, off;
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("rw16 error");
-		return;
-	}
-	num = rvi_msg_len - 7;
-	if (!num) {
-		async_msg_output("w16 OK");
-		return;
-	}
-	if (num & 1) {
-		print_etm_pkt_raw("rw16 malformed resp");
-		return;
-	}
-	num >>= 1;
-	strcpy(buf, "r16:");
-	dp = buf + 4;
-	off = 6;
-	for (i = 0; i < num; i++) {
-		d = rvi_msg[off] | rvi_msg[off+1] << 8;
-		off += 2;
-		sprintf(dp, " %04X", d);
-		dp += 5;
-	}
-	async_msg_output(buf);
-}
-
-static void
-rw32_response()
-{
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
-	int num, i, d, off;
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("rw32 error");
-		return;
-	}
-	num = rvi_msg_len - 7;
-	if (!num) {
-		async_msg_output("w32 OK");
-		return;
-	}
-	if (num & 3) {
-		print_etm_pkt_raw("rw32 malformed resp");
-		return;
-	}
-	num >>= 2;
-	strcpy(buf, "r32:");
-	dp = buf + 4;
-	off = 6;
-	for (i = 0; i < num; i++) {
-		d = rvi_msg[off] | rvi_msg[off+1] << 8 | rvi_msg[off+2] << 16
-			| rvi_msg[off+3] << 24;
-		off += 4;
-		sprintf(dp, " %08X", d);
-		dp += 9;
-	}
-	async_msg_output(buf);
-}
-
-static void
-dieid_response()
-{
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
-	int num, i;
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("dieid error");
-		return;
-	}
-	num = rvi_msg_len - 6;
-	strcpy(buf, "dieid resp:");
-	dp = buf + 11;
-	for (i = 0; i < num; i++) {
-		sprintf(dp, " %02X", rvi_msg[i+5]);
-		dp += 3;
-	}
-	async_msg_output(buf);
-}
-
-static void
-echo_response()
-{
-	if (rvi_msg[3])
-		print_etm_pkt_raw("echo error");
-	else
-		print_etm_pkt_raw("echo resp");
-}
-
-static void
-version_response()
-{
-	char buf[80];
-
-	if (rvi_msg[3]) {
-		print_etm_pkt_raw("version error");
-		return;
-	}
-	if (rvi_msg_len != 10) {
-		print_etm_pkt_raw("version malformed resp");
-		return;
-	}
-	sprintf(buf, "version resp: %02X%02X%02X%02X", rvi_msg[8], rvi_msg[7],
-		rvi_msg[6], rvi_msg[5]);
-	async_msg_output(buf);
-}
-
-void
-tmcore_msg_rx()
-{
-	switch (rvi_msg[4]) {
-	case TMCORE_OPC_MEM:
-		if (rvi_msg_len < 7)
-			goto unknown;
-		switch (rvi_msg[5]) {
-		case 0x00:
-		case 0x04:
-			rw32_response();
-			return;
-		case 0x01:
-			rw8_response();
-			return;
-		case 0x02:
-			rw16_response();
-			return;
-		default:
-			goto unknown;
-		}
-	case TMCORE_OPC_ECHO:
-		echo_response();
-		return;
-	case TMCORE_OPC_VERSION:
-		version_response();
-		return;
-	case TMCORE_OPC_CODEC_RD:
-		abbr_response();
-		return;
-	case TMCORE_OPC_CODEC_WR:
-		abbw_response();
-		return;
-	case TMCORE_OPC_DIEID:
-		dieid_response();
-		return;
-	default:
-	unknown:
-		print_etm_pkt_raw("ETM_CORE resp");
-	}
-}
-
-void
-cmd_r8(argc, argv)
-	char **argv;
-{
-	u32 addr;
-	int count;
-	u_char cmdpkt[10];
-
-	addr = strtoul(argv[1], 0, 16);
-	if (argv[2])
-		count = strtoul(argv[2], 0, 0);
-	else
-		count = 1;
-	if (count < 1 || count > 253) {
-		printf("error: count argument outside valid range\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x01;
-	cmdpkt[4] = count;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	send_etm_cmd(cmdpkt, 8);
-}
-
-void
-cmd_r16(argc, argv)
-	char **argv;
-{
-	u32 addr;
-	int count;
-	u_char cmdpkt[10];
-
-	addr = strtoul(argv[1], 0, 16);
-	if (argv[2])
-		count = strtoul(argv[2], 0, 0);
-	else
-		count = 1;
-	if (addr & 1) {
-		printf("error: address not aligned\n");
-		return;
-	}
-	if (count < 1 || count > 126) {
-		printf("error: count argument outside valid range\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x02;
-	cmdpkt[4] = count;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	send_etm_cmd(cmdpkt, 8);
-}
-
-void
-cmd_r32(argc, argv)
-	char **argv;
-{
-	u32 addr;
-	int count;
-	u_char cmdpkt[10];
-
-	addr = strtoul(argv[1], 0, 16);
-	if (argv[2])
-		count = strtoul(argv[2], 0, 0);
-	else
-		count = 1;
-	if (addr & 3) {
-		printf("error: address not aligned\n");
-		return;
-	}
-	if (count < 1 || count > 63) {
-		printf("error: count argument outside valid range\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x04;
-	cmdpkt[4] = count;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	send_etm_cmd(cmdpkt, 8);
-}
-
-void
-cmd_w8(argc, argv)
-	char **argv;
-{
-	u32 addr, v;
-	u_char cmdpkt[MAX_PKT_TO_TARGET];
-	int di;
-	char **ap;
-
-	addr = strtoul(argv[1], 0, 16);
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x11;
-	cmdpkt[4] = argc - 2;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	di = 9;
-	for (ap = argv + 2; *ap; ap++) {
-		v = strtoul(*ap, 0, 16);
-		cmdpkt[di++] = v;
-	}
-	send_etm_cmd(cmdpkt, di - 1);
-}
-
-void
-cmd_w16(argc, argv)
-	char **argv;
-{
-	u32 addr, v;
-	u_char cmdpkt[MAX_PKT_TO_TARGET];
-	int di;
-	char **ap;
-
-	addr = strtoul(argv[1], 0, 16);
-	if (addr & 1) {
-		printf("error: address not aligned\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x12;
-	cmdpkt[4] = argc - 2;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	di = 9;
-	for (ap = argv + 2; *ap; ap++) {
-		v = strtoul(*ap, 0, 16);
-		cmdpkt[di++] = v;
-		cmdpkt[di++] = v >> 8;
-	}
-	send_etm_cmd(cmdpkt, di - 1);
-}
-
-void
-cmd_w32(argc, argv)
-	char **argv;
-{
-	u32 addr, v;
-	u_char cmdpkt[MAX_PKT_TO_TARGET];
-	int di;
-	char **ap;
-
-	addr = strtoul(argv[1], 0, 16);
-	if (addr & 3) {
-		printf("error: address not aligned\n");
-		return;
-	}
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_MEM;
-	cmdpkt[3] = 0x14;
-	cmdpkt[4] = argc - 2;
-	cmdpkt[5] = addr;
-	cmdpkt[6] = addr >> 8;
-	cmdpkt[7] = addr >> 16;
-	cmdpkt[8] = addr >> 24;
-	di = 9;
-	for (ap = argv + 2; *ap; ap++) {
-		v = strtoul(*ap, 0, 16);
-		cmdpkt[di++] = v;
-		cmdpkt[di++] = v >> 8;
-		cmdpkt[di++] = v >> 16;
-		cmdpkt[di++] = v >> 24;
-	}
-	send_etm_cmd(cmdpkt, di - 1);
-}
-
-void
-cmd_dieid(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[4];
-
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_DIEID;
-	send_etm_cmd(cmdpkt, 2);
-}
-
-void
-cmd_ping(argc, argv)
-	char **argv;
-{
-	int delay, size;
-	u_char cmdpkt[8];
-
-	if (argc > 1) {
-		delay = strtoul(argv[1], 0, 0);
-		if (delay > 65535) {
-			printf("error: ping delay argument too big\n");
-			return;
-		}
-	} else
-		delay = 0;
-	if (argc > 2) {
-		size = strtoul(argv[2], 0, 0);
-		if (size > 240) {
-			printf("error: ping size argument too big\n");
-			return;
-		}
-	} else
-		size = 1;
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_ECHO;
-	cmdpkt[3] = delay;
-	cmdpkt[4] = delay >> 8;
-	cmdpkt[5] = size;
-	cmdpkt[6] = size >> 8;
-	send_etm_cmd(cmdpkt, 6);
-}
-
-void
-cmd_tgtreset(argc, argv)
-	char **argv;
-{
-	u_char cmdpkt[4];
-
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_RESET;
-	send_etm_cmd(cmdpkt, 2);
-}
-
-void
-cmd_version(argc, argv)
-	char **argv;
-{
-	u32 arg;
-	u_char cmdpkt[8];
-
-	arg = strtoul(argv[1], 0, 16);
-	cmdpkt[1] = ETM_CORE;
-	cmdpkt[2] = TMCORE_OPC_VERSION;
-	cmdpkt[3] = arg;
-	cmdpkt[4] = arg >> 8;
-	cmdpkt[5] = arg >> 16;
-	cmdpkt[6] = arg >> 24;
-	send_etm_cmd(cmdpkt, 6);
-}
--- a/rvinterf/etm/tmffs1.h	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/******************************************************************************
- * FFS1 Protocol Indentifiers
- ******************************************************************************/
-
-enum FFS1_PROTOCOL_IDENTIFIERS {
-    FPI_END = 0,         /* end */
-    FPI_BEGIN,           /* begin */
-    FPI_TMFFS_VERSION,   /* tmffs_version */
-
-    FPI_PREFORMAT,       /* preformat */
-    FPI_FORMAT,          /* format */
-
-    FPI_FCREATE,         /* fcreate */
-    FPI_FUPDATE,         /* fupdate */
-    FPI_FWRITE,          /* fwrite */
-    FPI_FREAD,           /* fread */
-    FPI_REMOVE,          /* remove */
-
-    FPI_MKDIR,           /* mkdir */
-    FPI_OPENDIR,         /* opendir */
-    FPI_READDIR,         /* readdir */
-
-    FPI_STAT,            /* stat */
-    FPI_LINKSTAT,        /* linkstat */
-
-    FPI_SYMLINK,         /* symlink */
-    FPI_READLINK,        /* readlink */
-
-    FPI_QUERY,           /* query */
-    FPI_FCONTROL,        /* fcontrol */
-
-    FPI_INIT,            /* init */
-    FPI_EXIT,            /* exit */
-
-    FPI_PCM_GETFILEINFO, /* getfileinfo */
-    FPI_PCM_READFILE,    /* readfile */
-    FPI_PCM_WRITEFILE,   /* writefile */
-    FPI_PCM_READRECORD,  /* readrecord */
-    FPI_PCM_WRITERECORD, /* writerecord */
-
-    FPI_BUFREAD,         /* buf_read */
-    FPI_BUFWRITE,        /* buf_write */
-    FPI_BUFSET,          /* buf_set */
-
-    FPI_UINT8,           /* UINT8 */
-    FPI_UINT16,          /* UINT16 */
-    FPI_UINT32,          /* UINT32 */
-    FPI_INT8,            /* INT8 */
-    FPI_INT16,           /* INT16 */
-    FPI_INT32,           /* INT32 */
-    FPI_BUFFER,          /* BUFFER */
-    FPI_DATA,            /* DATA */
-    FPI_STRBUF,          /* STRBUF */
-    FPI_STRING,          /* STRING */
-
-    FPI_TFFS             /* TFFS */
-
-};
--- a/rvinterf/etm/tmffs2.h	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-/******************************************************************************
- * FFS2 Protocol Indentifiers
- ******************************************************************************/
-
-enum FFS2_PROTOCOL_IDENTIFIERS {
-	TMFFS_FORMAT     = 'f',
-	TMFFS_PREFORMAT  = 'p',
-
-	TMFFS_MKDIR      = 'm',
-	TMFFS_OPENDIR    = 'o',
-	TMFFS_READDIR    = 'D',
-	TMFFS_REMOVE     = 'd',
-	TMFFS_RENAME     = 'n',
-	TMFFS_XLSTAT     = 'x',
-
-	TMFFS_SYMLINK    = 'y',
-	TMFFS_READLINK   = 'Y',
-
-	TMFFS_OPEN       = 'O',
-	TMFFS_CLOSE      = 'C',
-	TMFFS_READ       = 'R',
-	TMFFS_WRITE      = 'W',
-	TMFFS_SEEK       = 'S',
-
-	TMFFS_FTRUNCATE  = 'T',
-	TMFFS_TRUNCATE   = 't',
-
-	TMFFS_FILE_READ  = 'r',
-	TMFFS_FILE_WRITE = 'w',
-
-	TMFFS_FSTAT      = 'F',
-	TMFFS_LSTAT      = 'l',
-	TMFFS_STAT       = 's',
-
-	TMFFS_FCONTROL   = 'c',
-	TMFFS_QUERY      = 'q',
-
-	TMFFS_INIT       = 'i',
-	TMFFS_EXIT       = 'e', 
-
-	// Special
-	TMFFS_DIRXLSTAT  = 'X',
-
-	TMFFS_VERSION    = 'v',
-	TMFFS_TFFS       = 'z'
-}; 
-
-#define TMFFS_STRING_SIZE 127	/* includes the terminating NUL */
--- a/rvinterf/etm/ttymagic.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- * This module contains the tty "magic" code for fc-tmsh.
- */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <termios.h>
-
-extern int ttyhacks;
-
-struct termios orig_termios, our_termios;
-
-#define	MAX_USER_CMD	78
-char usercmd[MAX_USER_CMD+1];
-int usercmd_len;
-
-void
-tty_init()
-{
-	if (!ttyhacks)
-		return;
-	tcgetattr(0, &orig_termios);
-	bcopy(&orig_termios, &our_termios, sizeof(struct termios));
-	our_termios.c_oflag &= ~(OCRNL | ONOCR | ONLRET);
-	our_termios.c_lflag &= ~(ICANON | ECHO);
-	our_termios.c_cc[VMIN] = 1;
-	our_termios.c_cc[VTIME] = 0;
-	tcsetattr(0, TCSAFLUSH, &our_termios);
-	putchar('>');
-	fflush(stdout);
-}
-
-void
-tty_cleanup()
-{
-	if (!ttyhacks)
-		return;
-	tcsetattr(0, TCSAFLUSH, &orig_termios);
-}
-
-void
-handle_tty_input()
-{
-	char buf[256];
-	int i, c, cc;
-
-	cc = read(0, buf, sizeof buf);
-	if (cc <= 0) {
-		tty_cleanup();
-		exit(0);
-	}
-	for (i = 0; i < cc; i++) {
-		c = buf[i];
-		if (c >= ' ' && c <= '~') {
-			if (usercmd_len >= MAX_USER_CMD)
-				continue;
-			usercmd[usercmd_len++] = c;
-			if (ttyhacks)
-				putchar(c);	/* echo */
-			continue;
-		}
-		switch (c) {
-		case '\b':
-		case 0x7F:
-			if (!usercmd_len)
-				continue;
-			usercmd_len--;
-			if (ttyhacks) {
-				putchar('\b');
-				putchar(' ');
-				putchar('\b');
-			}
-			continue;
-		case '\n':
-		case '\r':
-			usercmd[usercmd_len] = '\0';
-			if (ttyhacks)
-				putchar('\n');	/* echo */
-			dispatch_user_cmd();
-			usercmd_len = 0;
-			if (ttyhacks)
-				putchar('>');	/* new prompt */
-		}
-	}
-}
-
-void
-async_msg_output(msg)
-	char *msg;
-{
-	int msglen, i;
-
-	msglen = strlen(msg);
-	if (ttyhacks)
-		putchar('\r');
-	fputs(msg, stdout);
-	if (ttyhacks)
-		for (i = msglen; i < usercmd_len + 1; i++)
-			putchar(' ');
-	putchar('\n');
-	if (!ttyhacks)
-		return;
-	/* reprint the input line */
-	putchar('>');
-	if (!usercmd_len)
-		return;
-	fwrite(usercmd, 1, usercmd_len, stdout);
-}
--- a/rvinterf/etm/usercmd.c	Wed Feb 05 00:11:34 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-/*
- * This module implements fc-tmsh user command dispatch.
- */
-
-#include <sys/types.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <stdlib.h>
-
-extern char usercmd[];
-
-extern void cmd_abbr();
-extern void cmd_abbw();
-extern void cmd_check_ffs1();
-extern void cmd_dieid();
-extern void cmd_etmpkt();
-extern void cmd_ffs2();
-extern void cmd_ping();
-extern void cmd_r8();
-extern void cmd_r16();
-extern void cmd_r32();
-extern void cmd_tgtreset();
-extern void cmd_version();
-extern void cmd_w8();
-extern void cmd_w16();
-extern void cmd_w32();
-
-void
-cmd_exit()
-{
-	tty_cleanup();
-	exit(0);
-}
-
-static struct cmdtab {
-	char *cmd;
-	int minargs;
-	int maxargs;
-	void (*func)();
-} cmdtab[] = {
-	{"abbr", 2, 2, cmd_abbr},
-	{"abbw", 3, 3, cmd_abbw},
-	{"check-ffs1", 0, 0, cmd_check_ffs1},
-	{"dieid", 0, 0, cmd_dieid},
-	{"etmpkt", 1, 253, cmd_etmpkt},
-	{"exit", 0, 0, cmd_exit},
-	{"ffs2", 1, 3, cmd_ffs2},
-	{"ping", 0, 2, cmd_ping},
-	{"quit", 0, 0, cmd_exit},
-	{"r8", 1, 2, cmd_r8},
-	{"r16", 1, 2, cmd_r16},
-	{"r32", 1, 2, cmd_r32},
-	{"tgtreset", 0, 0, cmd_tgtreset},
-	{"version", 1, 1, cmd_version},
-	{"w8", 2, 246, cmd_w8},
-	{"w16", 2, 123, cmd_w16},
-	{"w32", 2, 62, cmd_w32},
-	{0, 0, 0, 0}
-};
-
-void
-dispatch_user_cmd()
-{
-	char *argv[257];
-	char *cp, **ap;
-	struct cmdtab *tp;
-
-	for (cp = usercmd; isspace(*cp); cp++)
-		;
-	if (!*cp || *cp == '#')
-		return;
-	argv[0] = cp;
-	while (*cp && !isspace(*cp))
-		cp++;
-	if (*cp)
-		*cp++ = '\0';
-	for (tp = cmdtab; tp->cmd; tp++)
-		if (!strcmp(tp->cmd, argv[0]))
-			break;
-	if (!tp->func) {
-		printf("error: no such command\n");
-		return;
-	}
-	for (ap = argv + 1; ; ) {
-		while (isspace(*cp))
-			cp++;
-		if (!*cp || *cp == '#')
-			break;
-		if (ap - argv - 1 >= tp->maxargs) {
-			printf("error: too many arguments\n");
-			return;
-		}
-		*ap++ = cp;
-		while (*cp && !isspace(*cp))
-			cp++;
-		if (*cp)
-			*cp++ = '\0';
-	}
-	if (ap - argv - 1 < tp->minargs) {
-		printf("error: too few arguments\n");
-		return;
-	}
-	*ap = 0;
-	tp->func(ap - argv, argv);
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/include/etm.h	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,50 @@
+/*
+ * This header file contains various definitions for talking to ETM.
+ */
+
+#define	ETM_USE_ID	0x001E0004
+
+/* ETM Module IDs */
+enum {
+    ETM_TM3        = 0x00, // Use of old TM3 protocol
+    ETM_CORE       = 0x01,
+    ETM_TMT        = 0x02, // Pseudo module
+    ETM_SH         = 0x03, // Pseudo module
+    ETM_TM3_MISC   = 0x04, // Pseudo module - Target side
+    ETM_RF         = 0x05, 
+    ETM_IMEI       = 0x06,
+    ETM_FFS2       = 0x07,
+    ETM_AUDIO      = 0x08,
+    ETM_TPU        = 0x09, // Not official part ETM
+    ETM_PWR        = 0x0A,
+    ETM_BT         = 0x0B,
+    ETM_L23        = 0x0C,
+    ETM_RESERVED10 = 0x0D,
+    ETM_RESERVED11 = 0x0E,
+    ETM_RESERVED12 = 0x0F,
+
+    ETM_CUST       = 0xC0, // Customize id
+    ETM_CUST1      = 0xC1, // Customize id
+    ETM_CUST2      = 0xC2, // Customize id
+    ETM_CUST3      = 0xC3, // Customize id
+    ETM_CUST4      = 0xC4, // Customize id
+    ETM_CUST5      = 0xC5, // Customize id
+    ETM_CUST6      = 0xC6, // Customize id
+    ETM_CUST7      = 0xC7, // Customize id
+    ETM_CUST8      = 0xC8, // Customize id
+
+    ETM_TEST       = 0xAA, // used for test of dll's
+    ETM_TASK       = 0xEE, // ETM TASK in Target
+
+    ETM_FFS1       = 0x70
+};
+
+/* ETM_CORE opcodes */
+#define	TMCORE_OPC_MEM		0x61
+#define	TMCORE_OPC_ECHO		0x62
+#define	TMCORE_OPC_RESET	0x63
+#define	TMCORE_OPC_DEBUG	0x64
+#define	TMCORE_OPC_VERSION	0x65
+#define	TMCORE_OPC_CODEC_RD	0x66
+#define	TMCORE_OPC_CODEC_WR	0x67
+#define	TMCORE_OPC_DIEID	0x68
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/include/localtypes.h	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,7 @@
+/*
+ * Our own definition of u8/u16/u32
+ */
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/include/tmffs1.h	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * FFS1 Protocol Indentifiers
+ ******************************************************************************/
+
+enum FFS1_PROTOCOL_IDENTIFIERS {
+    FPI_END = 0,         /* end */
+    FPI_BEGIN,           /* begin */
+    FPI_TMFFS_VERSION,   /* tmffs_version */
+
+    FPI_PREFORMAT,       /* preformat */
+    FPI_FORMAT,          /* format */
+
+    FPI_FCREATE,         /* fcreate */
+    FPI_FUPDATE,         /* fupdate */
+    FPI_FWRITE,          /* fwrite */
+    FPI_FREAD,           /* fread */
+    FPI_REMOVE,          /* remove */
+
+    FPI_MKDIR,           /* mkdir */
+    FPI_OPENDIR,         /* opendir */
+    FPI_READDIR,         /* readdir */
+
+    FPI_STAT,            /* stat */
+    FPI_LINKSTAT,        /* linkstat */
+
+    FPI_SYMLINK,         /* symlink */
+    FPI_READLINK,        /* readlink */
+
+    FPI_QUERY,           /* query */
+    FPI_FCONTROL,        /* fcontrol */
+
+    FPI_INIT,            /* init */
+    FPI_EXIT,            /* exit */
+
+    FPI_PCM_GETFILEINFO, /* getfileinfo */
+    FPI_PCM_READFILE,    /* readfile */
+    FPI_PCM_WRITEFILE,   /* writefile */
+    FPI_PCM_READRECORD,  /* readrecord */
+    FPI_PCM_WRITERECORD, /* writerecord */
+
+    FPI_BUFREAD,         /* buf_read */
+    FPI_BUFWRITE,        /* buf_write */
+    FPI_BUFSET,          /* buf_set */
+
+    FPI_UINT8,           /* UINT8 */
+    FPI_UINT16,          /* UINT16 */
+    FPI_UINT32,          /* UINT32 */
+    FPI_INT8,            /* INT8 */
+    FPI_INT16,           /* INT16 */
+    FPI_INT32,           /* INT32 */
+    FPI_BUFFER,          /* BUFFER */
+    FPI_DATA,            /* DATA */
+    FPI_STRBUF,          /* STRBUF */
+    FPI_STRING,          /* STRING */
+
+    FPI_TFFS             /* TFFS */
+
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/include/tmffs2.h	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * FFS2 Protocol Indentifiers
+ ******************************************************************************/
+
+enum FFS2_PROTOCOL_IDENTIFIERS {
+	TMFFS_FORMAT     = 'f',
+	TMFFS_PREFORMAT  = 'p',
+
+	TMFFS_MKDIR      = 'm',
+	TMFFS_OPENDIR    = 'o',
+	TMFFS_READDIR    = 'D',
+	TMFFS_REMOVE     = 'd',
+	TMFFS_RENAME     = 'n',
+	TMFFS_XLSTAT     = 'x',
+
+	TMFFS_SYMLINK    = 'y',
+	TMFFS_READLINK   = 'Y',
+
+	TMFFS_OPEN       = 'O',
+	TMFFS_CLOSE      = 'C',
+	TMFFS_READ       = 'R',
+	TMFFS_WRITE      = 'W',
+	TMFFS_SEEK       = 'S',
+
+	TMFFS_FTRUNCATE  = 'T',
+	TMFFS_TRUNCATE   = 't',
+
+	TMFFS_FILE_READ  = 'r',
+	TMFFS_FILE_WRITE = 'w',
+
+	TMFFS_FSTAT      = 'F',
+	TMFFS_LSTAT      = 'l',
+	TMFFS_STAT       = 's',
+
+	TMFFS_FCONTROL   = 'c',
+	TMFFS_QUERY      = 'q',
+
+	TMFFS_INIT       = 'i',
+	TMFFS_EXIT       = 'e', 
+
+	// Special
+	TMFFS_DIRXLSTAT  = 'X',
+
+	TMFFS_VERSION    = 'v',
+	TMFFS_TFFS       = 'z'
+}; 
+
+#define TMFFS_STRING_SIZE 127	/* includes the terminating NUL */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/Makefile	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,19 @@
+CC=	gcc
+CFLAGS=	-O2 -I../include
+PROGS=	fc-tmsh
+INSTBIN=/usr/local/bin
+
+TMSH_OBJS=	abb.o etmbasic.o ffs2.o init.o interf.o launchrvif.o main.o \
+		misc.o pktsort.o tmcore.o ttymagic.o usercmd.o
+
+all:	${PROGS}
+
+fc-tmsh:	${TMSH_OBJS}
+	${CC} ${CFLAGS} -o $@ ${TMSH_OBJS}
+
+install:	${PROGS}
+	mkdir -p ${INSTBIN}
+	install -c ${PROGS} ${INSTBIN}
+
+clean:
+	rm -f *.o *.out *errs ${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/abb.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,98 @@
+/*
+ * In this module we are going to implement commands dealing with the ABB.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "localtypes.h"
+#include "etm.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+void
+cmd_abbr(argc, argv)
+	char **argv;
+{
+	u32 page, reg;
+	u_char cmdpkt[5];
+
+	page = strtoul(argv[1], 0, 0);
+	reg = strtoul(argv[2], 0, 0);
+	if (page > 1 || reg > 31) {
+		printf("error: argument(s) out of range\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_CODEC_RD;
+	cmdpkt[3] = page << 5 | reg;
+	send_etm_cmd(cmdpkt, 3);
+}
+
+void
+abbr_response()
+{
+	unsigned pg, reg, val;
+	char buf[80];
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("abbr error");
+		return;
+	}
+	if (rvi_msg_len != 9) {
+		print_etm_pkt_raw("abbr malformed resp");
+		return;
+	}
+	pg = rvi_msg[5] >> 5;
+	reg = rvi_msg[5] & 0x1F;
+	val = rvi_msg[6] | rvi_msg[7] << 8;
+	sprintf(buf, "abbr %u %u: %03X", pg, reg, val);
+	async_msg_output(buf);
+}
+
+void
+cmd_abbw(argc, argv)
+	char **argv;
+{
+	u32 page, reg, val;
+	u_char cmdpkt[7];
+
+	page = strtoul(argv[1], 0, 0);
+	reg = strtoul(argv[2], 0, 0);
+	val = strtoul(argv[3], 0, 16);
+	if (page > 1 || reg > 31 || val > 0x3FF) {
+		printf("error: argument(s) out of range\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_CODEC_WR;
+	cmdpkt[3] = page << 5 | reg;
+	cmdpkt[4] = val;
+	cmdpkt[5] = val >> 8;
+	send_etm_cmd(cmdpkt, 5);
+}
+
+void
+abbw_response()
+{
+	unsigned pg, reg;
+	char buf[80];
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("abbw error");
+		return;
+	}
+	if (rvi_msg_len != 7) {
+		print_etm_pkt_raw("abbw malformed resp");
+		return;
+	}
+	pg = rvi_msg[5] >> 5;
+	reg = rvi_msg[5] & 0x1F;
+	sprintf(buf, "abbw %u %u OK", pg, reg);
+	async_msg_output(buf);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/etmbasic.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,98 @@
+/*
+ * Basic ETM interaction
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "etm.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+void
+print_etm_pkt_raw(err)
+	char *err;
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int i;
+
+	sprintf(buf, "%s:", err);
+	dp = index(buf, '\0');
+	for (i = 2; i < rvi_msg_len; i++) {
+		sprintf(dp, " %02X", rvi_msg[i]);
+		dp += 3;
+	}
+	async_msg_output(buf);
+}
+
+void
+etm_packet_rx()
+{
+	int i, c;
+
+	if (rvi_msg_len < 4) {
+runt:		print_etm_pkt_raw("ETM Runt");
+		return;
+	}
+	c = 0;
+	for (i = 2; i < rvi_msg_len; i++)
+		c ^= rvi_msg[i];
+	if (c) {
+		print_etm_pkt_raw("BAD CKSUM");
+		return;
+	}
+	switch (rvi_msg[2]) {
+	case ETM_CORE:
+		if (rvi_msg_len < 6)
+			goto runt;
+		tmcore_msg_rx();
+		return;
+	case ETM_FFS1:
+		print_etm_pkt_raw("FFS1");
+		return;
+	case ETM_FFS2:
+		print_etm_pkt_raw("FFS2");
+		return;
+	default:
+		print_etm_pkt_raw("ETM Unknown");
+	}
+}
+
+void
+cmd_etmpkt(argc, argv)
+	char **argv;
+{
+	u_char pkt[MAX_PKT_TO_TARGET];
+	int di, c, b;
+	char **ap;
+
+	pkt[0] = RVT_TM_HEADER;
+	di = 1;
+	c = 0;
+	for (ap = argv + 1; *ap; ap++) {
+		b = strtoul(*ap, 0, 16);
+		pkt[di++] = b;
+		c ^= b;
+	}
+	pkt[di++] = c;
+	send_pkt_to_target(pkt, di);
+}
+
+void
+send_etm_cmd(buf, len)
+	u_char *buf;
+{
+	int i, c;
+
+	buf[0] = RVT_TM_HEADER;
+	c = 0;
+	for (i = 1; i <= len; i++)
+		c ^= buf[i];
+	buf[i] = c;
+	send_pkt_to_target(buf, len + 2);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/ffs2.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,157 @@
+/*
+ * In this module we are going to implement TMFFS2 functionality.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "localtypes.h"
+#include "etm.h"
+#include "tmffs2.h"
+
+void
+cmd_ffs2_close(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[5];
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_CLOSE;
+	cmdpkt[3] = strtoul(argv[1], 0, 0);
+	send_etm_cmd(cmdpkt, 3);
+}
+
+void
+cmd_ffs2_delete(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: argument exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_REMOVE;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_format(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: argument exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_FORMAT;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	/* magic is 0x2BAD, 16-bit little-endian */
+	*dp++ = 0xAD;
+	*dp++ = 0x2B;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_open(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: argument exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_OPEN;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	*dp++ = strtoul(argv[2], 0, 16);
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_preformat()
+{
+	u_char cmdpkt[6];
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_PREFORMAT;
+	/* magic is 0xDEAD, 16-bit little-endian */
+	cmdpkt[3] = 0xAD;
+	cmdpkt[4] = 0xDE;
+	send_etm_cmd(cmdpkt, 4);
+}
+
+void
+cmd_ffs2_version()
+{
+	u_char cmdpkt[4];
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_VERSION;
+	send_etm_cmd(cmdpkt, 2);
+}
+
+static struct cmdtab {
+	char *cmd;
+	int minargs;
+	int maxargs;
+	void (*func)();
+} ffs2_cmds[] = {
+	{"close", 1, 1, cmd_ffs2_close},
+	{"delete", 1, 1, cmd_ffs2_delete},
+	{"format", 1, 1, cmd_ffs2_format},
+	{"open", 2, 2, cmd_ffs2_open},
+	{"preformat", 0, 0, cmd_ffs2_preformat},
+	{"version", 0, 0, cmd_ffs2_version},
+	{0, 0, 0, 0}
+};
+
+void
+cmd_ffs2(argc, argv)
+	char **argv;
+{
+	struct cmdtab *tp;
+	int extargs;
+
+	for (tp = ffs2_cmds; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[1]))
+			break;
+	if (!tp->func) {
+		printf("error: no such ffs2 command\n");
+		return;
+	}
+	extargs = argc - 2;
+	if (extargs > tp->maxargs) {
+		printf("error: too many arguments\n");
+		return;
+	}
+	if (extargs < tp->minargs) {
+		printf("error: too few arguments\n");
+		return;
+	}
+	tp->func(argc - 1, argv + 1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/init.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,84 @@
+/*
+ * This module contains the initialization code for fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "pktmux.h"
+#include "localsock.h"
+
+extern char *socket_pathname;
+extern int sock;
+
+connect_local_socket()
+{
+	/* local socket binding voodoo copied from osmocon */
+	struct sockaddr_un local;
+	unsigned int namelen;
+	int rc;
+
+	sock = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (sock < 0) {
+		perror("socket(AF_UNIX, SOCK_STREAM, 0)");
+		exit(1);
+	}
+
+	local.sun_family = AF_UNIX;
+	strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
+	local.sun_path[sizeof(local.sun_path) - 1] = '\0';
+
+	/* we use the same magic that X11 uses in Xtranssock.c for
+	 * calculating the proper length of the sockaddr */
+#if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
+	local.sun_len = strlen(local.sun_path);
+#endif
+#if defined(BSD44SOCKETS) || defined(SUN_LEN)
+	namelen = SUN_LEN(&local);
+#else
+	namelen = strlen(local.sun_path) +
+		  offsetof(struct sockaddr_un, sun_path) + 1;
+#endif
+
+	rc = connect(sock, (struct sockaddr *) &local, namelen);
+	if (rc != 0) {
+		perror(socket_pathname);
+		exit(1);
+	}
+
+	return(0);
+}
+
+send_init_command(cmdpkt, cmdlen)
+	u_char *cmdpkt;
+{
+	u_char lenbuf[2];
+
+	lenbuf[0] = 0;
+	lenbuf[1] = cmdlen;
+	write(sock, lenbuf, 2);
+	write(sock, cmdpkt, cmdlen);
+}
+
+init()
+{
+	static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE,
+					  0xFF, 0xFF, 0xFF, 0xFF,
+					  0x00, 0x00, 0x00, 0x00};
+	static u_char want_rvt_etm[9]  = {CLI2RVI_WANT_RVTRACE,
+					  0xFF, 0xFF, 0xFF, 0xFF,
+					  0x00, 0x1E, 0x00, 0x04};
+	static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER};
+
+	if (!sock)
+		connect_local_socket();
+	localsock_prep_for_length_rx();
+	send_init_command(want_rvt_lost, 9);
+	send_init_command(want_rvt_etm, 9);
+	send_init_command(want_etm_mux, 2);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/interf.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,106 @@
+/*
+ * This module implements the link to rvinterf.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "localsock.h"
+
+extern int sock;
+
+u_char rvi_msg[LOCALSOCK_MAX_MSG];
+int rvi_msg_len;
+
+static int rx_state, rx_left;
+static u_char *rx_ptr;
+
+void
+localsock_prep_for_length_rx()
+{
+	rx_state = 0;
+	rx_ptr = rvi_msg;
+	rx_left = 2;
+}
+
+static void
+prep_for_message_rx()
+{
+	rx_state = 1;
+	rx_ptr = rvi_msg;
+	rx_left = rvi_msg_len;
+}
+
+void
+process_msg_from_rvinterf()
+{
+	switch (rvi_msg[0]) {
+	case RVI2CLI_PKT_FROM_TARGET:
+		process_pkt_from_target();
+		return;
+	case RVI2CLI_LOCAL_CMD_RESP:
+		if (rvi_msg_len < 2)
+			goto bad;
+		if (rvi_msg[1] == '+')
+			return;
+		tty_cleanup();
+		fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1,
+			rvi_msg + 1);
+		exit(1);
+	default:
+	bad:
+		tty_cleanup();
+		fprintf(stderr,
+			"Error: unexpected message type %02X from rvinterf\n",
+			rvi_msg[0]);
+		exit(1);
+	}
+}
+
+void
+handle_rvinterf_input()
+{
+	int cc;
+
+	cc = read(sock, rx_ptr, rx_left);
+	if (cc <= 0) {
+		tty_cleanup();
+		perror("read from rvinterf socket");
+		exit(1);
+	}
+	rx_ptr += cc;
+	rx_left -= cc;
+	if (rx_left)
+		return;
+	/* got the thing, process it */
+	if (rx_state) {
+		process_msg_from_rvinterf();
+		localsock_prep_for_length_rx();
+	} else {
+		rvi_msg_len = rvi_msg[0] << 8 | rvi_msg[1];
+		if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) {
+			tty_cleanup();
+			fprintf(stderr,
+				"Invalid length from rvinterf: %02X%02X\n",
+				rvi_msg[0], rvi_msg[1]);
+			exit(1);
+		}
+		prep_for_message_rx();
+	}
+}
+
+void
+send_pkt_to_target(pkt, pktlen)
+	u_char *pkt;
+{
+	u_char hdrbuf[3];
+	int len1;
+
+	len1 = pktlen + 1;
+	hdrbuf[0] = len1 >> 8;
+	hdrbuf[1] = len1 & 0xFF;
+	hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
+	write(sock, hdrbuf, 3);
+	write(sock, pkt, pktlen);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/launchrvif.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,63 @@
+/*
+ * This module implements the optional "behind the scenes" invokation
+ * of rvinterf from fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static char rvinterf_pathname[] = "/usr/local/bin/rvinterf";
+
+extern int sock;
+
+char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
+
+launch_rvinterf(ttyport)
+	char *ttyport;
+{
+	int sp[2], rc;
+	char *rvif_argv[11], Sarg[16], **ap;
+
+	rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
+	if (rc < 0) {
+		perror("socketpair");
+		exit(1);
+	}
+	sock = sp[0];
+	sprintf(Sarg, "-S%d", sp[1]);
+	ap = rvif_argv;
+	*ap++ = "rvinterf";
+	*ap++ = Sarg;
+	*ap++ = "-n";
+	if (rvinterf_Bopt) {
+		*ap++ = "-B";
+		*ap++ = rvinterf_Bopt;
+	}
+	if (rvinterf_lopt) {
+		*ap++ = "-l";
+		*ap++ = rvinterf_lopt;
+	}
+	if (rvinterf_wopt) {
+		*ap++ = "-w";
+		*ap++ = rvinterf_wopt;
+	}
+	*ap++ = ttyport;
+	*ap = 0;
+	rc = vfork();
+	if (rc < 0) {
+		perror("vfork for launching rvinterf");
+		exit(1);
+	}
+	if (!rc) {
+		/* we are in the child - do the exec */
+		close(sp[0]);
+		execv(rvinterf_pathname, rvif_argv);
+		perror(rvinterf_pathname);
+		_exit(1);
+	}
+	close(sp[1]);
+	return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/main.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,86 @@
+/*
+ * This module contains the main() function for fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+char *socket_pathname = "/tmp/rvinterf_socket";
+int ttyhacks, dflag;
+
+int sock;
+
+extern char *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt;
+
+main(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	extern char *optarg;
+	int c;
+	fd_set fds;
+
+	while ((c = getopt(argc, argv, "B:dl:s:w:")) != EOF)
+		switch (c) {
+		case 'B':
+			rvinterf_Bopt = optarg;
+			continue;
+		case 'd':
+			dflag++;
+			continue;
+		case 'l':
+			rvinterf_lopt = optarg;
+			continue;
+		case 's':
+			socket_pathname = optarg;
+			continue;
+		case 'w':
+			rvinterf_wopt = optarg;
+			continue;
+		case '?':
+		default:
+usage:			fprintf(stderr,
+				"usage: %s [options] [ttyport]\n", argv[0]);
+			exit(1);
+		}
+	switch (argc - optind) {
+	case 0:
+		if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) {
+			fprintf(stderr,
+      "%s: -B, -l and -w options are meaningful only when launching rvinterf\n",
+				argv[0]);
+			exit(1);
+		}
+		break;
+	case 1:
+		launch_rvinterf(argv[optind]);
+		break;
+	default:
+		goto usage;
+	}
+
+	ttyhacks = isatty(0) && !dflag;
+	init();
+	tty_init();
+	for (;;) {
+		FD_ZERO(&fds);
+		FD_SET(0, &fds);
+		FD_SET(sock, &fds);
+		c = select(sock+1, &fds, 0, 0, 0);
+		if (c < 0) {
+			if (errno == EINTR)
+				continue;
+			tty_cleanup();
+			perror("select");
+			exit(1);
+		}
+		if (FD_ISSET(0, &fds))
+			handle_tty_input();
+		if (FD_ISSET(sock, &fds))
+			handle_rvinterf_input();
+		fflush(stdout);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/misc.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,24 @@
+/*
+ * Commands which don't belong anywhere else
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "etm.h"
+#include "tmffs1.h"
+
+void
+cmd_check_ffs1(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[5];
+
+	cmdpkt[1] = ETM_FFS1;
+	cmdpkt[2] = FPI_TMFFS_VERSION;
+	cmdpkt[3] = FPI_END;
+	send_etm_cmd(cmdpkt, 3);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/pktsort.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,111 @@
+/*
+ * Here we sort out incoming packets from the target relayed via rvinterf.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "localsock.h"
+#include "localtypes.h"
+#include "etm.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+void
+safe_print_trace(src, srclen, dest)
+	u_char *src;
+	char *dest;
+{
+	int i, c;
+	char *dp;
+
+	dp = dest;
+	for (i = 0; i < srclen; i++) {
+		c = src[i];
+		if (c & 0x80) {
+			*dp++ = 'M';
+			*dp++ = '-';
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			*dp++ = '^';
+			*dp++ = c + '@';
+		} else if (c == 0x7F) {
+			*dp++ = '^';
+			*dp++ = '?';
+		} else
+			*dp++ = c;
+	}
+	*dp = '\0';
+}
+
+static void
+handle_useid_0()
+{
+	char buf[MAX_PKT_FROM_TARGET*4];
+
+	if (strncmp(rvi_msg + 7, "RVT: Lost Message", 17))
+		return;
+	safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf);
+	async_msg_output(buf);
+}
+
+static void
+print_etm_trace()
+{
+	char buf[MAX_PKT_FROM_TARGET*4];
+
+	strcpy(buf, "ETM Tr: ");
+	safe_print_trace(rvi_msg + 7, rvi_msg_len - 7, buf + 9);
+	async_msg_output(buf);
+}
+
+static void
+process_rvt()
+{
+	u32 useid;
+
+	if (rvi_msg_len < 7) {
+		tty_cleanup();
+		fprintf(stderr, "Error: rvinterf sent us an invalid RVT msg\n");
+		exit(1);
+	}
+	useid = rvi_msg[2] << 24 | rvi_msg[3] << 16 | rvi_msg[4] << 8
+		| rvi_msg[5];
+	switch (useid) {
+	case 0:
+		handle_useid_0();
+		return;
+	case ETM_USE_ID:
+		print_etm_trace();
+		return;
+	default:
+		tty_cleanup();
+		fprintf(stderr, "unexpected fwd of USEID %08X from rvinterf\n",
+			useid);
+		exit(1);
+	}
+}
+
+void
+process_pkt_from_target()
+{
+	switch (rvi_msg[1]) {
+	case RVT_RV_HEADER:
+		process_rvt();
+		return;
+	case RVT_TM_HEADER:
+		etm_packet_rx();
+		return;
+	default:
+		tty_cleanup();
+		fprintf(stderr, "unexpected fwd of MUX %02X from rvinterf\n",
+			rvi_msg[1]);
+		exit(1);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/tmcore.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,448 @@
+/*
+ * In this module we are going to implement commands which send requests
+ * to ETM_CORE and the handling of responses from that target module.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include "pktmux.h"
+#include "limits.h"
+#include "localtypes.h"
+#include "etm.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+static void
+rw8_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("rw8 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	if (!num) {
+		async_msg_output("w8 OK");
+		return;
+	}
+	strcpy(buf, "r8:");
+	dp = buf + 3;
+	for (i = 0; i < num; i++) {
+		sprintf(dp, " %02X", rvi_msg[i+6]);
+		dp += 3;
+	}
+	async_msg_output(buf);
+}
+
+static void
+rw16_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i, d, off;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("rw16 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	if (!num) {
+		async_msg_output("w16 OK");
+		return;
+	}
+	if (num & 1) {
+		print_etm_pkt_raw("rw16 malformed resp");
+		return;
+	}
+	num >>= 1;
+	strcpy(buf, "r16:");
+	dp = buf + 4;
+	off = 6;
+	for (i = 0; i < num; i++) {
+		d = rvi_msg[off] | rvi_msg[off+1] << 8;
+		off += 2;
+		sprintf(dp, " %04X", d);
+		dp += 5;
+	}
+	async_msg_output(buf);
+}
+
+static void
+rw32_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i, d, off;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("rw32 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	if (!num) {
+		async_msg_output("w32 OK");
+		return;
+	}
+	if (num & 3) {
+		print_etm_pkt_raw("rw32 malformed resp");
+		return;
+	}
+	num >>= 2;
+	strcpy(buf, "r32:");
+	dp = buf + 4;
+	off = 6;
+	for (i = 0; i < num; i++) {
+		d = rvi_msg[off] | rvi_msg[off+1] << 8 | rvi_msg[off+2] << 16
+			| rvi_msg[off+3] << 24;
+		off += 4;
+		sprintf(dp, " %08X", d);
+		dp += 9;
+	}
+	async_msg_output(buf);
+}
+
+static void
+dieid_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("dieid error");
+		return;
+	}
+	num = rvi_msg_len - 6;
+	strcpy(buf, "dieid resp:");
+	dp = buf + 11;
+	for (i = 0; i < num; i++) {
+		sprintf(dp, " %02X", rvi_msg[i+5]);
+		dp += 3;
+	}
+	async_msg_output(buf);
+}
+
+static void
+echo_response()
+{
+	if (rvi_msg[3])
+		print_etm_pkt_raw("echo error");
+	else
+		print_etm_pkt_raw("echo resp");
+}
+
+static void
+version_response()
+{
+	char buf[80];
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("version error");
+		return;
+	}
+	if (rvi_msg_len != 10) {
+		print_etm_pkt_raw("version malformed resp");
+		return;
+	}
+	sprintf(buf, "version resp: %02X%02X%02X%02X", rvi_msg[8], rvi_msg[7],
+		rvi_msg[6], rvi_msg[5]);
+	async_msg_output(buf);
+}
+
+void
+tmcore_msg_rx()
+{
+	switch (rvi_msg[4]) {
+	case TMCORE_OPC_MEM:
+		if (rvi_msg_len < 7)
+			goto unknown;
+		switch (rvi_msg[5]) {
+		case 0x00:
+		case 0x04:
+			rw32_response();
+			return;
+		case 0x01:
+			rw8_response();
+			return;
+		case 0x02:
+			rw16_response();
+			return;
+		default:
+			goto unknown;
+		}
+	case TMCORE_OPC_ECHO:
+		echo_response();
+		return;
+	case TMCORE_OPC_VERSION:
+		version_response();
+		return;
+	case TMCORE_OPC_CODEC_RD:
+		abbr_response();
+		return;
+	case TMCORE_OPC_CODEC_WR:
+		abbw_response();
+		return;
+	case TMCORE_OPC_DIEID:
+		dieid_response();
+		return;
+	default:
+	unknown:
+		print_etm_pkt_raw("ETM_CORE resp");
+	}
+}
+
+void
+cmd_r8(argc, argv)
+	char **argv;
+{
+	u32 addr;
+	int count;
+	u_char cmdpkt[10];
+
+	addr = strtoul(argv[1], 0, 16);
+	if (argv[2])
+		count = strtoul(argv[2], 0, 0);
+	else
+		count = 1;
+	if (count < 1 || count > 253) {
+		printf("error: count argument outside valid range\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x01;
+	cmdpkt[4] = count;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	send_etm_cmd(cmdpkt, 8);
+}
+
+void
+cmd_r16(argc, argv)
+	char **argv;
+{
+	u32 addr;
+	int count;
+	u_char cmdpkt[10];
+
+	addr = strtoul(argv[1], 0, 16);
+	if (argv[2])
+		count = strtoul(argv[2], 0, 0);
+	else
+		count = 1;
+	if (addr & 1) {
+		printf("error: address not aligned\n");
+		return;
+	}
+	if (count < 1 || count > 126) {
+		printf("error: count argument outside valid range\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x02;
+	cmdpkt[4] = count;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	send_etm_cmd(cmdpkt, 8);
+}
+
+void
+cmd_r32(argc, argv)
+	char **argv;
+{
+	u32 addr;
+	int count;
+	u_char cmdpkt[10];
+
+	addr = strtoul(argv[1], 0, 16);
+	if (argv[2])
+		count = strtoul(argv[2], 0, 0);
+	else
+		count = 1;
+	if (addr & 3) {
+		printf("error: address not aligned\n");
+		return;
+	}
+	if (count < 1 || count > 63) {
+		printf("error: count argument outside valid range\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x04;
+	cmdpkt[4] = count;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	send_etm_cmd(cmdpkt, 8);
+}
+
+void
+cmd_w8(argc, argv)
+	char **argv;
+{
+	u32 addr, v;
+	u_char cmdpkt[MAX_PKT_TO_TARGET];
+	int di;
+	char **ap;
+
+	addr = strtoul(argv[1], 0, 16);
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x11;
+	cmdpkt[4] = argc - 2;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	di = 9;
+	for (ap = argv + 2; *ap; ap++) {
+		v = strtoul(*ap, 0, 16);
+		cmdpkt[di++] = v;
+	}
+	send_etm_cmd(cmdpkt, di - 1);
+}
+
+void
+cmd_w16(argc, argv)
+	char **argv;
+{
+	u32 addr, v;
+	u_char cmdpkt[MAX_PKT_TO_TARGET];
+	int di;
+	char **ap;
+
+	addr = strtoul(argv[1], 0, 16);
+	if (addr & 1) {
+		printf("error: address not aligned\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x12;
+	cmdpkt[4] = argc - 2;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	di = 9;
+	for (ap = argv + 2; *ap; ap++) {
+		v = strtoul(*ap, 0, 16);
+		cmdpkt[di++] = v;
+		cmdpkt[di++] = v >> 8;
+	}
+	send_etm_cmd(cmdpkt, di - 1);
+}
+
+void
+cmd_w32(argc, argv)
+	char **argv;
+{
+	u32 addr, v;
+	u_char cmdpkt[MAX_PKT_TO_TARGET];
+	int di;
+	char **ap;
+
+	addr = strtoul(argv[1], 0, 16);
+	if (addr & 3) {
+		printf("error: address not aligned\n");
+		return;
+	}
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_MEM;
+	cmdpkt[3] = 0x14;
+	cmdpkt[4] = argc - 2;
+	cmdpkt[5] = addr;
+	cmdpkt[6] = addr >> 8;
+	cmdpkt[7] = addr >> 16;
+	cmdpkt[8] = addr >> 24;
+	di = 9;
+	for (ap = argv + 2; *ap; ap++) {
+		v = strtoul(*ap, 0, 16);
+		cmdpkt[di++] = v;
+		cmdpkt[di++] = v >> 8;
+		cmdpkt[di++] = v >> 16;
+		cmdpkt[di++] = v >> 24;
+	}
+	send_etm_cmd(cmdpkt, di - 1);
+}
+
+void
+cmd_dieid(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[4];
+
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_DIEID;
+	send_etm_cmd(cmdpkt, 2);
+}
+
+void
+cmd_ping(argc, argv)
+	char **argv;
+{
+	int delay, size;
+	u_char cmdpkt[8];
+
+	if (argc > 1) {
+		delay = strtoul(argv[1], 0, 0);
+		if (delay > 65535) {
+			printf("error: ping delay argument too big\n");
+			return;
+		}
+	} else
+		delay = 0;
+	if (argc > 2) {
+		size = strtoul(argv[2], 0, 0);
+		if (size > 240) {
+			printf("error: ping size argument too big\n");
+			return;
+		}
+	} else
+		size = 1;
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_ECHO;
+	cmdpkt[3] = delay;
+	cmdpkt[4] = delay >> 8;
+	cmdpkt[5] = size;
+	cmdpkt[6] = size >> 8;
+	send_etm_cmd(cmdpkt, 6);
+}
+
+void
+cmd_tgtreset(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[4];
+
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_RESET;
+	send_etm_cmd(cmdpkt, 2);
+}
+
+void
+cmd_version(argc, argv)
+	char **argv;
+{
+	u32 arg;
+	u_char cmdpkt[8];
+
+	arg = strtoul(argv[1], 0, 16);
+	cmdpkt[1] = ETM_CORE;
+	cmdpkt[2] = TMCORE_OPC_VERSION;
+	cmdpkt[3] = arg;
+	cmdpkt[4] = arg >> 8;
+	cmdpkt[5] = arg >> 16;
+	cmdpkt[6] = arg >> 24;
+	send_etm_cmd(cmdpkt, 6);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/ttymagic.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,112 @@
+/*
+ * This module contains the tty "magic" code for fc-tmsh.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <termios.h>
+
+extern int ttyhacks;
+
+struct termios orig_termios, our_termios;
+
+#define	MAX_USER_CMD	78
+char usercmd[MAX_USER_CMD+1];
+int usercmd_len;
+
+void
+tty_init()
+{
+	if (!ttyhacks)
+		return;
+	tcgetattr(0, &orig_termios);
+	bcopy(&orig_termios, &our_termios, sizeof(struct termios));
+	our_termios.c_oflag &= ~(OCRNL | ONOCR | ONLRET);
+	our_termios.c_lflag &= ~(ICANON | ECHO);
+	our_termios.c_cc[VMIN] = 1;
+	our_termios.c_cc[VTIME] = 0;
+	tcsetattr(0, TCSAFLUSH, &our_termios);
+	putchar('>');
+	fflush(stdout);
+}
+
+void
+tty_cleanup()
+{
+	if (!ttyhacks)
+		return;
+	tcsetattr(0, TCSAFLUSH, &orig_termios);
+}
+
+void
+handle_tty_input()
+{
+	char buf[256];
+	int i, c, cc;
+
+	cc = read(0, buf, sizeof buf);
+	if (cc <= 0) {
+		tty_cleanup();
+		exit(0);
+	}
+	for (i = 0; i < cc; i++) {
+		c = buf[i];
+		if (c >= ' ' && c <= '~') {
+			if (usercmd_len >= MAX_USER_CMD)
+				continue;
+			usercmd[usercmd_len++] = c;
+			if (ttyhacks)
+				putchar(c);	/* echo */
+			continue;
+		}
+		switch (c) {
+		case '\b':
+		case 0x7F:
+			if (!usercmd_len)
+				continue;
+			usercmd_len--;
+			if (ttyhacks) {
+				putchar('\b');
+				putchar(' ');
+				putchar('\b');
+			}
+			continue;
+		case '\n':
+		case '\r':
+			usercmd[usercmd_len] = '\0';
+			if (ttyhacks)
+				putchar('\n');	/* echo */
+			dispatch_user_cmd();
+			usercmd_len = 0;
+			if (ttyhacks)
+				putchar('>');	/* new prompt */
+		}
+	}
+}
+
+void
+async_msg_output(msg)
+	char *msg;
+{
+	int msglen, i;
+
+	msglen = strlen(msg);
+	if (ttyhacks)
+		putchar('\r');
+	fputs(msg, stdout);
+	if (ttyhacks)
+		for (i = msglen; i < usercmd_len + 1; i++)
+			putchar(' ');
+	putchar('\n');
+	if (!ttyhacks)
+		return;
+	/* reprint the input line */
+	putchar('>');
+	if (!usercmd_len)
+		return;
+	fwrite(usercmd, 1, usercmd_len, stdout);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/tmsh/usercmd.c	Wed Feb 05 04:02:13 2014 +0000
@@ -0,0 +1,107 @@
+/*
+ * This module implements fc-tmsh user command dispatch.
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+extern char usercmd[];
+
+extern void cmd_abbr();
+extern void cmd_abbw();
+extern void cmd_check_ffs1();
+extern void cmd_dieid();
+extern void cmd_etmpkt();
+extern void cmd_ffs2();
+extern void cmd_ping();
+extern void cmd_r8();
+extern void cmd_r16();
+extern void cmd_r32();
+extern void cmd_tgtreset();
+extern void cmd_version();
+extern void cmd_w8();
+extern void cmd_w16();
+extern void cmd_w32();
+
+void
+cmd_exit()
+{
+	tty_cleanup();
+	exit(0);
+}
+
+static struct cmdtab {
+	char *cmd;
+	int minargs;
+	int maxargs;
+	void (*func)();
+} cmdtab[] = {
+	{"abbr", 2, 2, cmd_abbr},
+	{"abbw", 3, 3, cmd_abbw},
+	{"check-ffs1", 0, 0, cmd_check_ffs1},
+	{"dieid", 0, 0, cmd_dieid},
+	{"etmpkt", 1, 253, cmd_etmpkt},
+	{"exit", 0, 0, cmd_exit},
+	{"ffs2", 1, 3, cmd_ffs2},
+	{"ping", 0, 2, cmd_ping},
+	{"quit", 0, 0, cmd_exit},
+	{"r8", 1, 2, cmd_r8},
+	{"r16", 1, 2, cmd_r16},
+	{"r32", 1, 2, cmd_r32},
+	{"tgtreset", 0, 0, cmd_tgtreset},
+	{"version", 1, 1, cmd_version},
+	{"w8", 2, 246, cmd_w8},
+	{"w16", 2, 123, cmd_w16},
+	{"w32", 2, 62, cmd_w32},
+	{0, 0, 0, 0}
+};
+
+void
+dispatch_user_cmd()
+{
+	char *argv[257];
+	char *cp, **ap;
+	struct cmdtab *tp;
+
+	for (cp = usercmd; isspace(*cp); cp++)
+		;
+	if (!*cp || *cp == '#')
+		return;
+	argv[0] = cp;
+	while (*cp && !isspace(*cp))
+		cp++;
+	if (*cp)
+		*cp++ = '\0';
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[0]))
+			break;
+	if (!tp->func) {
+		printf("error: no such command\n");
+		return;
+	}
+	for (ap = argv + 1; ; ) {
+		while (isspace(*cp))
+			cp++;
+		if (!*cp || *cp == '#')
+			break;
+		if (ap - argv - 1 >= tp->maxargs) {
+			printf("error: too many arguments\n");
+			return;
+		}
+		*ap++ = cp;
+		while (*cp && !isspace(*cp))
+			cp++;
+		if (*cp)
+			*cp++ = '\0';
+	}
+	if (ap - argv - 1 < tp->minargs) {
+		printf("error: too few arguments\n");
+		return;
+	}
+	*ap = 0;
+	tp->func(ap - argv, argv);
+}