Ejemplo n.º 1
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; 
}
Ejemplo n.º 2
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;
    }
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
    }
}