From 82d2633b5f550115e9e7c7d0520babb6680aa38f Mon Sep 17 00:00:00 2001 From: drath Date: Mon, 17 Jul 2006 14:13:27 +0000 Subject: - Added support for native MinGW builds (thanks to Spencer Oliver and Michael Fischer) - you still need to install GiveIO (not part of OpenOCD) - Added state-move support to ftd2xx and bitbang JTAG drivers (required for XScale, possibly useful for other targets, too) - various fixes git-svn-id: svn://svn.berlios.de/openocd/trunk@78 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/jtag/Makefile.am | 4 ++ src/jtag/amt_jtagaccel.c | 3 ++ src/jtag/bitbang.c | 41 +++++++++++++++ src/jtag/ep93xx.c | 3 ++ src/jtag/ftd2xx.c | 134 +++++++++++++++++++++++++++++++++++++++-------- src/jtag/ftdi2232.c | 3 ++ src/jtag/jtag.c | 5 ++ src/jtag/parport.c | 61 +++++++++++++++++++-- 8 files changed, 228 insertions(+), 26 deletions(-) (limited to 'src/jtag') diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am index a3a06606..bb9337aa 100644 --- a/src/jtag/Makefile.am +++ b/src/jtag/Makefile.am @@ -1,6 +1,10 @@ if FTD2XXDIR +if IS_MINGW +FTD2XXINC = -I@WITH_FTD2XX@ +else FTD2XXINC = -I@WITH_FTD2XX@/ +endif else FTD2XXINC = endif diff --git a/src/jtag/amt_jtagaccel.c b/src/jtag/amt_jtagaccel.c index 42f8bc36..113aee66 100644 --- a/src/jtag/amt_jtagaccel.c +++ b/src/jtag/amt_jtagaccel.c @@ -17,7 +17,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #include "log.h" #include "jtag.h" diff --git a/src/jtag/bitbang.c b/src/jtag/bitbang.c index d6ff2898..3d49d186 100644 --- a/src/jtag/bitbang.c +++ b/src/jtag/bitbang.c @@ -17,6 +17,9 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "bitbang.h" @@ -65,6 +68,38 @@ void bitbang_state_move(void) { cur_state = end_state; } +void bitbang_path_move(pathmove_command_t *cmd) +{ + int num_states = cmd->num_states; + int state_count; + + state_count = 0; + while (num_states) + { + if (tap_transitions[cur_state].low == cmd->path[state_count]) + { + bitbang_interface->write(0, 0, 0); + bitbang_interface->write(1, 0, 0); + } + else if (tap_transitions[cur_state].high == cmd->path[state_count]) + { + bitbang_interface->write(0, 1, 0); + bitbang_interface->write(1, 1, 0); + } + else + { + ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[cmd->path[state_count]]); + exit(-1); + } + + cur_state = cmd->path[state_count]; + state_count++; + num_states--; + } + + end_state = cur_state; +} + void bitbang_runtest(int num_cycles) { int i; @@ -187,6 +222,12 @@ int bitbang_execute_queue(void) bitbang_end_state(cmd->cmd.statemove->end_state); bitbang_state_move(); break; + case JTAG_PATHMOVE: +#ifdef _DEBUG_JTAG_IO_ + DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); +#endif + bitbang_path_move(cmd->cmd.pathmove); + break; case JTAG_SCAN: #ifdef _DEBUG_JTAG_IO_ DEBUG("scan end in %i", cmd->cmd.scan->end_state); diff --git a/src/jtag/ep93xx.c b/src/jtag/ep93xx.c index 9c24dba4..e68e3d15 100644 --- a/src/jtag/ep93xx.c +++ b/src/jtag/ep93xx.c @@ -17,7 +17,10 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #include "log.h" #include "jtag.h" #include "bitbang.h" diff --git a/src/jtag/ftd2xx.c b/src/jtag/ftd2xx.c index a14d0391..e8d29a88 100644 --- a/src/jtag/ftd2xx.c +++ b/src/jtag/ftd2xx.c @@ -17,17 +17,23 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #if IS_CYGWIN == 1 #include "windows.h" #undef ERROR #endif +#include "replacements.h" + /* project specific includes */ #include "log.h" #include "types.h" #include "jtag.h" #include "configuration.h" +#include "time_support.h" /* system includes */ #include @@ -222,6 +228,7 @@ int ftd2xx_send_and_recv(jtag_command_t *first, jtag_command_t *last) #ifdef _DEBUG_USB_IO_ struct timeval start, inter, inter2, end; + struct timeval d_inter, d_inter2, d_end; #endif #ifdef _DEBUG_USB_COMMS_ @@ -272,9 +279,11 @@ int ftd2xx_send_and_recv(jtag_command_t *first, jtag_command_t *last) #ifdef _DEBUG_USB_IO_ gettimeofday(&end, NULL); - INFO("inter: %i.%i, inter2: %i.%i end: %i.%i", inter.tv_sec - start.tv_sec, inter.tv_usec - start.tv_usec, - inter2.tv_sec - start.tv_sec, inter2.tv_usec - start.tv_usec, - end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec); + timeval_subtract(&d_inter, &inter, &start); + timeval_subtract(&d_inter2, &inter2, &start); + timeval_subtract(&d_end, &end, &start); + + INFO("inter: %i.%i, inter2: %i.%i end: %i.%i", d_inter.tv_sec, d_inter.tv_usec, d_inter2.tv_sec, d_inter2.tv_usec, d_end.tv_sec, d_end.tv_usec); #endif @@ -324,6 +333,46 @@ int ftd2xx_send_and_recv(jtag_command_t *first, jtag_command_t *last) return ERROR_OK; } +void ftd2xx_add_pathmove(pathmove_command_t *cmd) +{ + int num_states = cmd->num_states; + u8 tms_byte; + int state_count; + + state_count = 0; + while (num_states) + { + tms_byte = 0x0; + int bit_count = 0; + + /* command "Clock Data to TMS/CS Pin (no Read)" */ + BUFFER_ADD = 0x4b; + /* number of states remaining */ + BUFFER_ADD = (num_states % 7) - 1; + + while (num_states % 7) + { + if (tap_transitions[cur_state].low == cmd->path[state_count]) + buf_set_u32(&tms_byte, bit_count++, 1, 0x0); + else if (tap_transitions[cur_state].high == cmd->path[state_count]) + buf_set_u32(&tms_byte, bit_count++, 1, 0x1); + else + { + ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[cmd->path[state_count]]); + exit(-1); + } + + cur_state = cmd->path[state_count]; + state_count++; + num_states--; + } + + BUFFER_ADD = tms_byte; + } + + end_state = cur_state; +} + void ftd2xx_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size) { int num_bytes = (scan_size + 7) / 8; @@ -331,23 +380,26 @@ void ftd2xx_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size int cur_byte = 0; int last_bit; - /* command "Clock Data to TMS/CS Pin (no Read)" */ - BUFFER_ADD = 0x4b; - /* scan 7 bit */ - BUFFER_ADD = 0x6; - /* TMS data bits */ - if (ir_scan) - { - BUFFER_ADD = TAP_MOVE(cur_state, TAP_SI); - cur_state = TAP_SI; - } - else + if ((!ir_scan && (cur_state != TAP_SD)) || (ir_scan && (cur_state != TAP_SI))) { - BUFFER_ADD = TAP_MOVE(cur_state, TAP_SD); - cur_state = TAP_SD; + /* command "Clock Data to TMS/CS Pin (no Read)" */ + BUFFER_ADD = 0x4b; + /* scan 7 bit */ + BUFFER_ADD = 0x6; + /* TMS data bits */ + if (ir_scan) + { + BUFFER_ADD = TAP_MOVE(cur_state, TAP_SI); + cur_state = TAP_SI; + } + else + { + BUFFER_ADD = TAP_MOVE(cur_state, TAP_SD); + cur_state = TAP_SD; + } + //DEBUG("added TMS scan (no read)"); } - //DEBUG("added TMS scan (no read)"); - + /* add command for complete bytes */ if (num_bytes > 1) { @@ -370,7 +422,7 @@ void ftd2xx_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size //DEBUG("added TDI bytes (i %i)", num_bytes); } BUFFER_ADD = (num_bytes-2) & 0xff; - BUFFER_ADD = (num_bytes >> 8) & 0xff; + BUFFER_ADD = ((num_bytes-2) >> 8) & 0xff; } if (type != SCAN_IN) { @@ -440,15 +492,23 @@ void ftd2xx_add_scan(int ir_scan, enum scan_type type, u8 *buffer, int scan_size int ftd2xx_predict_scan_out(int scan_size, enum scan_type type) { - int predicted_size = 6; + int predicted_size = 3; + + if (cur_state != TAP_SD) + predicted_size += 3; + if (type == SCAN_IN) /* only from device to host */ { + /* complete bytes */ predicted_size += (CEIL(scan_size, 8) > 1) ? 3 : 0; + /* remaining bits - 1 (up to 7) */ predicted_size += ((scan_size - 1) % 8) ? 2 : 0; } else /* host to device, or bidirectional */ { + /* complete bytes */ predicted_size += (CEIL(scan_size, 8) > 1) ? (CEIL(scan_size, 8) + 3 - 1) : 0; + /* remaining bits -1 (up to 7) */ predicted_size += ((scan_size - 1) % 8) ? 3 : 0; } @@ -588,7 +648,10 @@ int ftd2xx_execute_queue() layout->reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); require_send = 1; - + +#ifdef _DEBUG_JTAG_IO_ + DEBUG("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); +#endif break; case JTAG_RUNTEST: /* only send the maximum buffer size that FT2232C can handle */ @@ -644,6 +707,9 @@ int ftd2xx_execute_queue() //DEBUG("added TMS scan (no read)"); } require_send = 1; +#ifdef _DEBUG_JTAG_IO_ + DEBUG("runtest: %i, end in %i", cmd->cmd.runtest->num_cycles, end_state); +#endif break; case JTAG_STATEMOVE: /* only send the maximum buffer size that FT2232C can handle */ @@ -665,6 +731,24 @@ int ftd2xx_execute_queue() //DEBUG("added TMS scan (no read)"); cur_state = end_state; require_send = 1; +#ifdef _DEBUG_JTAG_IO_ + DEBUG("statemove: %i", end_state); +#endif + break; + case JTAG_PATHMOVE: + /* only send the maximum buffer size that FT2232C can handle */ + predicted_size = 3 * CEIL(cmd->cmd.pathmove->num_states, 7); + if (ftd2xx_buffer_size + predicted_size + 1 > FTD2XX_BUFFER_SIZE) + { + ftd2xx_send_and_recv(first_unsent, cmd); + require_send = 0; + first_unsent = cmd; + } + ftd2xx_add_pathmove(cmd->cmd.pathmove); + require_send = 1; +#ifdef _DEBUG_JTAG_IO_ + DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); +#endif break; case JTAG_SCAN: scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); @@ -685,11 +769,17 @@ int ftd2xx_execute_queue() require_send = 1; if (buffer) free(buffer); +#ifdef _DEBUG_JTAG_IO_ + DEBUG("%s scan, %i bit, end in %i", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, end_state); +#endif break; case JTAG_SLEEP: ftd2xx_send_and_recv(first_unsent, cmd); first_unsent = cmd->next; jtag_sleep(cmd->cmd.sleep->us); +#ifdef _DEBUG_JTAG_IO_ + DEBUG("sleep %i usec", cmd->cmd.sleep->us); +#endif break; default: ERROR("BUG: unknown JTAG command type encountered"); @@ -740,7 +830,7 @@ int ftd2xx_init(void) ftd2xx_device_desc = "Dual RS232"; } -#if IS_CYGWIN != 1 +#if IS_WIN32 == 0 /* Add JTAGkey Vid/Pid to the linux driver */ if ((status = FT_SetVIDPID(ftd2xx_vid, ftd2xx_pid)) != FT_OK) { diff --git a/src/jtag/ftdi2232.c b/src/jtag/ftdi2232.c index efd528c3..c90cc2f9 100644 --- a/src/jtag/ftdi2232.c +++ b/src/jtag/ftdi2232.c @@ -17,6 +17,9 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* project specific includes */ #include "log.h" diff --git a/src/jtag/jtag.c b/src/jtag/jtag.c index e306b0a2..d43fafb9 100644 --- a/src/jtag/jtag.c +++ b/src/jtag/jtag.c @@ -17,7 +17,12 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + +#include "replacements.h" + #include "jtag.h" #include "command.h" diff --git a/src/jtag/parport.c b/src/jtag/parport.c index 8265ada8..e78215e2 100644 --- a/src/jtag/parport.c +++ b/src/jtag/parport.c @@ -17,22 +17,34 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#ifdef HAVE_CONFIG_H #include "config.h" -#include "log.h" +#endif + +#include "replacements.h" + #include "jtag.h" #include "bitbang.h" /* system includes */ // -ino: 060521-1036 #ifdef __FreeBSD__ + #include #include #include #define ioperm(startport,length,enable)\ i386_set_ioperm((startport), (length), (enable)) + #else + +#ifndef _WIN32 #include -#endif +#else +#include "errno.h" +#endif /* _WIN32 */ + +#endif /* __FreeBSD__ */ #include #include @@ -45,6 +57,16 @@ #include #endif +#if PARPORT_USE_GIVEIO == 1 +#if IS_CYGWIN == 1 +#include +#include +#undef ERROR +#endif +#endif + +#include "log.h" + /* parallel port cable description */ typedef struct cable_s @@ -221,6 +243,32 @@ int parport_register_commands(struct command_context_s *cmd_ctx) return ERROR_OK; } +#if PARPORT_USE_GIVEIO == 1 +int parport_get_giveio_access() +{ + HANDLE h; + OSVERSIONINFO version; + + version.dwOSVersionInfoSize = sizeof version; + if (!GetVersionEx( &version )) { + errno = EINVAL; + return -1; + } + if (version.dwPlatformId != VER_PLATFORM_WIN32_NT) + return 0; + + h = CreateFile( "\\\\.\\giveio", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); + if (h == INVALID_HANDLE_VALUE) { + errno = ENODEV; + return -1; + } + + CloseHandle( h ); + + return 0; +} +#endif + int parport_init(void) { cable_t *cur_cable; @@ -303,11 +351,16 @@ int parport_init(void) dataport = parport_port; statusport = parport_port + 1; - if (ioperm(dataport, 3, 1) != 0) { +#if PARPORT_USE_GIVEIO == 1 + if (parport_get_giveio_access() != 0) +#else /* PARPORT_USE_GIVEIO */ + if (ioperm(dataport, 3, 1) != 0) +#endif /* PARPORT_USE_GIVEIO */ + { ERROR("missing privileges for direct i/o"); return ERROR_JTAG_INIT_FAILED; } -#endif +#endif /* PARPORT_USE_PPDEV */ parport_reset(0, 0); parport_write(0, 0, 0); -- cgit v1.2.3