Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add xc3sprog patch

  • Loading branch information...
commit acd8e4a934ba40ac9d132c8b82c897601d63abda 1 parent ad490ac
tmbinc authored
7 src/xc3sprog/README
... ... @@ -0,0 +1,7 @@
  1 +This is a very rough patch to xc3sprog that
  2 +
  3 +- add a very simple makefile,
  4 +- a very simple python wrapper,
  5 +- XC2VP50 support.
  6 +
  7 +
837 src/xc3sprog/xc3sprog_472_crunchy.patch
... ... @@ -0,0 +1,837 @@
  1 +diff --git a/xc3sprog/Makefile b/xc3sprog/Makefile
  2 +new file mode 100644
  3 +index 0000000..92d0fb5
  4 +--- /dev/null
  5 ++++ b/xc3sprog/Makefile
  6 +@@ -0,0 +1,24 @@
  7 ++CFLAGS=-O2 -I /usr/include/python2.5 -g
  8 ++LDFLAGS=-lusb -lftdi
  9 ++
  10 ++.cpp.o:
  11 ++ $(CROSS)g++ $(CFLAGS) -c -o $@ $*.cpp
  12 ++
  13 ++all: xc3sprog jtag.so
  14 ++
  15 ++OBJS = bitfile.o \
  16 ++ devicedb.o iobase.o iodebug.o \
  17 ++ ioftdi.o ioparport.o ioxpc.o javr.o \
  18 ++ jedecfile.o jtag.o mapfile_xc2c.o progalgavr.o \
  19 ++ progalgspiflash.o progalgxc2c.o progalgxc3s.o progalgxc95x.o progalgxcf.o \
  20 ++ progalgxcfp.o srecfile.o \
  21 ++ utilities.o xc3sprog.o
  22 ++
  23 ++xc3sprog: $(OBJS)
  24 ++ $(CROSS)g++ $(OBJS) $(LDFLAGS) -o xc3sprog
  25 ++
  26 ++jtag.so: $(OBJS) python.o
  27 ++ $(CROSS)g++ $(OBJS) python.o $(LDFLAGS) -o jtag.so -shared
  28 ++
  29 ++clean:
  30 ++ rm -f $(OBJS)
  31 +diff --git a/xc3sprog/config.h b/xc3sprog/config.h
  32 +new file mode 100644
  33 +index 0000000..fc76f3d
  34 +--- /dev/null
  35 ++++ b/xc3sprog/config.h
  36 +@@ -0,0 +1 @@
  37 ++const char fb_string[]={"${fb_string}"};
  38 +diff --git a/xc3sprog/devlist.txt b/xc3sprog/devlist.txt
  39 +index f50e1e0..e782b0b 100644
  40 +--- a/xc3sprog/devlist.txt
  41 ++++ b/xc3sprog/devlist.txt
  42 +@@ -170,6 +170,10 @@
  43 + 06d7c093 8 0x1 XC2C512_PQ208
  44 + 06d7e093 8 0x1 XC2C512_FT256
  45 +
  46 ++
  47 ++1129e093 14 0xffc9 XC2VP50
  48 ++
  49 ++
  50 + #unsupported
  51 + #Virtex2
  52 + 01020093 6 5 XC2V500
  53 +diff --git a/xc3sprog/ioembedded.cpp b/xc3sprog/ioembedded.cpp
  54 +new file mode 100644
  55 +index 0000000..3f57ebc
  56 +--- /dev/null
  57 ++++ b/xc3sprog/ioembedded.cpp
  58 +@@ -0,0 +1,136 @@
  59 ++/* JTAG GNU/Linux parport device io
  60 ++
  61 ++Copyright (C) 2010 Felix Domke
  62 ++
  63 ++This program is free software; you can redistribute it and/or modify
  64 ++it under the terms of the GNU General Public License as published by
  65 ++the Free Software Foundation; either version 2 of the License, or
  66 ++(at your option) any later version.
  67 ++
  68 ++This program is distributed in the hope that it will be useful,
  69 ++but WITHOUT ANY WARRANTY; without even the implied warranty of
  70 ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  71 ++ GNU General Public License for more details.
  72 ++
  73 ++You should have received a copy of the GNU General Public License
  74 ++along with this program; if not, write to the Free Software
  75 ++Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  76 ++
  77 ++*/
  78 ++
  79 ++
  80 ++#include <stdio.h>
  81 ++#include <stdlib.h>
  82 ++#include <fcntl.h>
  83 ++#include <string.h>
  84 ++#include "ioembedded.h"
  85 ++#include "gpio.h"
  86 ++
  87 ++using namespace std;
  88 ++
  89 ++
  90 ++IOEmbedded::IOEmbedded() : IOBase(), total(0) {
  91 ++ printf("open gpio\n");
  92 ++ xgpio_init();
  93 ++ printf("init default gpio\n");
  94 ++ xgpio_set_oe(GPIO_TDI, 1);
  95 ++ xgpio_set_oe(GPIO_TDO, 0);
  96 ++ xgpio_set_oe(GPIO_TMS, 1);
  97 ++ xgpio_set_oe(GPIO_TCK, 1);
  98 ++ printf("ok\n");
  99 ++}
  100 ++
  101 ++bool IOEmbedded::txrx(bool tms, bool tdi)
  102 ++{
  103 ++ unsigned char ret;
  104 ++ bool retval;
  105 ++ unsigned char data=0;
  106 ++ if(tdi)data|=TDI;
  107 ++ if(tms)data|=TMS;
  108 ++ set_io(data);
  109 ++ data|=TCK;
  110 ++ retval = set_io(data);
  111 ++ total++;
  112 ++ return retval;
  113 ++
  114 ++}
  115 ++
  116 ++void IOEmbedded::tx(bool tms, bool tdi)
  117 ++{
  118 ++ unsigned char data=0; // D4 pin5 TDI enable
  119 ++ if(tdi)data|=TDI; // D0 pin2
  120 ++ if(tms)data|=TMS; // D2 pin4
  121 ++ set_io(data);
  122 ++ data|=TCK; // clk high
  123 ++ total++;
  124 ++ set_io(data);
  125 ++}
  126 ++
  127 ++void IOEmbedded::tx_tdi_byte(unsigned char tdi_byte)
  128 ++{
  129 ++ int k;
  130 ++
  131 ++ for (k = 0; k < 8; k++)
  132 ++ tx(false, (tdi_byte>>k)&1);
  133 ++}
  134 ++
  135 ++void IOEmbedded::txrx_block(const unsigned char *tdi, unsigned char *tdo,
  136 ++ int length, bool last)
  137 ++{
  138 ++ int i=0;
  139 ++ int j=0;
  140 ++ unsigned char tdo_byte=0;
  141 ++ unsigned char tdi_byte;
  142 ++ unsigned char data=0;
  143 ++ if (tdi)
  144 ++ tdi_byte = tdi[j];
  145 ++
  146 ++ while(i<length-1){
  147 ++ tdo_byte=tdo_byte+(txrx(false, (tdi_byte&1)==1)<<(i%8));
  148 ++ if (tdi)
  149 ++ tdi_byte=tdi_byte>>1;
  150 ++ i++;
  151 ++ if((i%8)==0){ // Next byte
  152 ++ if(tdo)
  153 ++ tdo[j]=tdo_byte; // Save the TDO byte
  154 ++ tdo_byte=0;
  155 ++ j++;
  156 ++ if (tdi)
  157 ++ tdi_byte=tdi[j]; // Get the next TDI byte
  158 ++ }
  159 ++ };
  160 ++ tdo_byte=tdo_byte+(txrx(last, (tdi_byte&1)==1)<<(i%8));
  161 ++ if(tdo)
  162 ++ tdo[j]=tdo_byte;
  163 ++ set_io(data); /* Make sure, TCK is low */
  164 ++ return;
  165 ++}
  166 ++
  167 ++void IOEmbedded::tx_tms(unsigned char *pat, int length, int force)
  168 ++{
  169 ++ int i;
  170 ++ unsigned char tms;
  171 ++ unsigned char data=0;
  172 ++ for (i = 0; i < length; i++)
  173 ++ {
  174 ++ if ((i & 0x7) == 0)
  175 ++ tms = pat[i>>3];
  176 ++ tx((tms & 0x01), true);
  177 ++ tms = tms >> 1;
  178 ++ }
  179 ++ set_io(data); /* Make sure, TCK is low */
  180 ++}
  181 ++
  182 ++IOEmbedded::~IOEmbedded()
  183 ++{
  184 ++ if (verbose) fprintf(stderr, "Total bytes sent: %d\n", total>>3);
  185 ++}
  186 ++
  187 ++
  188 ++int IOEmbedded::set_io(unsigned char data)
  189 ++{
  190 ++ xgpio_set(GPIO_TDI, !!(data & TDI));
  191 ++ xgpio_set(GPIO_TMS, !!(data & TMS));
  192 ++ xgpio_set(GPIO_TCK, !!(data & TCK));
  193 ++ return xgpio_get(GPIO_TDO);
  194 ++}
  195 +diff --git a/xc3sprog/ioembedded.h b/xc3sprog/ioembedded.h
  196 +new file mode 100644
  197 +index 0000000..bc77951
  198 +--- /dev/null
  199 ++++ b/xc3sprog/ioembedded.h
  200 +@@ -0,0 +1,58 @@
  201 ++/* JTAG for Embedded devices (using GPIO)
  202 ++
  203 ++Copyright (C) 2010 Felix Domke
  204 ++
  205 ++This program is free software; you can redistribute it and/or modify
  206 ++it under the terms of the GNU General Public License as published by
  207 ++the Free Software Foundation; either version 2 of the License, or
  208 ++(at your option) any later version.
  209 ++
  210 ++This program is distributed in the hope that it will be useful,
  211 ++but WITHOUT ANY WARRANTY; without even the implied warranty of
  212 ++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  213 ++GNU General Public License for more details.
  214 ++
  215 ++You should have received a copy of the GNU General Public License
  216 ++along with this program; if not, write to the Free Software
  217 ++Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  218 ++
  219 ++Changes:
  220 ++Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
  221 ++ Code cleanup for clean -Wall compile.
  222 ++ Changes to support new IOBase interface.
  223 ++*/
  224 ++
  225 ++
  226 ++
  227 ++#ifndef IOPARPORT_H
  228 ++#define IOPARPORT_H
  229 ++
  230 ++#include "iobase.h"
  231 ++
  232 ++class IOEmbedded : public IOBase
  233 ++{
  234 ++ enum {
  235 ++ TDI = 1,
  236 ++ TDO = 2,
  237 ++ TCK = 4,
  238 ++ TMS = 8
  239 ++ };
  240 ++protected:
  241 ++ int set_io(unsigned char data);
  242 ++
  243 ++public:
  244 ++ IOEmbedded();
  245 ++ ~IOEmbedded();
  246 ++ void tx(bool tms, bool tdi);
  247 ++ bool txrx(bool tms, bool tdi);
  248 ++ void tx_tdi_byte(unsigned char tdi_byte);
  249 ++ void tx_tms(unsigned char *pat, int length, int force);
  250 ++
  251 ++public:
  252 ++ void txrx_block(const unsigned char *tdi, unsigned char *tdo, int length, bool last);
  253 ++private:
  254 ++ int debug, total;
  255 ++};
  256 ++
  257 ++
  258 ++#endif // IOPARPORT_H
  259 +diff --git a/xc3sprog/ioftdi.cpp b/xc3sprog/ioftdi.cpp
  260 +index f103616..2be4d24 100644
  261 +--- a/xc3sprog/ioftdi.cpp
  262 ++++ b/xc3sprog/ioftdi.cpp
  263 +@@ -35,7 +35,7 @@ IOFtdi::IOFtdi(int vendor, int product, char const *desc, char const *serial,
  264 +
  265 + unsigned char buf1[5];
  266 + unsigned char buf[9] = { SET_BITS_LOW, 0x00, 0x0b,
  267 +- TCK_DIVISOR, 0x00, 0x00 ,
  268 ++ TCK_DIVISOR, 0x01, 0x00 ,
  269 + SET_BITS_HIGH, (unsigned char)~0x84, 0x84};
  270 +
  271 + char *fname = getenv("FTDI_DEBUG");
  272 +@@ -153,7 +153,7 @@ void IOFtdi::txrx_block(const unsigned char *tdi, unsigned char *tdo,
  273 + /* If we need to shift state, treat the last bit separate*/
  274 + unsigned int rem = (last)? length - 1: length;
  275 + unsigned char buf[TX_BUF];
  276 +- unsigned int buflen = TX_BUF - 3 ; /* we need the preamble*/
  277 ++ unsigned int buflen = (tdo ? TX_BUF_INPUT : TX_BUF) - 3 ; /* we need the preamble*/
  278 + unsigned int rembits;
  279 +
  280 + /*out on -ve edge, in on +ve edge */
  281 +diff --git a/xc3sprog/ioftdi.h b/xc3sprog/ioftdi.h
  282 +index f3a628a..8fea451 100644
  283 +--- a/xc3sprog/ioftdi.h
  284 ++++ b/xc3sprog/ioftdi.h
  285 +@@ -48,6 +48,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  286 + #define FTDI_LLIF 6
  287 +
  288 + #define TX_BUF (4096)
  289 ++#define TX_BUF_INPUT (32)
  290 +
  291 + class IOFtdi : public IOBase
  292 + {
  293 +diff --git a/xc3sprog/ioxpc.cpp b/xc3sprog/ioxpc.cpp
  294 +index e4b69dc..2f30738 100644
  295 +--- a/xc3sprog/ioxpc.cpp
  296 ++++ b/xc3sprog/ioxpc.cpp
  297 +@@ -24,8 +24,8 @@
  298 + #include <sys/time.h>
  299 + #include <stdint.h>
  300 +
  301 +-#include <xguff/usrp_interfaces.h>
  302 +-#include <xguff/usrp_commands.h>
  303 ++//#include <xguff/usrp_interfaces.h>
  304 ++//#include <xguff/usrp_commands.h>
  305 + #include <string.h>
  306 + #include <cstdio>
  307 +
  308 +diff --git a/xc3sprog/progalgxc3s.cpp b/xc3sprog/progalgxc3s.cpp
  309 +index 9553cac..e24f76b 100644
  310 +--- a/xc3sprog/progalgxc3s.cpp
  311 ++++ b/xc3sprog/progalgxc3s.cpp
  312 +@@ -199,6 +199,7 @@ void ProgAlgXC3S::reconfig(void)
  313 + switch(family)
  314 + {
  315 + case FAMILY_XC2V:
  316 ++ case FAMILY_XC2VP:
  317 + case FAMILY_XC3S:
  318 + case FAMILY_XC3SE:
  319 + case FAMILY_XC3SA:
  320 +diff --git a/xc3sprog/progalgxc3s.h b/xc3sprog/progalgxc3s.h
  321 +index 6efdded..ccd3cec 100644
  322 +--- a/xc3sprog/progalgxc3s.h
  323 ++++ b/xc3sprog/progalgxc3s.h
  324 +@@ -30,6 +30,7 @@ Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
  325 + #include "jtag.h"
  326 +
  327 + #define FAMILY_XC2V 0x08
  328 ++#define FAMILY_XC2VP 0x09
  329 + #define FAMILY_XC3S 0x0a
  330 + #define FAMILY_XC3SE 0x0e
  331 + #define FAMILY_XC3SA 0x11
  332 +diff --git a/xc3sprog/python.cpp b/xc3sprog/python.cpp
  333 +new file mode 100644
  334 +index 0000000..e05ec9c
  335 +--- /dev/null
  336 ++++ b/xc3sprog/python.cpp
  337 +@@ -0,0 +1,337 @@
  338 ++#include <Python.h>
  339 ++
  340 ++#include <stdio.h>
  341 ++#include <string.h>
  342 ++#include <stdarg.h>
  343 ++#include <stdlib.h>
  344 ++#include <unistd.h>
  345 ++
  346 ++
  347 ++#include "io_exception.h"
  348 ++#include "ioparport.h"
  349 ++#ifndef EMBEDDED
  350 ++#include "iofx2.h"
  351 ++#include "ioftdi.h"
  352 ++#include "ioxpc.h"
  353 ++#endif
  354 ++#include "bitfile.h"
  355 ++#include "jtag.h"
  356 ++#include "devicedb.h"
  357 ++#include "progalgxcf.h"
  358 ++#include "progalgxcfp.h"
  359 ++#include "javr.h"
  360 ++#include "progalgxc3s.h"
  361 ++#include "jedecfile.h"
  362 ++#include "mapfile_xc2c.h"
  363 ++#include "progalgxc95x.h"
  364 ++#include "progalgxc2c.h"
  365 ++#include "progalgavr.h"
  366 ++#include "progalgspiflash.h"
  367 ++#include "utilities.h"
  368 ++
  369 ++#define IDCODE_TO_FAMILY(id) ((id>>21) & 0x7f)
  370 ++#define IDCODE_TO_MANUFACTURER(id) ((id>>1) & 0x3ff)
  371 ++
  372 ++#define MANUFACTURER_ATMEL 0x01f
  373 ++#define MANUFACTURER_XILINX 0x049
  374 ++
  375 ++
  376 ++typedef struct {
  377 ++ PyObject_HEAD
  378 ++ IOBase *io;
  379 ++ DeviceDB *db;
  380 ++ Jtag *jtag;
  381 ++ /* Type-specific fields go here. */
  382 ++} JTAG;
  383 ++
  384 ++static void
  385 ++JTAG_dealloc(JTAG* self)
  386 ++{
  387 ++ delete self->jtag;
  388 ++ delete self->io;
  389 ++ delete self->db;
  390 ++ self->ob_type->tp_free((PyObject*)self);
  391 ++}
  392 ++
  393 ++static PyObject *
  394 ++JTAG_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  395 ++{
  396 ++ JTAG *self;
  397 ++
  398 ++ self = (JTAG *)type->tp_alloc(type, 0);
  399 ++ if (self != NULL) {
  400 ++ self->io = 0;
  401 ++ self->db = new DeviceDB(0);
  402 ++ self->jtag = 0;
  403 ++ }
  404 ++
  405 ++ return (PyObject *)self;
  406 ++}
  407 ++
  408 ++extern int init_chain(Jtag &jtag, DeviceDB &db);
  409 ++extern unsigned long get_id(Jtag &jtag, DeviceDB &db, int chainpos);
  410 ++extern int programXC3S(Jtag &g, BitFile &file, bool verify, bool reconfig, int family);
  411 ++
  412 ++static PyObject *
  413 ++JTAG_connect(JTAG *self, PyObject *args, PyObject *keywds)
  414 ++{
  415 ++ CABLES_TYPES cable = CABLE_NONE;
  416 ++
  417 ++ cable = CABLE_FTDI;
  418 ++#ifndef EMBEDDED
  419 ++ int subtype = FTDI_NO_EN;
  420 ++#else
  421 ++ int subtype = 0;
  422 ++#endif
  423 ++ int channel = 0;
  424 ++ int vendor = 0;
  425 ++ int product = 0;
  426 ++ char *dev = 0;
  427 ++ char *desc = 0;
  428 ++ char *serial = 0;
  429 ++ int verbose = 2;
  430 ++ int chainpos = 0;
  431 ++ int res;
  432 ++
  433 ++ const char *kwlist[] = {"cable", "product", "vendor", NULL};
  434 ++ char *s_cable;
  435 ++
  436 ++ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|ii", (char**)kwlist, &s_cable, &product, &vendor))
  437 ++ return NULL;
  438 ++
  439 ++#ifndef EMBEDDED
  440 ++ if (!strcmp(s_cable, "ftdi"))
  441 ++ cable = CABLE_FTDI;
  442 ++ else if (!strcmp(s_cable, "xpc"))
  443 ++ cable = CABLE_XPC;
  444 ++ else
  445 ++ {
  446 ++ PyErr_SetString(PyExc_TypeError, "Cable type must be {ftdi|xpc}");
  447 ++ return NULL;
  448 ++ }
  449 ++#else
  450 ++ cable = CABLE_EMBEDDED;
  451 ++#endif
  452 ++
  453 ++ std::auto_ptr<IOBase> io;
  454 ++ res = getIO( &io, cable, subtype, channel, vendor, product, dev, desc, serial);
  455 ++ if (res) /* some error happend*/
  456 ++ {
  457 ++ PyErr_SetString(PyExc_IOError, "Error connecting JTAG");
  458 ++ return NULL;
  459 ++ }
  460 ++
  461 ++ self->io = io.release();
  462 ++
  463 ++ self->io->setVerbose(verbose);
  464 ++
  465 ++ self->jtag = new Jtag(self->io);
  466 ++ self->jtag->setVerbose(verbose);
  467 ++
  468 ++ int num_devices = init_chain(*self->jtag, *self->db);
  469 ++
  470 ++ PyObject *result = 0;
  471 ++
  472 ++ if (num_devices != 0)
  473 ++ {
  474 ++ result = PyList_New(num_devices);
  475 ++ if (!result)
  476 ++ return NULL;
  477 ++ int i;
  478 ++ for (i = 0; i < num_devices; ++i)
  479 ++ {
  480 ++ int id = get_id(*self->jtag, *self->db, chainpos);
  481 ++ PyList_SetItem(result, i, PyLong_FromUnsignedLong(id));
  482 ++ }
  483 ++ } else
  484 ++ {
  485 ++ PyErr_SetString(PyExc_IOError, "Error init chain");
  486 ++ return NULL;
  487 ++ }
  488 ++
  489 ++ detect_chain(self->jtag, self->db);
  490 ++
  491 ++ if (!result)
  492 ++ {
  493 ++ Py_INCREF(Py_None);
  494 ++ return Py_None;
  495 ++ } else
  496 ++ {
  497 ++ return result;
  498 ++ }
  499 ++}
  500 ++
  501 ++static PyObject *
  502 ++JTAG_program(JTAG *self, PyObject *args)
  503 ++{
  504 ++ int chainpos = 0;
  505 ++ int verify = 0;
  506 ++ int reconfigure = 0;
  507 ++
  508 ++ PyObject *file;
  509 ++
  510 ++ if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &file, &chainpos))
  511 ++ return NULL;
  512 ++
  513 ++ int id = get_id(*self->jtag, *self->db, chainpos);
  514 ++
  515 ++ if (id == 0)
  516 ++ {
  517 ++ PyErr_SetString(PyExc_IOError, "Illegal chain position");
  518 ++ return NULL;
  519 ++ }
  520 ++
  521 ++ unsigned int family = IDCODE_TO_FAMILY(id);
  522 ++ unsigned int manufacturer = IDCODE_TO_MANUFACTURER(id);
  523 ++
  524 ++ switch (manufacturer)
  525 ++ {
  526 ++ case MANUFACTURER_XILINX:
  527 ++ switch (family)
  528 ++ {
  529 ++ case FAMILY_XC3S:
  530 ++ case FAMILY_XC3SE:
  531 ++ case FAMILY_XC3SA:
  532 ++ case FAMILY_XC3SAN:
  533 ++ case FAMILY_XC3SD:
  534 ++ case FAMILY_XC6S:
  535 ++ case FAMILY_XCF:
  536 ++ case FAMILY_XC2V:
  537 ++ case FAMILY_XC2VP:
  538 ++ case FAMILY_XC5VLX:
  539 ++ case FAMILY_XC5VLXT:
  540 ++ case FAMILY_XC5VSXT:
  541 ++ case FAMILY_XC5VFXT:
  542 ++ case FAMILY_XC5VTXT:
  543 ++ {
  544 ++ BitFile bitfile;
  545 ++ FILE_STYLE in_style = STYLE_BIT;
  546 ++ bitfile.readFile(PyFile_AsFile(file), in_style);
  547 ++ try
  548 ++ {
  549 ++ int res = programXC3S(*self->jtag, bitfile, verify, reconfigure, family);
  550 ++ printf("result is %d\n", res);
  551 ++ }
  552 ++ catch (io_exception &e)
  553 ++ {
  554 ++ PyErr_SetString(PyExc_IOError, e.getMessage().c_str());
  555 ++ return NULL;
  556 ++ }
  557 ++ break;
  558 ++ }
  559 ++ default:
  560 ++ PyErr_SetString(PyExc_IOError, "unknown xilinx device");
  561 ++ return NULL;
  562 ++ }
  563 ++ break;
  564 ++ default:
  565 ++ PyErr_SetString(PyExc_IOError, "unknown manufacturer");
  566 ++ return NULL;
  567 ++ }
  568 ++ Py_INCREF(Py_None);
  569 ++ return Py_None;
  570 ++}
  571 ++
  572 ++static PyObject *
  573 ++JTAG_scanuser(JTAG *self, PyObject *args)
  574 ++{
  575 ++ int chainpos = 0;
  576 ++ unsigned char *buffer;
  577 ++ Py_ssize_t size;
  578 ++ if (!PyArg_ParseTuple(args, "w#|i", &buffer, &size, &chainpos))
  579 ++ return NULL;
  580 ++
  581 ++ unsigned char USER1[] = {0xC2, 0xFF};
  582 ++
  583 ++ if (self->jtag->selectDevice(chainpos) != chainpos)
  584 ++ {
  585 ++ PyErr_SetString(PyExc_IOError, "illegal chain position");
  586 ++ return NULL;
  587 ++ }
  588 ++
  589 ++ self->jtag->shiftIR(USER1);
  590 ++ self->jtag->shiftDR(buffer, buffer, size * 8);
  591 ++
  592 ++ Py_INCREF(Py_None);
  593 ++ return Py_None;
  594 ++}
  595 ++
  596 ++static PyMethodDef JTAG_methods[] = {
  597 ++ {"connect", (PyCFunction)JTAG_connect, METH_VARARGS | METH_KEYWORDS,
  598 ++ "Connect JTAG"
  599 ++ },
  600 ++ {"program", (PyCFunction)JTAG_program, METH_VARARGS,
  601 ++ "program bitstream"
  602 ++ },
  603 ++ {"scanuser", (PyCFunction)JTAG_scanuser, METH_VARARGS,
  604 ++ "scan user chain"
  605 ++ },
  606 ++ {NULL} /* Sentinel */
  607 ++};
  608 ++
  609 ++static PyTypeObject jtag_JTAGType = {
  610 ++ PyObject_HEAD_INIT(NULL)
  611 ++ 0, /*ob_size*/
  612 ++ "jtag.JTAG", /*tp_name*/
  613 ++ sizeof(JTAG), /*tp_basicsize*/
  614 ++ 0, /*tp_itemsize*/
  615 ++ (destructor)JTAG_dealloc, /*tp_dealloc*/
  616 ++ 0, /*tp_print*/
  617 ++ 0, /*tp_getattr*/
  618 ++ 0, /*tp_setattr*/
  619 ++ 0, /*tp_compare*/
  620 ++ 0, /*tp_repr*/
  621 ++ 0, /*tp_as_number*/
  622 ++ 0, /*tp_as_sequence*/
  623 ++ 0, /*tp_as_mapping*/
  624 ++ 0, /*tp_hash */
  625 ++ 0, /*tp_call*/
  626 ++ 0, /*tp_str*/
  627 ++ 0, /*tp_getattro*/
  628 ++ 0, /*tp_setattro*/
  629 ++ 0, /*tp_as_buffer*/
  630 ++ Py_TPFLAGS_DEFAULT, /*tp_flags*/
  631 ++ "JTAG objects", /* tp_doc */
  632 ++ 0, /* tp_traverse */
  633 ++ 0, /* tp_clear */
  634 ++ 0, /* tp_richcompare */
  635 ++ 0, /* tp_weaklistoffset */
  636 ++ 0, /* tp_iter */
  637 ++ 0, /* tp_iternext */
  638 ++ JTAG_methods, /* tp_methods */
  639 ++ 0, /* tp_members */
  640 ++ 0, /* tp_getset */
  641 ++ 0, /* tp_base */
  642 ++ 0, /* tp_dict */
  643 ++ 0, /* tp_descr_get */
  644 ++ 0, /* tp_descr_set */
  645 ++ 0, /* tp_dictoffset */
  646 ++ 0, /* tp_init */
  647 ++ 0, /* tp_alloc */
  648 ++ JTAG_new, /* tp_new */
  649 ++};
  650 ++
  651 ++
  652 ++static PyMethodDef jtag_methods[] = {
  653 ++ {NULL} /* Sentinel */
  654 ++};
  655 ++
  656 ++extern "C" {
  657 ++#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
  658 ++#define PyMODINIT_FUNC void
  659 ++#endif
  660 ++PyMODINIT_FUNC
  661 ++initjtag(void)
  662 ++{
  663 ++ PyObject* m;
  664 ++
  665 ++ if (PyType_Ready(&jtag_JTAGType) < 0)
  666 ++ return;
  667 ++
  668 ++ m = Py_InitModule3("jtag", jtag_methods,
  669 ++ "JTAG module.");
  670 ++
  671 ++ Py_INCREF(&jtag_JTAGType);
  672 ++ PyModule_AddObject(m, "JTAG", (PyObject *)&jtag_JTAGType);
  673 ++}
  674 ++}
  675 +diff --git a/xc3sprog/utilities.cpp b/xc3sprog/utilities.cpp
  676 +index 1f77481..979f9f0 100644
  677 +--- a/xc3sprog/utilities.cpp
  678 ++++ b/xc3sprog/utilities.cpp
  679 +@@ -10,10 +10,14 @@
  680 + #include "io_exception.h"
  681 + #include "jtag.h"
  682 + #include "devicedb.h"
  683 ++#ifndef EMBEDDED
  684 + #include "ioparport.h"
  685 + #include "iofx2.h"
  686 + #include "ioftdi.h"
  687 + #include "ioxpc.h"
  688 ++#else
  689 ++#include "ioembedded.h"
  690 ++#endif
  691 + #include "utilities.h"
  692 +
  693 + extern char *optarg;
  694 +@@ -40,6 +44,7 @@ void detect_chain(Jtag *jtag, DeviceDB *db)
  695 +
  696 + CABLES_TYPES getCable(const char *given_name)
  697 + {
  698 ++#ifndef EMBEDDED
  699 + if (strcasecmp(given_name, "pp") == 0)
  700 + return CABLE_PP;
  701 + if (strcasecmp(given_name, "ftdi") == 0)
  702 +@@ -49,6 +54,9 @@ CABLES_TYPES getCable(const char *given_name)
  703 + if (strcasecmp(given_name, "xpc") == 0)
  704 + return CABLE_XPC;
  705 + return CABLE_UNKNOWN;
  706 ++#else
  707 ++ return CABLE_EMBEDDED;
  708 ++#endif
  709 + }
  710 +
  711 + const char * getCableName(CABLES_TYPES type)
  712 +@@ -59,6 +67,7 @@ const char * getCableName(CABLES_TYPES type)
  713 + case CABLE_FTDI: return "ftdi"; break;
  714 + case CABLE_FX2: return "fx2"; break;
  715 + case CABLE_XPC: return "xpc"; break;
  716 ++ case CABLE_EMBEDDED: return "embedded"; break;
  717 + default:
  718 + return "Unknown";
  719 + }
  720 +@@ -67,6 +76,7 @@ const char * getSubtypeName(int subtype)
  721 + {
  722 + switch (subtype)
  723 + {
  724 ++#ifndef EMBEDDED
  725 + case FTDI_NO_EN: return "No enable"; break;
  726 + case FTDI_IKDA: return "IKDA"; break;
  727 + case FTDI_OLIMEX: return "OLIMEX"; break;
  728 +@@ -74,6 +84,7 @@ const char * getSubtypeName(int subtype)
  729 + case FTDI_FTDIJTAG: return "FTDIJTAG"; break;
  730 + case FTDI_LLBBC: return "LLBBC"; break;
  731 + case FTDI_LLIF: return "LLIF"; break;
  732 ++#endif
  733 + default:
  734 + return "Unknown";
  735 + }
  736 +@@ -81,6 +92,7 @@ const char * getSubtypeName(int subtype)
  737 +
  738 + int getSubtype(const char *given_name, CABLES_TYPES *cable, int *channel)
  739 + {
  740 ++#ifndef EMBEDDED
  741 + if (strcasecmp(given_name, "ikda") == 0)
  742 + {
  743 + if (*cable == CABLE_NONE)
  744 +@@ -135,6 +147,7 @@ int getSubtype(const char *given_name, CABLES_TYPES *cable, int *channel)
  745 + *channel = 2;
  746 + return FTDI_LLIF;
  747 + }
  748 ++#endif
  749 + return -1;
  750 + }
  751 +
  752 +@@ -147,6 +160,7 @@ int getIO( std::auto_ptr<IOBase> *io, CABLES_TYPES cable, int subtype, int chan
  753 + return 1;
  754 + }
  755 +
  756 ++#ifndef EMBEDDED
  757 + if (cable == CABLE_PP)
  758 + {
  759 + try
  760 +@@ -189,6 +203,7 @@ int getIO( std::auto_ptr<IOBase> *io, CABLES_TYPES cable, int subtype, int chan
  761 + }
  762 + io->reset(new IOFtdi(vendor, product, desc, serial, subtype, channel));
  763 + }
  764 ++#if 0
  765 + else if(cable == CABLE_FX2)
  766 + {
  767 + if (vendor == 0)
  768 +@@ -197,6 +212,7 @@ int getIO( std::auto_ptr<IOBase> *io, CABLES_TYPES cable, int subtype, int chan
  769 + product = USRP_DEVICE;
  770 + io->reset(new IOFX2(vendor, product, desc, serial));
  771 + }
  772 ++#endif
  773 + else if(cable == CABLE_XPC)
  774 + {
  775 + if (vendor == 0)
  776 +@@ -219,6 +235,12 @@ int getIO( std::auto_ptr<IOBase> *io, CABLES_TYPES cable, int subtype, int chan
  777 + fprintf(stderr, "Reason: %s\n",e.getMessage().c_str());
  778 + return 1;
  779 + }
  780 ++#else
  781 ++ if (cable == CABLE_EMBEDDED)
  782 ++ io->reset(new IOEmbedded());
  783 ++ else
  784 ++ return 2;
  785 ++#endif
  786 + return 0;
  787 + }
  788 +
  789 +diff --git a/xc3sprog/utilities.h b/xc3sprog/utilities.h
  790 +index ad516ea..e983926 100644
  791 +--- a/xc3sprog/utilities.h
  792 ++++ b/xc3sprog/utilities.h
  793 +@@ -11,7 +11,8 @@ enum CABLES_TYPES
  794 + CABLE_PP,
  795 + CABLE_FTDI,
  796 + CABLE_FX2,
  797 +- CABLE_XPC
  798 ++ CABLE_XPC,
  799 ++ CABLE_EMBEDDED
  800 + };
  801 +
  802 + CABLES_TYPES getCable(const char *given_name);
  803 +diff --git a/xc3sprog/xc3sprog.cpp b/xc3sprog/xc3sprog.cpp
  804 +index c18af14..1af2554 100644
  805 +--- a/xc3sprog/xc3sprog.cpp
  806 ++++ b/xc3sprog/xc3sprog.cpp
  807 +@@ -37,9 +37,13 @@ Dmitry Teytelman [dimtey@gmail.com] 14 Jun 2006 [applied 13 Aug 2006]:
  808 +
  809 + #include "io_exception.h"
  810 + #include "ioparport.h"
  811 ++#ifndef EMBEDDED
  812 + #include "iofx2.h"
  813 + #include "ioftdi.h"
  814 + #include "ioxpc.h"
  815 ++#else
  816 ++#include "ioembedded.h"
  817 ++#endif
  818 + #include "bitfile.h"
  819 + #include "jtag.h"
  820 + #include "devicedb.h"
  821 +@@ -672,6 +688,7 @@ int main(int argc, char **args)
  822 + (family == FAMILY_XC6S) ||
  823 + (family == FAMILY_XCF) ||
  824 + (family == FAMILY_XC2V) ||
  825 ++ (family == FAMILY_XC2VP) ||
  826 + (family == FAMILY_XC5VLX) ||
  827 + (family == FAMILY_XC5VLXT) ||
  828 + (family == FAMILY_XC5VSXT) ||
  829 +@@ -763,6 +780,8 @@ int main(int argc, char **args)
  830 + int size = (id & 0x000ff000)>>13;
  831 + JedecFile file;
  832 + ProgAlgXC95X alg(jtag, size);
  833 ++ if (erase)
  834 ++ return alg.erase();
  835 + if (!readback)
  836 + {
  837 + int res = file.readFile(fpin);

0 comments on commit acd8e4a

Please sign in to comment.
Something went wrong with that request. Please try again.