forked from makestuff/libfpgalink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fx2.c
456 lines (439 loc) · 17 KB
/
fx2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
* Copyright (C) 2009-2012 Chris McClelland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <makestuff.h>
#include <libfx2loader.h>
#include <liberror.h>
#include <libusbwrap.h>
#include "vendorCommands.h"
#include "libfpgalink.h"
#include "private.h"
#include "firmware.h"
static FLStatus convertJtagFileToCsvf(
struct Buffer *dest, const char *xsvfFile, const char **error
) WARN_UNUSED_RESULT;
// On port A, only bits 0, 1, 3 & 7 are available. The other bits are used by the slave FIFOs.
static bool isInvalidPortABit(uint8 bit) {
return (bit == 2 || bit == 4 || bit == 5 || bit == 6);
}
// Load the standard FPGALink firmware into the FX2 at currentVid/currentPid.
DLLEXPORT(FLStatus) flLoadStandardFirmware(
const char *curVidPid, const char *newVidPid, const char *jtagPort, const char **error)
{
FLStatus flStatus, returnCode;
struct Buffer ramBuf = {0,};
BufferStatus bStatus;
FX2Status fxStatus;
struct USBDevice *device = NULL;
int uStatus;
uint16 newVid, newPid, newDid;
uint8 port, tdoBit, tdiBit, tmsBit, tckBit;
if ( !usbValidateVidPid(newVidPid) ) {
errRender(error, "flLoadStandardFirmware(): The supplied VID:PID:DID \"%s\" is invalid; it should look like 1D50:602B or 1D50:602B:0001", newVidPid);
FAIL(FL_USB_ERR);
}
newVid = (uint16)strtoul(newVidPid, NULL, 16);
newPid = (uint16)strtoul(newVidPid+5, NULL, 16);
newDid = (strlen(newVidPid) == 14) ? (uint16)strtoul(newVidPid+10, NULL, 16) : 0x0000;
if ( strlen(jtagPort) != 5 ) {
errRender(error, "flLoadStandardFirmware(): JTAG port specification must be <C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
if ( (jtagPort[0] & 0xDF) == 'A' ) {
port = 0;
} else if ( (jtagPort[0] & 0xDF) == 'C' ) {
port = 2;
} else if ( (jtagPort[0] & 0xDF) == 'D' ) {
port = 3;
} else {
errRender(error, "flLoadStandardFirmware(): JTAG port specification must be <A|C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
if (jtagPort[1] < '0' || jtagPort[1] > '7' || jtagPort[2] < '0' || jtagPort[2] > '7' || jtagPort[3] < '0' || jtagPort[3] > '7' || jtagPort[4] < '0' || jtagPort[4] > '7' ) {
errRender(error, "flLoadStandardFirmware(): JTAG port specification must be <A|C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
tdoBit = jtagPort[1] - '0';
tdiBit = jtagPort[2] - '0';
tmsBit = jtagPort[3] - '0';
tckBit = jtagPort[4] - '0';
if (
port == 0 &&
(isInvalidPortABit(tdoBit) || isInvalidPortABit(tdiBit) ||
isInvalidPortABit(tmsBit) || isInvalidPortABit(tckBit))
) {
errRender(error, "flFlashStandardFirmware(): Only bits 0, 1, 3 & 7 are available for JTAG use on port A");
FAIL(FL_FX2_ERR);
}
uStatus = usbOpenDevice(curVidPid, 1, 0, 0, &device, error);
CHECK_STATUS(uStatus, "flLoadStandardFirmware()", FL_USB_ERR);
bStatus = bufInitialise(&ramBuf, 0x4000, 0x00, error);
CHECK_STATUS(bStatus, "flLoadStandardFirmware()", FL_ALLOC_ERR);
flStatus = copyFirmwareAndRewriteIDs(
&ramFirmware, newVid, newPid, newDid,
port, tdoBit, tdiBit, tmsBit, tckBit,
&ramBuf, error);
CHECK_STATUS(flStatus, "flLoadStandardFirmware()", flStatus);
fxStatus = fx2WriteRAM(device, ramBuf.data, ramBuf.length, error);
CHECK_STATUS(fxStatus, "flLoadStandardFirmware()", FL_FX2_ERR);
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&ramBuf);
if ( device ) {
usbCloseDevice(device, 0);
}
return returnCode;
}
DLLEXPORT(FLStatus) flFlashStandardFirmware(
struct FLContext *handle, const char *newVidPid, const char *jtagPort,
uint32 eepromSize, const char *xsvfFile, const char **error)
{
FLStatus flStatus, returnCode;
struct Buffer i2cBuf = {0,};
BufferStatus bStatus;
FX2Status fxStatus;
uint32 fwSize, xsvfSize, initSize;
uint16 newVid, newPid, newDid;
uint8 port, tdoBit, tdiBit, tmsBit, tckBit;
if ( !usbValidateVidPid(newVidPid) ) {
errRender(error, "flFlashStandardFirmware(): The supplied new VID:PID \"%s\" is invalid; it should look like 04B4:8613", newVidPid);
FAIL(FL_USB_ERR);
}
newVid = (uint16)strtoul(newVidPid, NULL, 16);
newPid = (uint16)strtoul(newVidPid+5, NULL, 16);
newDid = (strlen(newVidPid) == 14) ? (uint16)strtoul(newVidPid+10, NULL, 16) : 0x0000;
if ( strlen(jtagPort) != 5 ) {
errRender(error, "flFlashStandardFirmware(): JTAG port specification must be <C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
if ( (jtagPort[0] & 0xDF) == 'A' ) {
port = 0;
} else if ( (jtagPort[0] & 0xDF) == 'C' ) {
port = 2;
} else if ( (jtagPort[0] & 0xDF) == 'D' ) {
port = 3;
} else {
errRender(error, "flFlashStandardFirmware(): JTAG port specification must be <A|C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
if (jtagPort[1] < '0' || jtagPort[1] > '7' || jtagPort[2] < '0' || jtagPort[2] > '7' || jtagPort[3] < '0' || jtagPort[3] > '7' || jtagPort[4] < '0' || jtagPort[4] > '7' ) {
errRender(error, "flFlashStandardFirmware(): JTAG port specification must be <A|C|D><tdoBit><tdiBit><tmsBit><tckBit>");
FAIL(FL_FX2_ERR);
}
tdoBit = jtagPort[1] - '0';
tdiBit = jtagPort[2] - '0';
tmsBit = jtagPort[3] - '0';
tckBit = jtagPort[4] - '0';
if (
port == 0 &&
(isInvalidPortABit(tdoBit) || isInvalidPortABit(tdiBit) ||
isInvalidPortABit(tmsBit) || isInvalidPortABit(tckBit))
) {
errRender(error, "flFlashStandardFirmware(): Only bits 0, 1, 3 & 7 are available for JTAG use on port A");
FAIL(FL_FX2_ERR);
}
bStatus = bufInitialise(&i2cBuf, 0x4000, 0x00, error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
if ( xsvfFile ) {
flStatus = copyFirmwareAndRewriteIDs(
&eepromWithBootFirmware, newVid, newPid, newDid,
port, tdoBit, tdiBit, tmsBit, tckBit,
&i2cBuf, error);
CHECK_STATUS(flStatus, "flFlashStandardFirmware()", flStatus);
fwSize = i2cBuf.length;
flStatus = convertJtagFileToCsvf(&i2cBuf, xsvfFile, error);
CHECK_STATUS(flStatus, "flFlashStandardFirmware()", flStatus);
xsvfSize = i2cBuf.length - fwSize;
if ( handle->writeBuffer.length ) {
// Write a big-endian uint24 length for the init data, then the data itself
const uint32 length = handle->writeBuffer.length;
if ( length > 0x20000 ) {
errRender(
error,
"flFlashStandardFirmware(): Cannot cope with %lu bytes of init data",
length);
FAIL(FL_FX2_ERR);
}
bStatus = bufAppendByte(&i2cBuf, (uint8)((length>>16) & 0xFF), error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
bStatus = bufAppendByte(&i2cBuf, (uint8)((length>>8) & 0xFF), error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
bStatus = bufAppendByte(&i2cBuf, (uint8)(length & 0xFF), error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
bStatus = bufAppendBlock(
&i2cBuf, handle->writeBuffer.data, length, error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
initSize = length + 3;
} else {
// Write a zero uint24 length so the firmware knows there's no init data to follow
bStatus = bufAppendByte(&i2cBuf, 0x00, error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
bStatus = bufAppendByte(&i2cBuf, 0x00, error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
bStatus = bufAppendByte(&i2cBuf, 0x00, error);
CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
initSize = 3;
}
} else {
flStatus = copyFirmwareAndRewriteIDs(
&eepromNoBootFirmware, newVid, newPid, newDid,
port, tdoBit, tdiBit, tmsBit, tckBit,
&i2cBuf, error);
CHECK_STATUS(flStatus, "flFlashStandardFirmware()", flStatus);
fwSize = i2cBuf.length;
xsvfSize = 0;
initSize = 0;
}
if ( i2cBuf.length > (eepromSize<<7) ) {
errRender(
error,
"flFlashStandardFirmware(): Cannot load %lu bytes (%lu + %lu + %lu) into an %lukbit EEPROM!",
i2cBuf.length, fwSize, xsvfSize, initSize, eepromSize);
FAIL(FL_FX2_ERR);
}
//bStatus = bufWriteBinaryFile(&i2cBuf, "out.bin", 0UL, i2cBuf.length, error);
//CHECK_STATUS(bStatus, "flFlashStandardFirmware()", FL_ALLOC_ERR);
printf("Writing %d bytes to EEPROM...\n", i2cBuf.length);
fxStatus = fx2WriteEEPROM(handle->device, i2cBuf.data, i2cBuf.length, error);
CHECK_STATUS(fxStatus, "flFlashStandardFirmware()", FL_FX2_ERR);
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&i2cBuf);
return returnCode;
}
// Load custom firmware (.hex) into the FX2's RAM
DLLEXPORT(FLStatus) flLoadCustomFirmware(
const char *curVidPid, const char *fwFile, const char **error)
{
FLStatus returnCode;
struct Buffer fwBuf = {0,};
BufferStatus bStatus;
FX2Status fxStatus;
struct USBDevice *device = NULL;
int uStatus;
const char *const ext = fwFile + strlen(fwFile) - 4;
if ( strcmp(".hex", ext) ) {
errRender(error, "flLoadCustomFirmware(): Filename should have .hex extension");
FAIL(FL_FILE_ERR);
}
uStatus = usbOpenDevice(curVidPid, 1, 0, 0, &device, error);
CHECK_STATUS(uStatus, "flLoadCustomFirmware()", FL_USB_ERR);
bStatus = bufInitialise(&fwBuf, 8192, 0x00, error);
CHECK_STATUS(bStatus, "flLoadCustomFirmware()", FL_ALLOC_ERR);
bStatus = bufReadFromIntelHexFile(&fwBuf, NULL, fwFile, error);
CHECK_STATUS(bStatus, "flLoadCustomFirmware()", FL_FILE_ERR);
fxStatus = fx2WriteRAM(device, fwBuf.data, fwBuf.length, error);
CHECK_STATUS(fxStatus, "flLoadCustomFirmware()", FL_FX2_ERR);
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&fwBuf);
if ( device ) {
usbCloseDevice(device, 0);
}
return returnCode;
}
// Flash custom firmware (.hex or .iic) into the FX2's EEPROM
DLLEXPORT(FLStatus) flFlashCustomFirmware(
struct FLContext *handle, const char *fwFile, uint32 eepromSize, const char **error)
{
FLStatus returnCode;
struct Buffer fwData = {0,};
struct Buffer fwMask = {0,};
struct Buffer iicBuf = {0,};
BufferStatus bStatus;
FX2Status fxStatus;
I2CStatus iStatus;
const char *const ext = fwFile + strlen(fwFile) - 4;
if ( strcmp(".hex", ext) && strcmp(".iic", ext) ) {
errRender(error, "flFlashCustomFirmware(): Filename should have .hex or .iic extension");
FAIL(FL_FX2_ERR);
}
bStatus = bufInitialise(&iicBuf, 8192, 0x00, error);
CHECK_STATUS(bStatus, "flFlashCustomFirmware()", FL_ALLOC_ERR);
if ( !strcmp(".hex", ext) ) {
// Load the .hex file, populate iicBuf:
bStatus = bufInitialise(&fwData, 8192, 0x00, error);
CHECK_STATUS(bStatus, "flFlashCustomFirmware()", FL_ALLOC_ERR);
bStatus = bufInitialise(&fwMask, 8192, 0x00, error);
CHECK_STATUS(bStatus, "flFlashCustomFirmware()", FL_ALLOC_ERR);
bStatus = bufReadFromIntelHexFile(&fwData, &fwMask, fwFile, error);
CHECK_STATUS(bStatus, "flFlashCustomFirmware()", FL_FILE_ERR);
iStatus = i2cWritePromRecords(&iicBuf, &fwData, &fwMask, error);
CHECK_STATUS(iStatus, "flFlashCustomFirmware()", FL_FX2_ERR);
} else if ( !strcmp(".iic", ext) ) {
// Load the .iic file into the iicBuf:
bStatus = bufAppendFromBinaryFile(&iicBuf, fwFile, error);
CHECK_STATUS(bStatus, "flFlashCustomFirmware()", FL_FILE_ERR);
}
if ( iicBuf.length > (eepromSize << 7) ) {
errRender(
error,
"flFlashCustomFirmware(): Cannot load %lu bytes into an %lukbit EEPROM!",
iicBuf.length, eepromSize);
FAIL(FL_FX2_ERR);
}
fxStatus = fx2WriteEEPROM(handle->device, iicBuf.data, iicBuf.length, error);
CHECK_STATUS(fxStatus, "flFlashCustomFirmware()", FL_FX2_ERR);
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&iicBuf);
bufDestroy(&fwMask);
bufDestroy(&fwData);
return returnCode;
}
// Save the EEPROM to an .iic file
DLLEXPORT(FLStatus) flSaveFirmware(
struct FLContext *handle, uint32 eepromSize, const char *saveFile, const char **error)
{
FLStatus returnCode;
struct Buffer i2cBuf = {0,};
BufferStatus bStatus;
FX2Status fxStatus;
const char *const ext = saveFile + strlen(saveFile) - 4;
if ( strcmp(".iic", ext) ) {
errRender(error, "flSaveFirmware(): Filename should have .iic extension");
FAIL(FL_FX2_ERR);
}
eepromSize <<= 7; // convert from kbits to bytes
bStatus = bufInitialise(&i2cBuf, eepromSize, 0x00, error);
CHECK_STATUS(bStatus, "flSaveFirmware()", FL_ALLOC_ERR);
fxStatus = fx2ReadEEPROM(handle->device, eepromSize, &i2cBuf, error);
CHECK_STATUS(fxStatus, "flSaveFirmware()", FL_FX2_ERR);
bStatus = bufWriteBinaryFile(&i2cBuf, saveFile, 0UL, i2cBuf.length, error);
CHECK_STATUS(bStatus, "flSaveFirmware()", FL_FILE_ERR);
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&i2cBuf);
return returnCode;
}
FLStatus copyFirmwareAndRewriteIDs(
const struct FirmwareInfo *fwInfo, uint16 vid, uint16 pid, uint16 did,
uint8 port, uint8 tdoBit, uint8 tdiBit, uint8 tmsBit, uint8 tckBit,
struct Buffer *dest, const char **error)
{
FLStatus returnCode; // Can return FL_ALLOC_ERR, FL_FX2_ERR and FL_INTERNAL_ERR
BufferStatus bStatus;
uint8 reg;
int i;
bStatus = bufAppendBlock(dest, fwInfo->data, fwInfo->length, error);
CHECK_STATUS(bStatus, "copyFirmwareAndRewriteIDs()", FL_ALLOC_ERR);
dest->data[fwInfo->vp] = (uint8)(vid & 0xFF);
dest->data[fwInfo->vp + 1] = (uint8)(vid >> 8);
dest->data[fwInfo->vp + 2] = (uint8)(pid & 0xFF);
dest->data[fwInfo->vp + 3] = (uint8)(pid >> 8);
dest->data[fwInfo->vp + 4] = (uint8)(did & 0xFF);
dest->data[fwInfo->vp + 5] = (uint8)(did >> 8);
if ( port == 0 ) {
// Use port A for JTAG operations
dest->data[fwInfo->d0E] = 0x08;
dest->data[fwInfo->d0F] = 0x09;
reg = 0xB2;
} else if ( port == 2 ) {
// Use port C for JTAG operations
dest->data[fwInfo->d0E] = 0x0C;
dest->data[fwInfo->d0F] = 0x0D;
reg = 0xB4;
} else if ( port == 3 ) {
// Use port D for JTAG operations
dest->data[fwInfo->d0E] = 0x0E;
dest->data[fwInfo->d0F] = 0x0F;
reg = 0xB5;
} else {
errRender(
error,
"copyFirmwareAndRewriteIDs(): Only port C or D may be used for JTAG operations!");
FAIL(FL_FX2_ERR);
}
dest->data[fwInfo->outBits] = (1<<tdiBit) | (1<<tmsBit) | (1<<tckBit);
dest->data[fwInfo->outBitsComp] = (uint8)~((1<<tdiBit) | (1<<tmsBit) | (1<<tckBit));
i = NUM_OE_BITS;
while ( i-- ) {
dest->data[fwInfo->oeRegs[i]] = reg;
}
i = NUM_ALL_BITS;
while ( i-- ) {
dest->data[fwInfo->allBits[i]] = (1<<tdoBit) | (1<<tdiBit) | (1<<tmsBit) | (1<<tckBit);;
}
i = NUM_ALL_BITS;
while ( i-- ) {
dest->data[fwInfo->allBitsComp[i]] = (uint8)~((1<<tdoBit) | (1<<tdiBit) | (1<<tmsBit) | (1<<tckBit));
}
i = NUM_TDO_BIT;
while ( i-- ) {
dest->data[fwInfo->tdoBit[i]] = (0x80 + (port<<4) + tdoBit);
}
i = NUM_TDI_BIT;
while ( i-- ) {
dest->data[fwInfo->tdiBit[i]] = (0x80 + (port<<4) + tdiBit);
}
i = NUM_TMS_BIT;
while ( i-- ) {
dest->data[fwInfo->tmsBit[i]] = (0x80 + (port<<4) + tmsBit);
}
i = NUM_TCK_BIT;
while ( i-- ) {
dest->data[fwInfo->tckBit[i]] = (0x80 + (port<<4) + tckBit);
}
returnCode = FL_SUCCESS;
cleanup:
return returnCode;
}
static FLStatus convertJtagFileToCsvf(struct Buffer *dest, const char *xsvfFile, const char **error) {
FLStatus returnCode, fStatus;
struct Buffer csvfBuf = {0,};
BufferStatus bStatus;
uint32 maxBufSize;
const char *const ext = xsvfFile + strlen(xsvfFile) - 5;
if ( strcmp(".svf", ext+1) == 0 ) {
bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
fStatus = flLoadSvfAndConvertToCsvf(xsvfFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
if ( maxBufSize > CSVF_BUF_SIZE ) {
errRender(error, "convertJtagFileToCsvf(): This SVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
FAIL(FL_JTAG_ERR);
}
fStatus = flCompressCsvf(&csvfBuf, error);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
bStatus = bufAppendBlock(dest, csvfBuf.data, csvfBuf.length, error);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
} else if ( strcmp(".xsvf", ext) == 0 ) {
bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
fStatus = flLoadXsvfAndConvertToCsvf(xsvfFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
if ( maxBufSize > CSVF_BUF_SIZE ) {
errRender(error, "convertJtagFileToCsvf(): This XSVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
FAIL(FL_JTAG_ERR);
}
fStatus = flCompressCsvf(&csvfBuf, error);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
bStatus = bufAppendBlock(dest, csvfBuf.data, csvfBuf.length, error);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
} else if ( strcmp(".csvf", ext) == 0 ) {
bStatus = bufAppendFromBinaryFile(dest, xsvfFile, error);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_FILE_ERR);
} else {
errRender(error, "convertJtagFileToCsvf(): Filename should have .svf, .xsvf or .csvf extension");
FAIL(FL_FILE_ERR);
}
returnCode = FL_SUCCESS;
cleanup:
bufDestroy(&csvfBuf);
return returnCode;
}