1
0

preliminary support for amontec jtagkey.

it's too slow to be usable right now
This commit is contained in:
michael 2007-04-29 00:43:14 +00:00
parent 8121bc50c2
commit 19b2e286ce
3 changed files with 95 additions and 51 deletions

View File

@ -2,15 +2,21 @@
#a Parallel Cable III
CFLAGS=-Wall -fPIC #-DFORCE_PC3_IDENT
FTDI := $(shell libftdi-config --libs 2>/dev/null)
ifneq ($(FTDI),)
JTAGKEYSRC = jtagkey.c
CFLAGS += -DJTAGKEY
endif
SOBJECTS=libusb-driver.so libusb-driver-DEBUG.so
all: $(SOBJECTS)
libusb-driver.so: usb-driver.c usb-driver.h Makefile
gcc $(CFLAGS) $< -o $@ -ldl -lusb -lpthread -shared
libusb-driver.so: usb-driver.c jtagkey.c usb-driver.h jtagkey.h Makefile
gcc $(CFLAGS) usb-driver.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared
libusb-driver-DEBUG.so: usb-driver.c usb-driver.h Makefile
gcc -DDEBUG $(CFLAGS) $< -o $@ -ldl -lusb -lpthread -shared
libusb-driver-DEBUG.so: usb-driver.c jtagkey.c usb-driver.h jtagkey.h Makefile
gcc -DDEBUG $(CFLAGS) usb-driver.c $(JTAGKEYSRC) -o $@ -ldl -lusb -lpthread $(FTDI) -shared
clean:
rm -f $(SOBJECTS)

View File

@ -42,6 +42,9 @@
#include <linux/parport.h>
#include <linux/ppdev.h>
#include "usb-driver.h"
#ifdef JTAGKEY
#include "jtagkey.h"
#endif
static int (*ioctl_func) (int, int, void *) = NULL;
static int windrvrfd = -1;
@ -63,7 +66,6 @@ static pthread_mutex_t int_wait = PTHREAD_MUTEX_INITIALIZER;
#define NO_WINDRVR 1
#ifdef DEBUG
#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
void hexdump(unsigned char *buf, int len) {
int i;
@ -74,8 +76,6 @@ void hexdump(unsigned char *buf, int len) {
}
fprintf(stderr,"\n");
}
#else
#define DPRINTF(format, args...)
#endif
int usb_deviceinfo(unsigned char *buf) {
@ -242,7 +242,13 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd
int ret = 0;
unsigned long port = (unsigned long)tr->dwPort;
unsigned char val;
static int last_pp_write = 0;
static unsigned char last_pp_write = 0;
#ifdef JTAGKEY
/* FIXME: Config file and mor intelligent mapping! */
if (ppbase == 0x30)
return jtagkey_transfer(tr, fd, request, ppbase, ecpbase, 1);
#endif
DPRINTF("dwPort: 0x%lx, cmdTrans: %lu, dwbytes: %ld, fautoinc: %ld, dwoptions: %ld\n",
(unsigned long)tr->dwPort, tr->cmdTrans, tr->dwBytes,
@ -284,11 +290,11 @@ int pp_transfer(WD_TRANSFER *tr, int fd, unsigned int request, unsigned char *wd
case PP_READ:
ret = ioctl(parportfd, PPRSTATUS, &val);
#ifdef FORCE_PC3_IDENT
val &= 95;
if (last_pp_write & 64)
val |= 32;
val &= 0x5f;
if (last_pp_write & 0x40)
val |= 0x20;
else
val |= 128;
val |= 0x80;
#endif
break;
@ -355,7 +361,7 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
switch(request & ~(0xc0000000)) {
case VERSION:
version = (struct version_struct*)(wdheader->data);
strcpy(version->version, "libusb-driver.so $Revision: 1.60 $");
strcpy(version->version, "libusb-driver.so $Revision: 1.61 $");
version->versionul = 802;
DPRINTF("VERSION\n");
break;
@ -385,46 +391,61 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
#ifndef NO_WINDRVR
ret = (*ioctl_func) (fd, request, wdioctl);
#else
if (parportfd < 0) {
snprintf(ppdev, sizeof(ppdev), "/dev/parport%lu",
(unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
DPRINTF("opening %s\n", ppdev);
parportfd = open(ppdev, O_RDWR|O_EXCL);
if (parportfd < 0)
fprintf(stderr,"Can't open %s: %s\n", ppdev, strerror(errno));
}
if (parportfd >= 0) {
int pmode;
if (ioctl(parportfd, PPCLAIM) == -1)
return ret;
ecpbase = 0;
pmode = IEEE1284_MODE_COMPAT;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
return ret;
if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) {
DPRINTF("ECP mode requested\n");
ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr;
/* TODO: Implement ECP mode */
#if 0
pmode = IEEE1284_MODE_ECP;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1) {
ecpbase = 0;
pmode = IEEE1284_MODE_COMPAT;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
return ret;
}
/* FIXME: Ugly hack which maps amontec JtagKey to 4. parallel port */
#ifdef JTAGKEY
if ((unsigned long)cr->Card.Item[0].I.IO.dwAddr != 0x30)
#endif
{
if (parportfd < 0) {
snprintf(ppdev, sizeof(ppdev), "/dev/parport%lu",
(unsigned long)cr->Card.Item[0].I.IO.dwAddr / 0x10);
DPRINTF("opening %s\n", ppdev);
parportfd = open(ppdev, O_RDWR|O_EXCL);
if (parportfd < 0)
fprintf(stderr,"Can't open %s: %s\n", ppdev, strerror(errno));
}
cr->hCard = parportfd;
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
if (parportfd >= 0) {
int pmode;
if (ioctl(parportfd, PPCLAIM) == -1)
return ret;
ecpbase = 0;
pmode = IEEE1284_MODE_COMPAT;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
return ret;
if (cr->Card.dwItems > 1 && cr->Card.Item[1].I.IO.dwAddr) {
DPRINTF("ECP mode requested\n");
ecpbase = (unsigned long)cr->Card.Item[1].I.IO.dwAddr;
/* TODO: Implement ECP mode */
#if 0
pmode = IEEE1284_MODE_ECP;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1) {
ecpbase = 0;
pmode = IEEE1284_MODE_COMPAT;
if (ioctl(parportfd, PPNEGOT, &pmode) == -1)
return ret;
}
#endif
}
cr->hCard = parportfd;
}
#ifdef JTAGKEY
} else {
ret=jtagkey_init(0x0403, 0xcff8); /* I need a config file... */
cr->hCard = 0xff;
#endif
}
ppbase = (unsigned long)cr->Card.Item[0].I.IO.dwAddr;
if (ret < 0)
cr->hCard = 0;
#endif
DPRINTF("hCard: %lu\n", cr->hCard);
}
@ -705,7 +726,6 @@ int do_wdioctl(int fd, unsigned int request, unsigned char *wdioctl) {
unsigned long num = wdheader->size/sizeof(WD_TRANSFER);
int i;
for (i = 0; i < num; i++) {
DPRINTF("Transfer %d:\n", i+1);
#ifndef NO_WINDRVR
@ -955,7 +975,13 @@ FILE *fopen(const char *path, const char *mode) {
if (!func)
func = (FILE* (*) (const char*, const char*)) dlsym(RTLD_NEXT, "fopen");
ret = (*func) (path, mode);
#ifdef JTAGKEY
/* FIXME: Hack for parport mapping */
if (!strcmp(path, "/proc/sys/dev/parport/parport3/base-addr")) {
ret = (*func) ("/dev/null", mode);
} else
#endif
ret = (*func) (path, mode);
if (!strcmp(path, "/proc/modules")) {
DPRINTF("opening /proc/modules\n");

View File

@ -31,6 +31,18 @@
#define PP_READ 10
#define PP_WRITE 13
#define PP_TDI 0x01
#define PP_TDO 0x10
#define PP_TCK 0x02
#define PP_TMS 0x04
#define PP_CTRL 0x08
#ifdef DEBUG
#define DPRINTF(format, args...) fprintf(stderr, format, ##args)
#else
#define DPRINTF(format, args...)
#endif
#define WDU_GET_MAX_PACKET_SIZE(x) ((unsigned short) (((x) & 0x7ff) * (1 + (((x) & 0x1800) >> 11))))
/* http://www.jungo.com/support/documentation/windriver/811/wdusb_man_mhtml/node78.html#SECTION001734000000000000000 */