Пример #1
0
void ProgAlgXC3S::flow_program_legacy(BitFile &file)
{
  byte data[2];
  struct timeval tv[2];
  gettimeofday(tv, NULL);

  jtag->shiftIR(&JSHUTDOWN);
  io->cycleTCK(tck_len);
  jtag->shiftIR(&CFG_IN);
  jtag->shiftDR((file.getData()),0,file.getLength());
  io->cycleTCK(1);
  jtag->shiftIR(&JSTART);
  io->cycleTCK(2*tck_len);
  jtag->shiftIR(&BYPASS);
  data[0]=0x0;
  jtag->shiftDR(data,0,1);
  io->cycleTCK(1);

  // Print the timing summary
  if (io->getVerbose())
    {
      gettimeofday(tv+1, NULL);
      printf("Done.\nProgramming time %.1f ms\n", (double)deltaT(tv, tv + 1)/1.0e3);
    }

}
Пример #2
0
int ProgAlgXC3S::program(BitFile &file)
{
  jtag->shiftIR(&JPROGRAM);
  jtag->shiftIR(&CFG_IN);
  
  byte init[24];
  jtag->longToByteArray(0xffffffff,&init[0]); // Sync
  jtag->longToByteArray(0x66aa9955,&init[4]); // Sync
  jtag->longToByteArray(0x8001000c,&init[8]); // CMD
  jtag->longToByteArray(0xe0000000,&init[12]); // Clear CRC
  jtag->longToByteArray(0x00000000,&init[16]); // Flush
  jtag->longToByteArray(0x00000000,&init[20]); // Flush
  jtag->shiftDR(init,0,192,32); // Align to 32 bits.
  jtag->shiftIR(&JSHUTDOWN);
  io->cycleTCK(12);
  jtag->shiftIR(&CFG_IN);
  
  byte hdr[12];
  jtag->longToByteArray(0x8001000c,&hdr[0]); // CMD
  jtag->longToByteArray(0x10000000,&hdr[4]); // Assert GHIGH
  jtag->longToByteArray(0x00000000,&hdr[8]); // Flush
  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.
  printf("Done\n");
}
Пример #3
0
void ProgAlgXC3S::flow_program_legacy(BitFile &file)
{
  Timer timer;
  byte data[2];

  jtag->shiftIR(JSHUTDOWN);
  jtag->cycleTCK(tck_len);
  jtag->shiftIR(CFG_IN);
  jtag->shiftDR((file.getData()),0,file.getLength());
  jtag->cycleTCK(1);
  jtag->shiftIR(JSTART);
  jtag->cycleTCK(2*tck_len);
  jtag->shiftIR(BYPASS);
  data[0]=0x0;
  jtag->shiftDR(data,0,1);
  jtag->cycleTCK(1);
  
  // Print the timing summary
  if (jtag->getVerbose())
    {
      fprintf(stderr, "done. Programming time %.1f ms\n",
	      timer.elapsed() * 1000);
    }
 
}
Пример #4
0
void ProgAlgXC3S::flow_program_xc2s(BitFile &file)
{
    byte data[2];
    byte xc2sbuf0[] =
        {
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x55, 0x99, 0xaa, 0x66,
            0x0c, 0x80, 0x04, 0x80, /*Header: Write to COR*/
            0x00, 0x05, 0xfd, 0xbc, /* OR data sets SHUTDOWN = 1 */
            0x0c, 0x00, 0x01, 0x80, /*-> Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xa0, /*Start Shutdown*/
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xe0, /*RCRC command*/
            0x00, 0x00, 0x00, 0x00
        };
    byte xc2sbuf1[] =
        {
            0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00,
            0x55, 0x99, 0xaa, 0x66,
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0x10, /* Assert GHIGH */
            0x0c, 0x80, 0x04, 0x80, /*Header: Write to COR*/
            0x00, 0x05, 0xfc, 0xff, /* OR data sets SHUTDOWN = 0 */
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xa0, /*Start command*/
            0x0c, 0x00, 0x01, 0x80, /* Header: Write to CMD*/
            0x00, 0x00, 0x00, 0xe0, /*RCRC command*/
            0x00, 0x00, 0x00, 0x00
        };
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf0,0, sizeof(xc2sbuf0) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf1,0, sizeof(xc2sbuf1) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR(xc2sbuf0,0, sizeof(xc2sbuf0) *8);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    
    jtag->shiftIR(CFG_IN);
    jtag->shiftDR((file.getData()),0,file.getLength());
    jtag->cycleTCK(1);
    jtag->shiftIR(JSTART);
    jtag->cycleTCK(13);
    jtag->shiftIR(BYPASS);
    jtag->shiftDR(data,0,1);
    jtag->cycleTCK(1);
    return;
  }
Пример #5
0
void ProgAlgXC3S::flow_array_program(BitFile &file)
{
  Timer timer;
  unsigned int i;
  for(i=0; i<file.getLength(); i += array_transfer_len)
    {
      jtag->shiftIR(ISC_PROGRAM);
      jtag->shiftDR(&(file.getData())[i/8],0,array_transfer_len);
      jtag->cycleTCK(1);
      if((i % (10000*array_transfer_len)) == 0)
	{
	  fprintf(stderr,".");
	  fflush(stderr);
	}
    }
  
  // Print the timing summary
  if (jtag->getVerbose())
    fprintf(stderr, " done. Programming time %.1f ms\n",
	    timer.elapsed() * 1000);
}
Пример #6
0
void ProgAlgXC3S::flow_array_program(BitFile &file)
{
  struct timeval tv[2];
  unsigned int i;
  gettimeofday(tv, NULL);
  for(i=0; i<file.getLength(); i= i+ array_transfer_len)
    {
      jtag->shiftIR(&ISC_PROGRAM);
      jtag->shiftDR(&(file.getData())[i/8],0,array_transfer_len);
      io->cycleTCK(1);
      if((i % (10000*array_transfer_len)) == 0)
	{
	  fprintf(stdout,".");
	  fflush(stdout);
	}
    }
  gettimeofday(tv+1, NULL);

  // Print the timing summary
  if (io->getVerbose())
    printf(" Done.\nProgramming time %.1f ms\n", (double)deltaT(tv, tv + 1)/1.0e3);
}
Пример #7
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.
}
Пример #8
0
int main(int argc, char**args)
{
  bool verbose = false;
  bool revert  = false;
  const char * outfile = NULL;
  FILE_STYLE  in_style = STYLE_BIT;
  FILE_STYLE out_style = STYLE_BIT;
  char device[256]= "";
  FILE *fp = NULL;
  const char * mapdir = NULL;
  fprintf(stderr, "Release $Rev: 237 $\n"
	  "Please provide feedback on success/failure/enhancement requests!\n"
	  "Check Sourceforge SVN for updates!\n");

  while(true) {
    switch(getopt(argc, args, "?m:i:vo:O:")) {
    case -1:
     goto args_done;

    case 'v':
      verbose = true;
      break;

    case 'i':
      if (BitFile::styleFromString(optarg, &in_style))
	{
	  fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	  usage();
	}
      break;
      
    case 'o':
      if (BitFile::styleFromString(optarg, &out_style))
	{
	  fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	  usage();
	}
      break;
      
    case 'm':
      mapdir = optarg;
      break;
 
    case 'O':
      outfile = optarg;
      break;
      
    case '?':
    case 'h':
    default:
      usage();
    }
  }
 args_done:
  argc -= optind;
  args += optind;
  if(argc < 1)
    usage();
  MapFile_XC2C map;
  JedecFile  fuses;
  BitFile bits;
  if (*args[0] == '-')
    fp = stdin;
  else
    {
      fp=fopen(args[0],"rb");
      if(!fp)
	{
	  fprintf(stderr, "Can't open datafile %s: %s\n", args[0], 
		  strerror(errno));
	  return 1;
	}
    }
  
  if (fuses.readFile(fp) == 0)
    {
      if (verbose)
	fprintf(stderr,"Jedecfile %s for %s: %d Fuses, Checksum: 0x%04x\n", 
		args[0], fuses.getDevice(), fuses.getLength(),
		fuses.getChecksum());
      strncpy(device, fuses.getDevice(), 255);
    }
  else
    {
      if (*args[0] == '-')
	fp = stdin;
      else
	{
	  fp=fopen(args[0],"rb");
	  if(!fp)
	    {
	      fprintf(stderr, "Can't open datafile %s: %s\n", args[0], 
		  strerror(errno));
	      return 1;
	    }
	}
      if (bits.readFile(fp, in_style) == 0 )
	{
	  if (verbose)
	    fprintf(stderr,"Got Bitfile for Device %s: %ld Fuses\n", 
		    bits.getPartName(), bits.getLength());
	  revert = true;
	  strncpy(device, bits.getPartName(), 255);
	}
      
      else
	{
	  fprintf(stderr, "File %s not recognized as Bit- or Jedecfile\n",
		  args[0]);
	  return 3;
	}
    }
  if (map.loadmapfile(mapdir, device))
    {
      fprintf(stderr, "failed to load Mapfile %s, aborting\n",
	      map.GetFilename());
      return 2;
    }
  if(outfile)
    {
      fp = fopen(outfile,"wb");
      if (!fp)
	{
	  fprintf(stderr, "failed to open %s: %s\n", outfile,
		  strerror(errno));
	  return 1;
	}
    }
  else return 0;
  if (revert)
    {
      map.bitfile2jedecfile(&bits, &fuses);
      fprintf(stderr, "Device %s: %d Fuses, Checksum calculated: 0x%04x,"
	      " Checksum from file 0x%04x\n",
		 fuses.getDevice(), fuses.getLength(), fuses.calcChecksum(),
	      fuses.getChecksum());
      fuses.saveAsJed( device, fp);
    }
  else
    {
      map.jedecfile2bitfile(&fuses, &bits);
      bits.saveAs(out_style, device, fp);
     }
  return 0; 
}
Пример #9
0
int main(int argc, char**args)
{

  FILE_STYLE in_style  = STYLE_BIT;
  FILE_STYLE out_style = STYLE_BIT;
  const char * outfile = NULL;
  while(true)
    {
      switch(getopt(argc, args, "?i:vo:O:"))
	{
	case -1: goto args_done;
	case 'i':
          if (BitFile::styleFromString(optarg, &in_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'o':
          if (BitFile::styleFromString(optarg, &out_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'O':
	  outfile = optarg;
	  break;
	case '?':
	case 'h':
	default:
	  usage();
	}
    }
 args_done:
  argc -= optind;
  args += optind;
  if(argc < 1)
    usage();
  try {
    BitFile  file;
    FILE* fp;
    if (*args[0] == '-')
      fp = stdin;
    else
      {
	fp=fopen(args[0],"rb");
	if(!fp)
	  {
	    fprintf(stderr, "Can't open datafile %s: %s\n", args[0], 
		    strerror(errno));
	  return 1;
	  }
      }
    file.readFile(fp, in_style);
    fprintf(stderr, "Created from NCD file: %s\n",file.getNCDFilename());
    fprintf(stderr, "Target device: %s\n",file.getPartName());
    fprintf(stderr, "Created: %s %s\n",file.getDate(),file.getTime());
    fprintf(stderr, "Bitstream length: %lu bits\n", file.getLength());
    
    if(outfile) {
      if(outfile[0] == '-')
	fp = stdout;
      else
	fp = fopen(outfile,"wb");
      if (fp)
	{
	  file.saveAs(out_style,file.getPartName(), fp);
	  fprintf(stderr, "Bitstream saved in format %s as file: %s\n",
                  BitFile::styleToString(out_style), outfile);
	}
      else
	  fprintf(stderr," Can't open %s: %s  \n", outfile, strerror(errno));
      }
    }
    catch(io_exception& e) {
      fprintf(stderr, "IOException: %s", e.getMessage().c_str());
      return  1;
    }
}
Пример #10
0
int main(int argc, char**args)
{

  FILE_STYLE in_style  = STYLE_BIT;
  FILE_STYLE out_style = STYLE_BIT;
  uint64_t sum = 0L;
  unsigned int i;

  const char * outfile = NULL;
  while(true)
    {
      switch(getopt(argc, args, "?i:vo:O:"))
	{
	case -1: goto args_done;
	case 'i':
          if (BitFile::styleFromString(optarg, &in_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'o':
          if (BitFile::styleFromString(optarg, &out_style))
	    {
	      fprintf(stderr, "Unknown format \"%s\"\n", optarg);
	      usage();
	    }
	  break;

	case 'O':
	  outfile = optarg;
	  break;
	case '?':
	case 'h':
	default:
	  usage();
	}
    }
 args_done:
  argc -= optind;
  args += optind;
  if(argc < 1)
    usage();
  try {
    BitFile  file;
    FILE* fp;

    if (*args[0] == '-')
      fp = stdin;
    else
      {
	fp=fopen(args[0],"rb");
	if(!fp)
	  {
	    fprintf(stderr, "Can't open datafile %s: %s\n", args[0], 
		    strerror(errno));
	  return 1;
	  }
      }
    file.readFile(fp, in_style);
    fprintf(stderr, "Created from NCD file: %s\n",file.getNCDFilename());
    fprintf(stderr, "Target device: %s\n",file.getPartName());
    fprintf(stderr, "Created: %s %s\n",file.getDate(),file.getTime());
    fprintf(stderr, "Bitstream length: %u bits %u bytes(0x%06x)\n", 
            file.getLength(),file.getLength()/8,file.getLength()/8);

    for (i = 0; i < file.getLength()/8; i++)
    {
        /* Umprogrammed Bytes are 0xff, so invert
           to not count them
        */
        sum += (file.getData()[i]) ^0xff;
    }
    fprintf(stderr, "64-bit sum: %" PRIu64 "\n", sum);
    
    if(outfile) {
      if(outfile[0] == '-')
	fp = stdout;
      else
	fp = fopen(outfile,"wb");
      if (fp)
	{
	  file.saveAs(out_style,file.getPartName(), fp);
	  fprintf(stderr, "Bitstream saved in format %s as file: %s\n",
                  BitFile::styleToString(out_style), outfile);
	}
      else
	  fprintf(stderr," Can't open %s: %s  \n", outfile, strerror(errno));
      }
    }
    catch(io_exception& e) {
      fprintf(stderr, "IOException: %s", e.getMessage().c_str());
      return  1;
    }
}