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); } }
int main(int argc, char **args) { // Produce release info from CVS tags char release[]={"$Name: Release-0-5 $"}; char *loc0=strchr(release,'-'); if(loc0>0){ loc0++; char *loc=loc0; do{ loc=strchr(loc,'-'); if(loc)*loc='.'; }while(loc); release[strlen(release)-1]='\0'; // Strip off $ } printf("Release %s\n",loc0); sakcXCProgrammer io; int chainpos=0; if(io.checkError()){ fprintf(stderr,"Can map physical address into virtual space! or can not open '%s'.\n",MEMDEV); } if(argc<=1){ fprintf(stderr,"\nUsage: %s infile.bit [POS]\n\n",args[0]); fprintf(stderr,"\tPOS position in JTAG chain, 0=closest to TDI (default)\n\n",args[0]); return 1; } if(argc>2)chainpos=atoi(args[2]); BitFile file; if(file.load(args[1]))process(io,file,chainpos); else return 1; return 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); } }
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"); }
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; }
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); }
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); }
int main(int argc, char **args) { char release[]={"$Name: Release-0-3 $"}; char *loc0=strchr(release,'-'); if(loc0>0){ loc0++; char *loc=loc0; do{ loc=strchr(loc,'-'); if(loc)*loc='.'; }while(loc); release[strlen(release)-1]='\0'; // Strip off $ } printf("Release %s\n",loc0); IOParport io(PPDEV); int chainpos=0; 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); } if(argc<=1){ fprintf(stderr,"\nUsage: %s infile.bit [POS]\n\n",args[0]); fprintf(stderr,"\tPOS position in JTAG chain, 0=closest to TDI (default)\n\n",args[0]); return 1; } if(argc>2)chainpos=atoi(args[2]); BitFile file; if(file.load(args[1]))process(io,file,chainpos); else return 1; return 0; }
int main(int argc, char**args) { BitFile file; if(argc>1){ int length=file.load(args[1]); file.getData(); if(length>0){ printf("Created from NCD file: %s\n",file.getNCDFilename()); printf("Target device: %s\n",file.getPartName()); printf("Created: %s %s\n",file.getDate(),file.getTime()); printf("Bitstream length: %d bits\n",length); } else return 1; } if(argc>2)if(file.saveAsBin(args[2])>0)printf("Bitstream saved in binary format in file: %s\n",args[2]); if(argc<2){ fprintf(stderr,"Usage: %s infile.bit [outfile.bin]\n",args[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; }
int PPMCompressor::CompressFile(BitFile &inputFile, BitFile &outputFile, bool paramVerbose) { int result; unsigned char curSymbol; int curOrder,i; std::string context; ContextModel *CM; Intervals curInterval; RangeCoder RC; unsigned int mask[256]; unsigned int cumFreq; long int fSize, kSymb; FILE *f = tmpfile(); RC.StartEncode(f); CM = new ContextModel[ORDER+1]; for (i = 0; i <= ORDER; ++i) { CM[i].SetOrder(i); } context = ""; fSize = inputFile.GetFileSize(); kSymb = 0; if (paramVerbose) printProcentsBar(kSymb,fSize); do { inputFile.Read(&curSymbol,sizeof(char)); if ( !inputFile.FEOF() ) { if (paramVerbose) printProcentsBar(++kSymb,fSize); curOrder = ORDER; for (i = 0; i < 256; ++i) { mask[i] = 0; } do { result = CM[curOrder].GetInterval(context, curSymbol, curInterval, &mask[0]); if (result != 2) { // если контекст существует RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq); } --curOrder; } while ( result != 0 && curOrder>=0); //пока окончательно не закодировали символ и не зашли за границу порядка if (result != 0) { //кодируем по равновероятностной модели for (i = 0, cumFreq = 0; i < 256; ++i) { if (mask[i] == 0) { if (i == (int)curSymbol) { curInterval.cumFreq = cumFreq; curInterval.curFreq = 1; } cumFreq += 1; } } curInterval.totalFreq = cumFreq + 1; RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq); } for (curOrder=0; curOrder <= ORDER; ++curOrder) { CM[curOrder].UpdateContextModel(context, curSymbol); } context.push_back(curSymbol); context = cutString(context,ORDER); } } while ( !inputFile.FEOF() ); //записываем символ конца файла. Он кодируется как уход в модели -1 порядка curOrder = ORDER; for (i = 0; i < 256; ++i) { mask[i] = 0; } do { result = CM[curOrder].GetInterval(context, curSymbol, curInterval,&mask[0], true); if (result != 2) { // если контекст существует RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq); } --curOrder; } while ( curOrder>=0); //пока окончательно не закодировали символ и не зашли за границу порядка //кодируем по равновероятностной модели for (i = 0, cumFreq = 0; i < 256; ++i) { if (mask[i] == 0) { cumFreq += 1; } } curInterval.cumFreq = cumFreq; curInterval.curFreq = 1; curInterval.totalFreq = cumFreq + 1; RC.encode(curInterval.cumFreq,curInterval.curFreq,curInterval.totalFreq); RC.FinishEncode(); fseek(f,0,SEEK_SET); while (!feof(f)) { result = fread(&curSymbol, sizeof(curSymbol),1,f); outputFile.Write(&curSymbol,sizeof(curSymbol)); } fclose(f); delete[] CM; return 0; }
int PPMCompressor::DecompressFile(BitFile &inputFile, BitFile &outputFile,bool paramVerbose) { int result; unsigned int i; long int fSize; int curOrder, curDecodeOrder; unsigned int cum_freq=0, totFreq, CumFreqUnder; unsigned int mask[256]; bool EndOfFile, found; std::string context; RangeCoder RC; ContextModel *CM; Intervals curInterval; unsigned char curSymbol; FILE *f; f = tmpfile(); while (inputFile.FEOF() == false) { result = inputFile.Read(&curSymbol, sizeof(curSymbol)); result = fwrite(&curSymbol, sizeof(curSymbol),1, f); } fseek(f,0,SEEK_SET); //инициализация RC.StartDecode(f); CM = new ContextModel[ORDER+1]; for (curOrder = 0; curOrder <= ORDER; ++curOrder) { CM[curOrder].SetOrder(curOrder); } context = ""; curDecodeOrder = -1; totFreq = 257; EndOfFile = false; for (i = 0; i < 256; ++i) { mask[i] = 0; } fSize = inputFile.GetFileSize(); if (paramVerbose) printProcentsBar(0,fSize); do { cum_freq = RC.get_freq(totFreq); if (curDecodeOrder == -1) { for (i = 0, found = false, CumFreqUnder = 0; i < 256; ++i) { if (mask[i] == 0) { if ( found == false && (CumFreqUnder + 1) > cum_freq ) { curSymbol = (unsigned char)i; curInterval.cumFreq = CumFreqUnder; curInterval.curFreq = 1; found = true; } CumFreqUnder += 1; mask[i] = 1; } } curInterval.totalFreq = CumFreqUnder + 1; if (found == false) { EndOfFile = true; curInterval.curFreq = 1; curInterval.cumFreq = CumFreqUnder; } RC.decode_update(curInterval.cumFreq,curInterval.curFreq, curInterval.totalFreq); if (found == true) { outputFile.Write(&curSymbol, sizeof(curSymbol)); for (curOrder=0; curOrder <= ORDER; ++curOrder) { CM[curOrder].UpdateContextModel(context, curSymbol); } if (paramVerbose) printProcentsBar(ftell(f),fSize); context.push_back(curSymbol); context = cutString(context,ORDER); for (i = 0; i < 256; ++i) { mask[i] = 0; } //находим значение максимального порядка, по которому будем декодировать curDecodeOrder = ORDER; for (curOrder = curDecodeOrder, totFreq = 0; curOrder >= 0 && totFreq == 0; --curOrder) { totFreq = CM[curOrder].GetTotalFreq( cutString(context, curOrder)); curDecodeOrder = curOrder; } if (totFreq == 0) { totFreq = 257; curDecodeOrder = -1; } } } else { result = CM[curDecodeOrder].GetSymbol( cutString(context, curDecodeOrder) , cum_freq,curSymbol,curInterval, &mask[0]); RC.decode_update(curInterval.cumFreq,curInterval.curFreq, curInterval.totalFreq); if (result == 0) { outputFile.Write(&curSymbol, sizeof(curSymbol)); for (curOrder=0; curOrder <= ORDER; ++curOrder) { CM[curOrder].UpdateContextModel(context, curSymbol); } if (paramVerbose) printProcentsBar(ftell(f),fSize); context.push_back(curSymbol); context = cutString(context,ORDER); for (i = 0; i < 256; ++i) { mask[i] = 0; } //находим значение максимального порядка, по которому можно декодировать curDecodeOrder = ORDER; for (curOrder = curDecodeOrder, totFreq = 0; curOrder >= 0 && totFreq == 0; --curOrder) { totFreq = CM[curOrder].GetTotalFreq( cutString(context, curOrder)); curDecodeOrder = curOrder; } if (totFreq == 0) { totFreq = 257; curDecodeOrder = -1; } } else { --curDecodeOrder; if (curDecodeOrder>=0) { totFreq = CM[curDecodeOrder].GetTotalFreq( cutString(context, curDecodeOrder) , &mask[0]); } else { for (i = 0, CumFreqUnder = 0; i<256; ++i) { if (mask[i] == 0) { CumFreqUnder += 1; } } totFreq = CumFreqUnder + 1; } } } }while (!feof(f) && !EndOfFile); if (paramVerbose) printProcentsBar(fSize,fSize); RC.FinishDecode(); fclose(f); delete[] CM; return 0; }
int main(int argc, char **args) { bool verbose = false; char *device = NULL; int ch, ll_driver = DRIVER_PARPORT; IOBase *io; IOParport io_pp; IOFtdi io_ftdi; // Produce release info from CVS tags char release[]={"$Name: Release-0-5 $"}; char *loc0=strchr(release,'-'); if(loc0>0){ loc0++; char *loc=loc0; do{ loc=strchr(loc,'-'); if(loc)*loc='.'; }while(loc); release[strlen(release)-1]='\0'; // Strip off $ } printf("Release %s\n",loc0); // Start from parsing command line arguments while ((ch = getopt(argc, args, "c:d:v")) != -1) switch ((char)ch) { case 'c': if (strcmp(optarg, "pp") == 0) ll_driver = DRIVER_PARPORT; else if (strcmp(optarg, "ftdi") == 0) ll_driver = DRIVER_FTDI; else usage(); break; case 'd': device = strdup(optarg); break; case 'v': verbose = true; break; default: usage(); } if ((device == NULL) && (ll_driver == DRIVER_PARPORT)) if(getenv("XCPORT")) device = strdup(getenv("XCPORT")); else device = strdup(PPDEV); switch (ll_driver) { case DRIVER_PARPORT: io = &io_pp; break; case DRIVER_FTDI: io = &io_ftdi; break; default: usage(); } io->setVerbose(verbose); printf("argc: %d\n", argc); // Get rid of options argc -= optind; args += optind; printf("argc: %d\n", argc); if(argc<1) usage(); io->dev_open(device); if(io->checkError()){ if (ll_driver == DRIVER_FTDI) fprintf(stderr, "Could not access USB device (%s).\n", (device == NULL) ? "*" : device); else { fprintf(stderr,"Could not access parallel device '%s'.\n", device); fprintf(stderr,"You may need to set permissions of '%s' \n", device); fprintf(stderr, "by issuing the following command as root:\n\n# chmod 666 %s\n\n", device); } return 1; } free(device); int chainpos=0; if(argc>1)chainpos=atoi(args[1]); if(verbose) printf("JTAG chainpos: %d\n", chainpos); int length; BitFile file; if((length = file.load(args[0]))) { if (verbose) { printf("Created from NCD file: %s\n",file.getNCDFilename()); printf("Target device: %s\n",file.getPartName()); printf("Created: %s %s\n",file.getDate(),file.getTime()); printf("Bitstream length: %d bits\n",length); } process(*io, file, chainpos, verbose); } else return 1; return 0; }
static PyObject * JTAG_program(JTAG *self, PyObject *args) { int chainpos = 0; int verify = 0; int reconfigure = 0; PyObject *file; if (!PyArg_ParseTuple(args, "O!|i", &PyFile_Type, &file, &chainpos)) return NULL; int id = get_id(*self->jtag, *self->db, chainpos); if (id == 0) { PyErr_SetString(PyExc_IOError, "Illegal chain position"); return NULL; } unsigned int family = IDCODE_TO_FAMILY(id); unsigned int manufacturer = IDCODE_TO_MANUFACTURER(id); switch (manufacturer) { case MANUFACTURER_XILINX: switch (family) { case FAMILY_XC3S: case FAMILY_XC3SE: case FAMILY_XC3SA: case FAMILY_XC3SAN: case FAMILY_XC3SD: case FAMILY_XC6S: case FAMILY_XCF: case FAMILY_XC2V: case FAMILY_XC2VP: case FAMILY_XC5VLX: case FAMILY_XC5VLXT: case FAMILY_XC5VSXT: case FAMILY_XC5VFXT: case FAMILY_XC5VTXT: { BitFile bitfile; FILE_STYLE in_style = STYLE_BIT; bitfile.readFile(PyFile_AsFile(file), in_style); try { int res = programXC3S(*self->jtag, bitfile, verify, reconfigure, family); printf("result is %d\n", res); } catch (io_exception &e) { PyErr_SetString(PyExc_IOError, e.getMessage().c_str()); return NULL; } break; } default: PyErr_SetString(PyExc_IOError, "unknown xilinx device"); return NULL; } break; default: PyErr_SetString(PyExc_IOError, "unknown manufacturer"); return NULL; } Py_INCREF(Py_None); return Py_None; }
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; } }
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. }
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; } }