diff --git a/jtag/ChangeLog b/jtag/ChangeLog index 4fe1eb84..e3c89be0 100644 --- a/jtag/ChangeLog +++ b/jtag/ChangeLog @@ -1,3 +1,10 @@ +2008-04-13 Kolja Waschk + + * src/tap/parport/ftd2xx.c, src/tap/usbconn/libusb.c, src/lib/fclock.c, + src/jtag.c, src/flash/amd_flash.c, src/flash/amd.c, src/flash/jedec.c, + src/svf/svf.c, configure.ac, doc/UrJTAG.txt: Provide variants of + usleep, frealtime, mkdir for [ 1838732 ] EXE built with MinGW + 2008-04-11 Kolja Waschk * src/bsdl/bsdl.c, src/tap/parport/ftd2xx.c, src/tap/parport/ftdi.c, diff --git a/jtag/configure.ac b/jtag/configure.ac index 4a0af5e2..8181acdc 100644 --- a/jtag/configure.ac +++ b/jtag/configure.ac @@ -209,7 +209,7 @@ AS_IF([test "x$with_ftd2xx" == xyes -o "x$with_ftd2xx" = xcheck], [ AS_IF([test "x$with_ftd2xx" != xno], [ HAVELIBFTD2XX=yes case $host in - *cygwin*) + *cygwin*|*mingw*) CFLAGS="$CFLAGS -I$with_ftd2xx" AS_IF([test -d "$with_ftd2xx/i386"], [ FTD2XXLIB="$with_ftd2xx/i386/ftd2xx.lib" diff --git a/jtag/doc/UrJTAG.txt b/jtag/doc/UrJTAG.txt index c5aba738..5898cd08 100644 --- a/jtag/doc/UrJTAG.txt +++ b/jtag/doc/UrJTAG.txt @@ -381,6 +381,19 @@ might give problems if the path contains spaces, as "Program Files" does!): ./configure --with-libusb="/cygdrive/c/Programme/LibUSB-Win32/" +==== Compiling with MinGW ==== + +UrJTAG may be compiled into a Windows executable using the MinGW compiler +(http://www.mingw.org). This has the advantage over running in a Cygwin +environment that you don't need to install anything else but the jtag.exe. +However, because support for MinGW is quite new in UrJTAG, it may lack some +features (e.g. readline support) or run a little slower. + +It is even possible to cross-compile and build the executable on a Linux +host: + + ./configure --host=i586-mingw32msvc --with-ftd2xx=/tmp/cdm-drivers + make ==== Driver tailoring ==== diff --git a/jtag/src/flash/amd.c b/jtag/src/flash/amd.c index 49c7d9fc..41b32b1b 100644 --- a/jtag/src/flash/amd.c +++ b/jtag/src/flash/amd.c @@ -43,6 +43,11 @@ #include #include +#ifdef __MINGW32__ +#include +#define usleep(x) Sleep(x/1E3) +#endif + static int dbg = 0; static int amd_flash_erase_block( cfi_array_t *cfi_array, uint32_t adr ); diff --git a/jtag/src/flash/amd_flash.c b/jtag/src/flash/amd_flash.c index 5cb5fb1c..22f92d8f 100644 --- a/jtag/src/flash/amd_flash.c +++ b/jtag/src/flash/amd_flash.c @@ -39,6 +39,11 @@ #include #include +#ifdef __MINGW32__ +#include +#define usleep(x) Sleep(x/1E3) +#endif + //write specific #define AMD_SECTOR_PROTECTED diff --git a/jtag/src/flash/jedec.c b/jtag/src/flash/jedec.c index e94c27f6..1be49197 100644 --- a/jtag/src/flash/jedec.c +++ b/jtag/src/flash/jedec.c @@ -60,9 +60,9 @@ #define AUTOSELECT_NUM 2 struct mtd_erase_region_info { - u_int32_t offset; /* At which this region starts, from the beginning of the MTD */ - u_int32_t erasesize; /* For this region */ - u_int32_t numblocks; /* Number of blocks of erasesize in this region */ + uint32_t offset; /* At which this region starts, from the beginning of the MTD */ + uint32_t erasesize; /* For this region */ + uint32_t numblocks; /* Number of blocks of erasesize in this region */ }; struct amd_flash_info { @@ -70,7 +70,7 @@ struct amd_flash_info { const int dev_id; const char *name; const long size; - const u_int8_t interface_width; + const uint8_t interface_width; const int as_method; const int numeraseregions; const struct mtd_erase_region_info regions[4]; diff --git a/jtag/src/jtag.c b/jtag/src/jtag.c index ac541c9c..99af2338 100644 --- a/jtag/src/jtag.c +++ b/jtag/src/jtag.c @@ -82,7 +82,11 @@ jtag_create_jtagdir( void ) strcat( jdir, JTAGDIR ); /* Create the directory if it doesn't exists. */ +#ifdef __MINGW32__ + mkdir( jdir ); +#else mkdir( jdir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); +#endif free( jdir ); } @@ -285,11 +289,13 @@ main( int argc, char *const argv[] ) jtag_argv0 = argv[0]; +#ifndef __MINGW32__ if(geteuid()==0 && getuid()!=0) { printf (_("'%s' must not be run suid root!\n"), "jtag"); return(-1); } +#endif #ifdef ENABLE_NLS /* l10n support */ diff --git a/jtag/src/lib/fclock.c b/jtag/src/lib/fclock.c index 08d0a914..88b8daba 100644 --- a/jtag/src/lib/fclock.c +++ b/jtag/src/lib/fclock.c @@ -26,16 +26,94 @@ #include #include #include +#ifndef __MINGW32__ #include +#endif #include #include +/* ------------------------------------------------------------------ */ + #ifdef __APPLE__ #include #include #include -#endif +long double +frealtime() +{ + long double result; + static uint64_t start_mat; + static long double start_time; + static double multiplier; + + mach_timebase_info_data_t mtid; + struct timeval tv; + + if(!mtid.denom == 0) { + mach_timebase_info(&mtid); + multiplier = (double)mtid.numer / (double)mtid.denom; + gettimeofday(&tv, NULL); + start_time = (long double)tv.tv_sec + (long double)tv.tv_usec * 1000.0; + start_mat = mach_absolute_time(); + } + + result = start_time + (mach_absolute_time() - start_mat) * multiplier; + + assert(isnormal(result)); + assert(result > 0); + return result; +} +#else /* def __APPLE__ */ + +/* ------------------------------------------------------------------ */ + +#ifdef _POSIX_TIMERS + +long double +frealtime() +{ + long double result; + + struct timespec t; + if (clock_gettime(CLOCK_REALTIME, &t)==-1) { + perror("frealtime (clock_gettime)"); + exit(EXIT_FAILURE); + } + result = (long double)t.tv_sec + (long double)t.tv_nsec*(long double)1e-9; + + assert(isnormal(result)); + assert(result > 0); + return result; +} + +#else /* def _POSIX_TIMERS */ + +/* ------------------------------------------------------------------ */ + +#ifdef __MINGW32__ + +#include + +long double +frealtime() +{ + long double result; + + struct timeb t; + + ftime(&t); + result = (long double)t.time + (long double)t.millitm * (long double)1e-3; + + assert(isnormal(result)); + assert(result > 0); + return result; +} + + +#else /* def __MINGW32__ */ + +/* ------------------------------------------------------------------ */ #ifndef CLK_TCK static clock_t CLK_TCK = 0; @@ -51,37 +129,12 @@ static void set_clk_tck(void) } #endif - long double frealtime() { long double result; -#ifdef __APPLE__ - static uint64_t start_mat; - static long double start_time; - static double multiplier; - mach_timebase_info_data_t mtid; - struct timeval tv; - - if(!mtid.denom == 0) { - mach_timebase_info(&mtid); - multiplier = (double)mtid.numer / (double)mtid.denom; - gettimeofday(&tv, NULL); - start_time = (long double)tv.tv_sec + (long double)tv.tv_usec * 1000.0; - start_mat = mach_absolute_time(); - } - - result = start_time + (mach_absolute_time() - start_mat) * multiplier; -#else -#ifdef _POSIX_TIMERS - struct timespec t; - if (clock_gettime(CLOCK_REALTIME, &t)==-1) { - perror("frealtime (clock_gettime)"); - exit(EXIT_FAILURE); - } - result = (long double)t.tv_sec + (long double)t.tv_nsec*(long double)1e-9; -#else + struct tms t; clock_t c=times(&t); if (c==(clock_t)-1) { @@ -89,23 +142,14 @@ frealtime() exit(EXIT_FAILURE); } result = (long double)c/CLK_TCK; -#endif -#endif + assert(isnormal(result)); assert(result > 0); return result; } +#endif +#endif +#endif -long double -fcputime() -{ - struct tms t; - clock_t c=times(&t); - if (c==(clock_t)-1) { - perror("fcputime (times)"); - exit(EXIT_FAILURE); - } - return ((long double)t.tms_utime+t.tms_stime)/CLK_TCK; -} diff --git a/jtag/src/svf/svf.c b/jtag/src/svf/svf.c index 074e26a7..439a71fe 100644 --- a/jtag/src/svf/svf.c +++ b/jtag/src/svf/svf.c @@ -51,6 +51,10 @@ #include "svf.h" #include "svf_bison.h" +#ifdef __MINGW__ +#include "fclock.h" +#endif + int svfparse(parser_priv_t *priv_data, chain_t *chain); @@ -654,6 +658,20 @@ svf_runtest(chain_t *chain, parser_priv_t *priv, struct runtest *params) svf_goto_state(chain, priv->runtest_run_state); +#ifdef __MINGW32__ + if (params->max_time > 0.0) { + double maxt = frealtime() + params->max_time; + + while (run_count-- > 0 && frealtime() < maxt) { + chain_clock(chain, 0, 0, 1); + } + } + else + chain_clock(chain, 0, 0, run_count); + + svf_goto_state(chain, priv->runtest_end_state); + +#else /* set up the timer for max_time */ if (params->max_time > 0.0) { struct sigaction sa; @@ -694,6 +712,7 @@ svf_runtest(chain_t *chain, parser_priv_t *priv, struct runtest *params) exit(EXIT_FAILURE); } } +#endif return(1); } diff --git a/jtag/src/tap/parport/ftd2xx.c b/jtag/src/tap/parport/ftd2xx.c index 418076b9..c48b6e1b 100644 --- a/jtag/src/tap/parport/ftd2xx.c +++ b/jtag/src/tap/parport/ftd2xx.c @@ -31,7 +31,7 @@ #include #include -#if __CYGWIN__ +#if __CYGWIN__ || __MINGW32__ #include #endif #ifdef HAVE_STROPTS_H @@ -213,8 +213,8 @@ ftd2xx_generic_open( parport_t *parport ) ftd2xx_params_t *p = parport->params; FT_STATUS status; -#if !__CYGWIN__ - /* Add non-standard Vid/Pid to the linux driver */ +#if !__CYGWIN__ && !__MINGW32__ + /* Add non-standard Vid/Pid to the linux driver */ if ((status = FT_SetVIDPID(p->vendor_id, p->product_id)) != FT_OK) fprintf( stderr, "Warning: couldn't add %4.4x:%4.4x", p->vendor_id, p->product_id ); #endif diff --git a/jtag/src/tap/usbconn/libusb.c b/jtag/src/tap/usbconn/libusb.c index 47dac86a..60625d51 100644 --- a/jtag/src/tap/usbconn/libusb.c +++ b/jtag/src/tap/usbconn/libusb.c @@ -29,7 +29,7 @@ #ifdef HAVE_LIBUSB #include -#if __CYGWIN__ +#if __CYGWIN__ || __MINGW32__ #include #endif #include