view loadtools/ttypassthru.c @ 923:10b4bed10192

gsm-fw/L1: fix for the DSP patch corruption bug The L1 code we got from the LoCosto fw contains a feature for DSP CPU load measurement. This feature is a LoCosto-ism, i.e., not applicable to earlier DBB chips (Calypso) with their respective earlier DSP ROMs. Most of the code dealing with that feature is conditionalized as #if (DSP >= 38), but one spot was missed, and the MCU code was writing into an API word dealing with this feature. In TCS211 this DSP API word happens to be used by the DSP code patch, hence that write was corrupting the patched DSP code.
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Mon, 19 Oct 2015 17:13:56 +0000
parents dfd3110d84e3
children
line wrap: on
line source

/*
 * This module implements the pass-thru operation mode, in which
 * the Unix host tty is cross-connected directly to the target
 * running some code we have just loaded.
 */

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <termios.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>

extern int errno;

extern int target_fd;

static struct termios saved_termios, my_termios;

static void
safe_output(buf, cc)
	u_char *buf;
{
	int i, c;

	for (i = 0; i < cc; i++) {
		c = buf[i];
		if (c == '\r' || c == '\n' || c == '\t' || c == '\b') {
			putchar(c);
			continue;
		}
		if (c & 0x80) {
			putchar('M');
			putchar('-');
			c &= 0x7F;
		}
		if (c < 0x20) {
			putchar('^');
			putchar(c + '@');
		} else if (c == 0x7F) {
			putchar('^');
			putchar('?');
		} else
			putchar(c);
	}
	fflush(stdout);
}

static void
loop()
{
	char buf[BUFSIZ];
	fd_set fds, fds1;
	register int i, cc, max;

	FD_ZERO(&fds);
	FD_SET(0, &fds);
	FD_SET(target_fd, &fds);
	max = target_fd + 1;
	for (;;) {
		bcopy(&fds, &fds1, sizeof(fd_set));
		i = select(max, &fds1, NULL, NULL, NULL);
		if (i < 0) {
			if (errno == EINTR)
				continue;
			tcsetattr(0, TCSAFLUSH, &saved_termios);
			perror("select");
			exit(1);
		}
		if (FD_ISSET(0, &fds1)) {
			cc = read(0, buf, sizeof buf);
			if (cc <= 0)
				return;
			if (cc == 1 && buf[0] == 0x1C)
				return;
			write(target_fd, buf, cc);
		}
		if (FD_ISSET(target_fd, &fds1)) {
			cc = read(target_fd, buf, sizeof buf);
			if (cc <= 0) {
				tcsetattr(0, TCSAFLUSH, &saved_termios);
				fprintf(stderr, "EOF/error on target tty\n");
				exit(1);
			}
			safe_output(buf, cc);
		}
	}
}

tty_passthru()
{
	static int zero = 0;

	ioctl(target_fd, FIONBIO, &zero);

	tcgetattr(0, &saved_termios);
	bcopy(&saved_termios, &my_termios, sizeof(struct termios));
	cfmakeraw(&my_termios);
	my_termios.c_cc[VMIN] = 1;
	my_termios.c_cc[VTIME] = 0;
	tcsetattr(0, TCSAFLUSH, &my_termios);

	printf("Entering tty pass-thru; type ^\\ to exit\r\n\n");
	loop();
	tcsetattr(0, TCSAFLUSH, &saved_termios);
	return 0;
}