changeset 188:9f4f331ac24d

fc-tmsh: implemented handling of ETM_CORE responses
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 25 Nov 2013 02:11:47 +0000
parents f5f8776f7c66
children a95d253ef952
files rvinterf/etm/Makefile rvinterf/etm/etm.h rvinterf/etm/etmbasic.c rvinterf/etm/tmcore.c
diffstat 4 files changed, 260 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etm/Makefile	Sun Nov 24 23:25:59 2013 +0000
+++ b/rvinterf/etm/Makefile	Mon Nov 25 02:11:47 2013 +0000
@@ -3,7 +3,8 @@
 PROGS=	fc-tmsh
 INSTBIN=/usr/local/bin
 
-TMSH_OBJS=	etmbasic.o init.o interf.o main.o pktsort.o ttymagic.o usercmd.o
+TMSH_OBJS=	etmbasic.o init.o interf.o main.o pktsort.o tmcore.o ttymagic.o\
+		usercmd.o
 
 all:	${PROGS}
 
--- a/rvinterf/etm/etm.h	Sun Nov 24 23:25:59 2013 +0000
+++ b/rvinterf/etm/etm.h	Mon Nov 25 02:11:47 2013 +0000
@@ -3,3 +3,48 @@
  */
 
 #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	Sun Nov 24 23:25:59 2013 +0000
+++ b/rvinterf/etm/etmbasic.c	Mon Nov 25 02:11:47 2013 +0000
@@ -9,30 +9,52 @@
 #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()
 {
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
 	int i, c;
 
 	if (rvi_msg_len < 4) {
-		async_msg_output("!!! Short ETM Rx packet !!!");
+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;
 	}
-	strcpy(buf, "Pkt from ETM:");
-	dp = index(buf, '\0');
-	c = 0;
-	for (i = 2; i < rvi_msg_len; i++) {
-		sprintf(dp, " %02X", rvi_msg[i]);
-		dp += 3;
-		c ^= rvi_msg[i];
+	switch (rvi_msg[2]) {
+	case ETM_CORE:
+		if (rvi_msg_len < 6)
+			goto runt;
+		tmcore_msg_rx();
+		return;
+	default:
+		print_etm_pkt_raw("ETM Unknown");
 	}
-	sprintf(dp, " chksum %s", c ? "BAD" : "OK");
-	async_msg_output(buf);
 }
 
 void
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etm/tmcore.c	Mon Nov 25 02:11:47 2013 +0000
@@ -0,0 +1,180 @@
+/*
+ * 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 "etm.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+static void
+r8_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("r8 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	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
+r16_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i, d, off;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("r16 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	if (num & 1) {
+		print_etm_pkt_raw("r16 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
+r32_response()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int num, i, d, off;
+
+	if (rvi_msg[3]) {
+		print_etm_pkt_raw("r32 error");
+		return;
+	}
+	num = rvi_msg_len - 7;
+	if (num & 3) {
+		print_etm_pkt_raw("r32 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];
+		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 + 3;
+	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:
+			r32_response();
+			return;
+		case 0x01:
+			r8_response();
+			return;
+		case 0x02:
+			r16_response();
+			return;
+		default:
+			goto unknown;
+		}
+	case TMCORE_OPC_ECHO:
+		echo_response();
+		return;
+	case TMCORE_OPC_VERSION:
+		version_response();
+		return;
+	case TMCORE_OPC_CODEC_RD:
+	case TMCORE_OPC_CODEC_WR:
+		/* not yet implemented */
+		goto unknown;
+	case TMCORE_OPC_DIEID:
+		dieid_response();
+		return;
+	default:
+	unknown:
+		print_etm_pkt_raw("ETM_CORE resp");
+	}
+}