Beispiel #1
0
// Write the standard firmware into the FX2's external EEPROM
DLLEXPORT(FLStatus) flFlashStandardFirmware(
	struct FLContext *handle, const char *newVidPid, const char **error)
{
	FLStatus flStatus, retVal = FL_SUCCESS;
	struct Buffer i2cBuf = {0,};
	BufferStatus bStatus;
	FX2Status fxStatus;
	uint16 newVid, newPid, newDid;
	CHECK_STATUS(
		!usbValidateVidPid(newVidPid), FL_USB_ERR, cleanup,
		"flFlashStandardFirmware(): The supplied new VID:PID \"%s\" is invalid; it should look like 1D50:602B or 1D50:602B:0001",
		newVidPid);
	newVid = (uint16)strtoul(newVidPid, NULL, 16);
	newPid = (uint16)strtoul(newVidPid+5, NULL, 16);
	newDid = (uint16)((strlen(newVidPid) == 14) ? strtoul(newVidPid+10, NULL, 16) : 0x0000);
	bStatus = bufInitialise(&i2cBuf, 0x4000, 0x00, error);
	CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flFlashStandardFirmware()");
	flStatus = copyFirmwareAndRewriteIDs(
		&eepromNoBootFirmware, newVid, newPid, newDid,
		&i2cBuf, error);
	CHECK_STATUS(flStatus, flStatus, cleanup, "flFlashStandardFirmware()");

	fxStatus = fx2WriteEEPROM(handle->device, i2cBuf.data, (uint32)i2cBuf.length, error);
	CHECK_STATUS(fxStatus, FL_FX2_ERR, cleanup, "flFlashStandardFirmware()");
cleanup:
	bufDestroy(&i2cBuf);
	return retVal;
}
Beispiel #2
0
// Load the standard FPGALink firmware into the FX2 at currentVid/currentPid.
DLLEXPORT(FLStatus) flLoadStandardFirmware(
	const char *curVidPid, const char *newVidPid, const char **error)
{
	FLStatus flStatus, retVal = FL_SUCCESS;
	struct Buffer ramBuf = {0,};
	BufferStatus bStatus;
	FX2Status fxStatus;
	struct USBDevice *device = NULL;
	USBStatus uStatus;
	uint16 newVid, newPid, newDid;
	CHECK_STATUS(
		!usbValidateVidPid(newVidPid), FL_USB_ERR, cleanup,
		"flLoadStandardFirmware(): The supplied VID:PID:DID \"%s\" is invalid; it should look like 1D50:602B or 1D50:602B:0001",
		newVidPid);
	newVid = (uint16)strtoul(newVidPid, NULL, 16);
	newPid = (uint16)strtoul(newVidPid+5, NULL, 16);
	newDid = (uint16)((strlen(newVidPid) == 14) ? strtoul(newVidPid+10, NULL, 16) : 0x0000);
	uStatus = usbOpenDevice(curVidPid, 1, 0, 0, &device, error);
	CHECK_STATUS(uStatus, FL_USB_ERR, cleanup, "flLoadStandardFirmware()");
	bStatus = bufInitialise(&ramBuf, 0x4000, 0x00, error);
	CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flLoadStandardFirmware()");
	flStatus = copyFirmwareAndRewriteIDs(
		&ramFirmware, newVid, newPid, newDid,
		&ramBuf, error);
	CHECK_STATUS(flStatus, flStatus, cleanup, "flLoadStandardFirmware()");
	fxStatus = fx2WriteRAM(device, ramBuf.data, (uint32)ramBuf.length, error);
	CHECK_STATUS(fxStatus, FL_FX2_ERR, cleanup, "flLoadStandardFirmware()");
cleanup:
	bufDestroy(&ramBuf);
	if ( device ) {
		usbCloseDevice(device, 0);
	}
	return retVal;
}
Beispiel #3
0
// 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;
}
Beispiel #4
0
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 {