Skip to content

Commit

Permalink
Added SVF support, in preparation for Altera testing
Browse files Browse the repository at this point in the history
  • Loading branch information
makestuff committed Mar 18, 2012
1 parent b323f75 commit b9fc888
Show file tree
Hide file tree
Showing 13 changed files with 1,772 additions and 31 deletions.
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ DEPS := error usbwrap fx2loader nero sync buffer
TYPE := dll
SUBDIRS := tests-unit
PRE_BUILD := $(ROOT)/3rd/fx2lib/lib/fx2.lib gen_fw
POST_BUILD := x2c gen_csvf
POST_BUILD := tools gen_csvf
EXTRA_CC_SRCS := gen_fw/ramFirmware.c gen_fw/eepromWithBootFirmware.c gen_fw/eepromNoBootFirmware.c
EXTRA_CLEAN := gen_xsvf gen_csvf gen_fw
EXTRA_CLEAN_DIRS := vhdl mkfw firmware
EXTRA_CLEAN := gen_svf gen_xsvf gen_csvf gen_fw
EXTRA_CLEAN_DIRS := vhdl mkfw firmware xsvf2csvf dump

-include $(ROOT)/common/top.mk

Expand All @@ -32,8 +32,9 @@ X2C := xsvf2csvf/$(PLATFORM)/rel/xsvf2csvf$(EXE)
$(MKFW):
make -C mkfw rel

x2c:
tools:
make -C xsvf2csvf rel
make -C dump rel

gen_fw: $(MKFW)
mkdir -p gen_fw
Expand All @@ -50,26 +51,32 @@ gen_fw: $(MKFW)
make -C firmware clean

gen_csvf:
mkdir -p gen_svf
mkdir -p gen_xsvf
mkdir -p gen_csvf
make -C vhdl clean
make -C vhdl PLATFORM=nexys2-500 X2C=$(X2C) TopLevel.xsvf
cp -rp vhdl/TopLevel.svf gen_svf/nexys2-500.svf
cp -rp vhdl/TopLevel.xsvf gen_xsvf/nexys2-500.xsvf
$(X2C) vhdl/TopLevel.xsvf gen_csvf/nexys2-500.csvf
make -C vhdl clean
make -C vhdl PLATFORM=nexys2-1200 X2C=$(X2C) TopLevel.xsvf
cp -rp vhdl/TopLevel.svf gen_svf/nexys2-1200.svf
cp -rp vhdl/TopLevel.xsvf gen_xsvf/nexys2-1200.xsvf
$(X2C) vhdl/TopLevel.xsvf gen_csvf/nexys2-1200.csvf
make -C vhdl clean
make -C vhdl PLATFORM=s3board X2C=$(X2C) TopLevel.xsvf
cp -rp vhdl/TopLevel.svf gen_svf/s3board.svf
cp -rp vhdl/TopLevel.xsvf gen_xsvf/s3board.xsvf
$(X2C) vhdl/TopLevel.xsvf gen_csvf/s3board.csvf
make -C vhdl clean
make -C vhdl PLATFORM=atlys X2C=$(X2C) TopLevel.xsvf
cp -rp vhdl/TopLevel.svf gen_svf/atlys.svf
cp -rp vhdl/TopLevel.xsvf gen_xsvf/atlys.xsvf
$(X2C) vhdl/TopLevel.xsvf gen_csvf/atlys.csvf
make -C vhdl clean
make -C vhdl PLATFORM=nexys3 X2C=$(X2C) TopLevel.xsvf
cp -rp vhdl/TopLevel.svf gen_svf/nexys3.svf
cp -rp vhdl/TopLevel.xsvf gen_xsvf/nexys3.xsvf
$(X2C) vhdl/TopLevel.xsvf gen_csvf/nexys3.csvf
make -C vhdl clean
Expand Down
22 changes: 22 additions & 0 deletions dump/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (C) 2012 Chris McClelland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
ROOT := $(realpath ../../..)
DEPS := fpgalink buffer error
TYPE := exe
SUBDIRS :=

-include $(ROOT)/common/top.mk
167 changes: 167 additions & 0 deletions dump/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* Copyright (C) 2011 Chris McClelland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <makestuff.h>
#include <stdio.h>
#include <stdlib.h>
#include <libfpgalink.h>

#define bitsToBytes(x) ((x>>3) + (x&7 ? 1 : 0))

typedef enum {
XCOMPLETE = 0x00,
XTDOMASK = 0x01,
XSIR = 0x02,
XSDR = 0x03,
XRUNTEST = 0x04,
XREPEAT = 0x07,
XSDRSIZE = 0x08,
XSDRTDO = 0x09,
XSETSDRMASKS = 0x0A,
XSDRINC = 0x0B,
XSDRB = 0x0C,
XSDRC = 0x0D,
XSDRE = 0x0E,
XSDRTDOB = 0x0F,
XSDRTDOC = 0x10,
XSDRTDOE = 0x11,
XSTATE = 0x12,
XENDIR = 0x13,
XENDDR = 0x14,
XSIR2 = 0x15,
XCOMMENT = 0x16,
XWAIT = 0x17
} Command;


int main(int argc, const char *argv[]) {
const uint8 *buffer, *p;
uint32 length;
uint8 byte;
uint32 xsdrSize = 0;
uint32 numBytes, temp;
if ( argc != 2 ) {
fprintf(stderr, "Synopsis: %s <xsvfFile>\n", argv[0]);
exit(1);
}
buffer = flLoadFile(argv[1], &length);
p = buffer;
byte = *p++;
while ( byte != XCOMPLETE ) {
switch ( byte ) {
case XTDOMASK:
printf("XTDOMASK(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSDRTDO:
printf("XSDRTDO(");
numBytes = temp = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(", ");
while ( temp ) {
printf("%02X", *p++);
temp--;
}
printf(")\n");
break;
case XREPEAT:
printf("XREPEAT(%02X)\n", *p++);
break;
case XRUNTEST:
printf("XRUNTEST(%02X%02X%02X%02X)\n", p[0], p[1], p[2], p[3]);
p += 4;
break;
case XSDRSIZE:
xsdrSize = *p++;
xsdrSize <<= 8;
xsdrSize |= *p++;
xsdrSize <<= 8;
xsdrSize |= *p++;
xsdrSize <<= 8;
xsdrSize |= *p++;
printf("XSDRSIZE(%08X)\n", xsdrSize);
break;
case XSIR:
byte = *p++;
printf("XSIR(%02X, ", byte);
numBytes = bitsToBytes(byte);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSDR:
printf("XSDR(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSDRB:
printf("XSDRB(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSDRC:
printf("XSDRC(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSDRE:
printf("XSDRE(");
numBytes = bitsToBytes(xsdrSize);
while ( numBytes ) {
printf("%02X", *p++);
numBytes--;
}
printf(")\n");
break;
case XSTATE:
printf("XSTATE(%02X)\n", *p++);
break;
case XENDIR:
printf("XENDIR(%02X)\n", *p++);
break;
case XENDDR:
printf("XENDDR(%02X)\n", *p++);
break;
default:
fprintf(stderr, "Unrecognised command %02X\n", byte);
exit(1);
}
byte = *p++;
}
return 0;
}
2 changes: 1 addition & 1 deletion firmware/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define DEFS_H

// The buffer available on the firmware side
#define CSVF_BUF_SIZE 12
#define CSVF_BUF_SIZE 128

// Make SYNCDELAY look like the Cypress code
#define SYNCDELAY SYNCDELAY4;
Expand Down
35 changes: 24 additions & 11 deletions fx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static FLStatus copyFirmwareAndRewriteIDs(
const uint8 *src, uint32 length, uint16 vid, uint16 pid, struct Buffer *dest, const char **error
) WARN_UNUSED_RESULT;

static FLStatus appendCsvfFromXsvf(
static FLStatus convertJtagFileToCsvf(
struct Buffer *dest, const char *xsvfFile, const char **error
) WARN_UNUSED_RESULT;

Expand Down Expand Up @@ -105,7 +105,7 @@ DLLEXPORT(FLStatus) flFlashStandardFirmware(
eepromWithBootFirmwareData, eepromWithBootFirmwareSize, newVid, newPid, &i2cBuf, error);
CHECK_STATUS(flStatus, "flFlashStandardFirmware()", flStatus);
fwSize = i2cBuf.length;
flStatus = appendCsvfFromXsvf(&i2cBuf, xsvfFile, error);
flStatus = convertJtagFileToCsvf(&i2cBuf, xsvfFile, error);
CHECK_STATUS(flStatus, "flFlashStandardFirmware()", flStatus);
xsvfSize = i2cBuf.length - fwSize;
if ( handle->writeBuffer.length ) {
Expand Down Expand Up @@ -320,30 +320,43 @@ static FLStatus copyFirmwareAndRewriteIDs(
return returnCode;
}

static FLStatus appendCsvfFromXsvf(struct Buffer *dest, const char *xsvfFile, const char **error) {
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(".xsvf", ext) == 0 ) {
if ( strcmp(".svf", ext+1) == 0 ) {
bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
CHECK_STATUS(bStatus, "appendCsvfFromXsvf()", FL_ALLOC_ERR);
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, "appendCsvfFromXsvf()", fStatus);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
if ( maxBufSize > CSVF_BUF_SIZE ) {
errRender(error, "appendCsvfFromXsvf(): This XSVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
errRender(error, "convertJtagFileToCsvf(): This XSVF file requires CSVF_BUF_SIZE=%d", maxBufSize);
FAIL(FL_JTAG_ERR);
}
fStatus = flCompressCsvf(&csvfBuf, error);
CHECK_STATUS(fStatus, "appendCsvfFromXsvf()", fStatus);
CHECK_STATUS(fStatus, "convertJtagFileToCsvf()", fStatus);
bStatus = bufAppendBlock(dest, csvfBuf.data, csvfBuf.length, error);
CHECK_STATUS(bStatus, "appendCsvfFromXsvf()", FL_ALLOC_ERR);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_ALLOC_ERR);
} else if ( strcmp(".csvf", ext) == 0 ) {
bStatus = bufAppendFromBinaryFile(dest, xsvfFile, error);
CHECK_STATUS(bStatus, "appendCsvfFromXsvf()", FL_FILE_ERR);
CHECK_STATUS(bStatus, "convertJtagFileToCsvf()", FL_FILE_ERR);
} else {
errRender(error, "appendCsvfFromXsvf(): Filename should have .xsvf or .csvf extension");
errRender(error, "convertJtagFileToCsvf(): Filename should have .svf, .xsvf or .csvf extension");
FAIL(FL_FILE_ERR);
}
returnCode = FL_SUCCESS;
Expand Down
16 changes: 10 additions & 6 deletions jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

// Play an XSVF file into the JTAG chain.
//
DLLEXPORT(FLStatus) flPlayXSVF(struct FLContext *handle, const char *xsvfFile, const char **error) {
DLLEXPORT(FLStatus) flPlayXSVF(struct FLContext *handle, const char *jtagFile, const char **error) {
FLStatus returnCode, fStatus;
struct NeroHandle nero = {0,};
struct Buffer csvfBuf = {0,};
Expand All @@ -33,23 +33,27 @@ DLLEXPORT(FLStatus) flPlayXSVF(struct FLContext *handle, const char *xsvfFile, c
int cStatus;
uint32 maxBufSize;
bool isCompressed;
const char *const ext = xsvfFile + strlen(xsvfFile) - 5;
const char *const ext = jtagFile + strlen(jtagFile) - 5;
if ( !handle->isNeroCapable ) {
errRender(error, "flPlayXSVF(): This device does not support NeroJTAG");
FAIL(FL_PROTOCOL_ERR);
}
bStatus = bufInitialise(&csvfBuf, 0x20000, 0, error);
CHECK_STATUS(bStatus, "flPlayXSVF()", FL_ALLOC_ERR);
if ( strcmp(".xsvf", ext) == 0 ) {
fStatus = flLoadXsvfAndConvertToCsvf(xsvfFile, &csvfBuf, &maxBufSize, error);
if ( strcmp(".svf", ext+1) == 0 ) {
fStatus = flLoadSvfAndConvertToCsvf(jtagFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "flPlayXSVF()", fStatus);
isCompressed = false;
} else if ( strcmp(".xsvf", ext) == 0 ) {
fStatus = flLoadXsvfAndConvertToCsvf(jtagFile, &csvfBuf, &maxBufSize, error);
CHECK_STATUS(fStatus, "flPlayXSVF()", fStatus);
isCompressed = false;
} else if ( strcmp(".csvf", ext) == 0 ) {
bStatus = bufAppendFromBinaryFile(&csvfBuf, xsvfFile, error);
bStatus = bufAppendFromBinaryFile(&csvfBuf, jtagFile, error);
CHECK_STATUS(bStatus, "flPlayXSVF()", FL_FILE_ERR);
isCompressed = true;
} else {
errRender(error, "flPlayXSVF(): Filename should have .xsvf or .csvf extension");
errRender(error, "flPlayXSVF(): Filename should have .svf, .xsvf or .csvf extension");
FAIL(FL_FILE_ERR);
}
nStatus = neroInitialise(handle->device, &nero, error);
Expand Down
1 change: 1 addition & 0 deletions libfpgalink.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern "C" {
FL_UNSUPPORTED_CMD_ERR, ///< The XSVF file contains an unsupported command.
FL_UNSUPPORTED_DATA_ERR, ///< The XSVF file contains an unsupported XENDIR or XENDDR.
FL_UNSUPPORTED_SIZE_ERR, ///< The XSVF file requires more buffer space than is available.
FL_SVF_PARSE_ERR, ///< The SVF file was not parseable.
FL_INTERNAL_ERR ///< An internal error occurred. Please report it!
} FLStatus;
//@}
Expand Down
4 changes: 4 additions & 0 deletions private.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ extern "C" {
struct Buffer *csvfBuf, const char **error
) WARN_UNUSED_RESULT;

DLLEXPORT(FLStatus) flLoadSvfAndConvertToCsvf(
const char *svfFile, struct Buffer *csvfBuf, uint32 *maxBufSize, const char **error
) WARN_UNUSED_RESULT;

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit b9fc888

Please sign in to comment.