Esempio n. 1
0
int main(int argc, char **args)
{
//  IOParport io(PPDEV);
  IOXUSB io("");
  
  if(io.checkError()){
    fprintf(stderr,"Could not access parallel device '%s'.\n",PPDEV);
    fprintf(stderr,"You may need to set permissions of '%s' ",PPDEV);
    fprintf(stderr,"by issuing the following command as root:\n\n# chmod 666 %s\n\n",PPDEV);
    return 1;
  }

  Jtag jtag(&io);
  int num=jtag.getChain();
  DeviceDB db(DEVICEDB);
  int dblast=0;
  for(int i=0; i<num; i++){
    unsigned long id=jtag.getDeviceID(i);
    int length=db.loadDevice(id);
    printf("IDCODE: 0x%08x\t",id);
    if(length>0){
      jtag.setDeviceIRLength(i,length);
      printf("Desc: %s\tIR length: %d\n",db.getDeviceDescription(dblast),length);
      dblast++;
    } 
    else{
      printf("not found in '%s'.\n",DEVICEDB);
    }
  }
  return 0;
}
Esempio n. 2
0
void process(IOBase &io, BitFile &file, int chainpos, bool verbose)
{
  char *devicedb = NULL;
  unsigned id;
  Jtag jtag(&io);
  int num=jtag.getChain();

  // Synchronise database with chain of devices.

  if(getenv("XCDB"))
    devicedb = strdup(getenv("XCDB"));
  else
    devicedb = strdup(DEVICEDB);

  DeviceDB db(devicedb);
  for(int i=0; i<num; i++){
    int length=db.loadDevice(jtag.getDeviceID(i));
    if(length>0)jtag.setDeviceIRLength(i,length);
    else{
      id=jtag.getDeviceID(i);
      fprintf(stderr,"Cannot find device having IDCODE=%08x\n",id);
      return;
    }
  }
  
  if(jtag.selectDevice(chainpos)<0){
    fprintf(stderr,"Invalid chain position %d, position must be less than %d (but not less than 0).\n",chainpos,num);
    return;
  }

  // Find the programming algorithm required for device
  const char *dd=db.getDeviceDescription(chainpos);

  if (verbose)
  {
    id = jtag.getDeviceID(chainpos);
    printf("Device IDCODE = 0x%08x\tDesc: %s\nProgramming: ", id, dd);
    fflush(stdout);
  }

  if(strncmp("XC3S",dd,4)==0) programXC3S(jtag,io,file);
  else if(strncmp("XC2V",dd,4)==0) programXC3S(jtag,io,file);
  else if(strncmp("XCF",dd,3)==0) { 
      int bs=(dd[4]-'0'==1) ? 2048 : 4096;
      if (verbose)
	printf("Device block size is %d.\n", bs);
      programXCF(jtag,io,file, bs);
    }
  else{
    fprintf(stderr,"Sorry, cannot program '%s', a later release may be able to.\n",dd);
    return;
  }
}
Esempio n. 3
0
void process(IOBase &io, BitFile &file, int chainpos)
{
  Jtag jtag(&io);
  int num=jtag.getChain();

  // Synchronise database with chain of devices.
  DeviceDB db(DEVICEDB);
  for(int i=0; i<num; i++){
    printf("ID=%x\n", jtag.getDeviceID(i));
    int length=db.loadDevice(jtag.getDeviceID(i));
    if(length>0)jtag.setDeviceIRLength(i,length);
    else{
      unsigned id=jtag.getDeviceID(i);
      fprintf(stderr,"Cannot find device having IDCODE=%08x\n",id);
      return;
    }
  }
  

  if(jtag.selectDevice(chainpos)<0){
    fprintf(stderr,"Invalid chain position %d, position must be less than %d (but not less than 0).\n",chainpos,num);
    return;
  }

  // Find the programming algorithm required for device
  const char *dd=db.getDeviceDescription(chainpos);
  if(strncmp("XC3S",dd,4)==0) {
    printf("Programming..\n");
    programXC3S(jtag,io,file);
  }
  else if(strncmp("XCF",dd,3)==0) programXCF(jtag,io,file);
  else{
    fprintf(stderr,"Sorry, cannot program '%s', a later release may be able to.\n",dd);
    return;
  }
}
Esempio n. 4
0
void process(IOBase &io, BitFile &file, int chainpos)
{
  const byte IDCODE=0x09;
  const byte XCF_IDCODE=0xfe;

  Jtag jtag(&io);
  int num=jtag.getChain();
  DeviceDB db(DEVICEDB);
  for(int i=0; i<num; i++){
    int length=db.loadDevice(jtag.getDeviceID(i));
    if(length>0)jtag.setDeviceIRLength(i,length);
    else{
      byte *id=jtag.getDeviceID(i);
      fprintf(stderr,"Cannot find device having IDCODE=%02x%02x%02x%02x\n",id[0],id[1],id[2],id[3]);
      return;
    }
  }
  

  byte tdo[4];

  if(jtag.selectDevice(chainpos)<0){
    fprintf(stderr,"Invalid chain position %d, position must be less than <%d.\n",chainpos,num);
    return;
  }

  jtag.shiftIR(&IDCODE);
  jtag.shiftDR(0,tdo,32);
  printf("IDCODE: 0x%02x%02x%02x%02x\tDesc: %s\n",tdo[0],tdo[1],tdo[2],tdo[3],db.getDeviceDescription(chainpos)); 

  const byte JPROGRAM=0x0b;
  const byte CFG_IN=0x05;
  const byte JSHUTDOWN=0x0d;
  const byte JSTART=0x0c;
  const byte BYPASS=0x3f;

  jtag.shiftIR(&JPROGRAM);
  jtag.shiftIR(&CFG_IN);
  byte init[]={0x00, 0x00, 0x00, 0x00, // Flush
	       0x00, 0x00, 0x00, 0x00, // Flush
	       0xe0, 0x00, 0x00, 0x00, // Clear CRC
	       0x80, 0x01, 0x00, 0x0c, // CMD
	       0x66, 0xAA, 0x99, 0x55, // Sync
	       0xff, 0xff, 0xff, 0xff  // Sync
  };
  jtag.shiftDR(init,0,192,32); // Align to 32 bits.
  jtag.shiftIR(&JSHUTDOWN);
  io.cycleTCK(12);
  jtag.shiftIR(&CFG_IN);
  byte hdr[]={0x00, 0x00, 0x00, 0x00, // Flush
	      0x10, 0x00, 0x00, 0x00, // Assert GHIGH
	      0x80, 0x01, 0x00, 0x0c  // CMD
  };
  jtag.shiftDR(hdr,0,96,32,false); // Align to 32 bits and do not goto EXIT1-DR
  jtag.shiftDR(file.getData(),0,file.getLength()); 
  io.tapTestLogicReset();
  io.setTapState(IOBase::RUN_TEST_IDLE);
  jtag.shiftIR(&JSTART);
  io.cycleTCK(12);
  jtag.shiftIR(&BYPASS); // Don't know why, but without this the FPGA will not reconfigure from Flash when PROG is asserted.
}
Esempio n. 5
0
int main(int argc, char **args)
{
    bool        verbose = false;
    bool     use_ftd2xx = false;
    struct cable_t cable;
    char const *dev     = 0;
    char const *serial  = 0;
    char const *cablename = 0;
    unsigned int jtag_freq = 0;
    byte idata[8];
    byte odata[8];
    int chainpos =0;
    char *devicedb = NULL;
    std::auto_ptr<IOBase>  io;
    DeviceDB db(devicedb);
    int i, res;
   
    // Start from parsing command line arguments
    while(true) {
      switch(getopt(argc, args, "?hvc:d:J:L")) {
      case -1:
	goto args_done;
		
      case 'v':
	verbose = true;
	break;
      
      case 'J':
        jtag_freq = atoi(optarg);
        break;

      case 'L':
	use_ftd2xx = true;
	break;
      
      case 'c':
	cablename =  optarg;
	break;
		
      case 'd':
	dev = optarg;
	break;
		
      case 's':
	serial = optarg;
	break;
		
      case '?':
      case 'h':
      default:
	usage();
      }
    }
args_done:
  // Get rid of options
  //printf("argc: %d\n", argc);
  argc -= optind;
  args += optind;
  //printf("argc: %d\n", argc);
  if((argc != 0) || (cablename == 0)) usage();
  
  if (verbose)
    fprintf(stderr, "Using %s\n", db.getFile().c_str());
 
  CableDB cabledb(0);
  res = cabledb.getCable(cablename, &cable);
  res = getIO( &io, &cable, dev, serial, verbose, use_ftd2xx, jtag_freq);
  if (res) /* some error happend*/
    {
      if (res == 1) exit(1);
      else usage();
    }
  io.get()->setVerbose(verbose);
  
  Jtag jtag(io.get());
  jtag.setVerbose(verbose);
  get_id (jtag, db, chainpos, verbose);

  if (verbose)
    fprintf(stderr, "Using %s\n", db.getFile().c_str());
#define CFG_IN      0x05
#define ISC_ENABLE  0x10
#define ISC_DISABLE 0x16
#define JPROGRAM    0x0b
#define ISC_DNA     0x31
#define BYPASS      0x3f
  jtag.selectDevice(chainpos);

  idata[0] = JPROGRAM;
  jtag.shiftIR(idata);
  idata[0] = CFG_IN;
  do
    jtag.shiftIR(idata, odata);
  while (! (odata[0] & 0x10)); /* wait until configuration cleared */
  /* As ISC_DNA only works on a unconfigured device, see AR #29977*/

  idata[0] = ISC_ENABLE;
  jtag.shiftIR(idata);
  idata[0] = ISC_DNA;
  jtag.shiftIR(idata);
  jtag.shiftDR(0, odata, 64);
  if (*(long long*)odata != -1LL)
    printf("DNA is 0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 
		 odata[0], odata[1], odata[2], odata[3], 
		 odata[4], odata[5], odata[6], odata[7]);

  idata[0] = ISC_DISABLE;
  jtag.shiftIR(idata);

  /* Release JTAG control over configuration (AR 16829)*/
  jtag.tapTestLogicReset();
  idata[0] = JPROGRAM;
  jtag.shiftIR(idata); 
  /* Now device will reconfigure from standard configuration source */
  idata[0] = BYPASS;
  fprintf(stderr, "Will wait up to 10 seconds for device to reconfigure.");
  fflush(stderr);
  do
    {
      jtag.Usleep(1000);
      jtag.shiftIR(idata, odata);
      if(i%250 == 249)
	{
	  fprintf(stderr, ".");
	  fflush(stderr);
	}
      i++;
    }
  while ((( odata[0] & 0x23) != 0x21) && (i <10000));
  fprintf(stderr, "\n");

  return 0;
}