in common/recipes-utils/cpldupdate-jtag/files/jedecfile.c [438:606]
void jedec_save_as_jed(const char *device, FILE *fp)
{
unsigned int i, b=0, l=0 ,w=0;
unsigned short chksum=0;
unsigned int DRegLength;
int type=-1;
if (!fp)
return;
if (strnicmp("XC9536",device, sizeof("XC9536X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC9572",device, sizeof("XC9572X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC95108",device, sizeof("XC95144X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC95144",device, sizeof("XC95288X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC95216",device, sizeof("XC95288X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC95288",device, sizeof("XC95288X")-1) == 0)
{
type = JED_XC95;
}
else if (strnicmp("XC9536X",device, sizeof("XC9536X")-1) == 0)
{
type = JED_XC95X;
DRegLength=2;
}
else if (strnicmp("XC9572X",device, sizeof("XC9572X")-1) == 0)
{
type = JED_XC95X;
DRegLength=4;
}
else if (strnicmp("XC95144X",device, sizeof("XC95144X")-1) == 0)
{
type = JED_XC95X;
DRegLength=8;
}
else if (strnicmp("XC95288X",device, sizeof("XC95288X")-1) == 0)
{
type = JED_XC95X;
DRegLength=16;
}
else if (strnicmp("XC2C",device, sizeof("XC2C")-1) == 0)
{
type = JED_XC2C;
}
if (strlen(jed.date) == 0)
{
time_t t;
struct tm *tmp;
char outstr[200];
t = time(NULL);
tmp = localtime(&t);
if (tmp != NULL)
{
if (strftime(outstr, sizeof(outstr), "%a %b %d %T %Y", tmp)){
fprintf(fp, "Date Extracted: %s\n\n", outstr);
}
}
}else{
fprintf(fp, "Date Extracted%s\n\n",jed.date);
}
fprintf(fp, "\2QF%d*\nQV0*\nF0*\nX0*\nJ0 0*\n",jed.fuse_count);
if (strlen(jed.version) == 0)
fprintf(fp, "N VERSION XC3SPROG*\n");
else
fprintf(fp, "N VERSION %s*\n",jed.version);
fprintf(fp, "N DEVICE %s*\n", device);
if(type == JED_XC95X)
{
/* Xilinx Impact (10.1) needs following additional items
* to recognizes as a valid Jedec File
* the 4 Digits as total Checksum
* N DEVICE
*/
for (i=0; i<jed.fuse_count; i++)
{
if(!w && !b)
fprintf(fp, "L%07d",i);
if (!b)
fprintf(fp, " ");
fprintf(fp, "%d", jedec_get_fuse(i));
if (l<9)
{
if(b==7)
b=0;
else
b++;
}
else
{
if (b == 5)
b = 0;
else
b++;
}
if(!b)
{
if (w == (DRegLength-1))
{
fprintf(fp, "*\n");
w = 0;
l++;
}else{
w++;
}
}
if (l==15){
l =0;
}
}
}
else if(type == JED_XC95)
{
for (i=0; i<jed.fuse_count; i++)
{
if(!b && w%5 == 0)
fprintf(fp, "L%07d",i);
if (!b)
fprintf(fp, " ");
fprintf(fp, "%d", jedec_get_fuse(i));
if( b == (((i%9072)<7776) ? ((w %15 < 9)?7:5):((w%5== 0)?7:6)))
{
b=0;
w++;
}
else
b++;
if(!b && (w %5 == 0 ))
fprintf(fp, "*\n");
}
}
else if (type == JED_XC2C)
{
for (i=0; i<jed.fuse_count; i++)
{
if ((i %64) == 0){
fprintf(fp, "L%07d ",i);
}
fprintf(fp, "%d", jedec_get_fuse(i));
if ((i %64) == 63){
fprintf(fp, "*\n");
}
}
fprintf(fp, "*\n");
}
for(i=0; i<(jed.fuse_count/8 + ((jed.fuse_count%8)?1:0)); i++){
chksum += jed.fuse_list[i];
}
fprintf(fp, "C%04X*\n%c0000\n", chksum, 3);
}