Пример #1
0
// Load custom firmware (.hex) into the FX2's RAM
DLLEXPORT(FLStatus) flLoadCustomFirmware(
	const char *curVidPid, const char *fwFile, const char **error)
{
	FLStatus retVal = FL_SUCCESS;
	struct Buffer fwBuf = {0,};
	BufferStatus bStatus;
	FX2Status fxStatus;
	struct USBDevice *device = NULL;
	USBStatus uStatus;
	const char *const ext = fwFile + strlen(fwFile) - 4;
	const bool isHex = (strcmp(".hex", ext) == 0) || (strcmp(".ihx", ext) == 0);
	CHECK_STATUS(
		!isHex, FL_FILE_ERR, cleanup,
		"flLoadCustomFirmware(): Filename should have .hex or .ihx extension");
	uStatus = usbOpenDevice(curVidPid, 1, 0, 0, &device, error);
	CHECK_STATUS(uStatus, FL_USB_ERR, cleanup, "flLoadCustomFirmware()");
	bStatus = bufInitialise(&fwBuf, 8192, 0x00, error);
	CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flLoadCustomFirmware()");
	bStatus = bufReadFromIntelHexFile(&fwBuf, NULL, fwFile, error);
	CHECK_STATUS(bStatus, FL_FILE_ERR, cleanup, "flLoadCustomFirmware()");
	fxStatus = fx2WriteRAM(device, fwBuf.data, (uint32)fwBuf.length, error);
	CHECK_STATUS(fxStatus, FL_FX2_ERR, cleanup, "flLoadCustomFirmware()");
cleanup:
	bufDestroy(&fwBuf);
	if ( device ) {
		usbCloseDevice(device, 0);
	}
	return retVal;
}
Пример #2
0
// Flash custom firmware (.hex or .iic) into the FX2's EEPROM
DLLEXPORT(FLStatus) flFlashCustomFirmware(
	struct FLContext *handle, const char *fwFile, const char **error)
{
	FLStatus retVal = FL_SUCCESS;
	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;
	const bool isHex = (strcmp(".hex", ext) == 0) || (strcmp(".ihx", ext) == 0);
	const bool isI2C = (strcmp(".iic", ext) == 0);
	CHECK_STATUS(
		!isHex && !isI2C, FL_FX2_ERR, cleanup,
		"flFlashCustomFirmware(): Filename should have .hex, .ihx or .iic extension");
	bStatus = bufInitialise(&iicBuf, 8192, 0x00, error);
	CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flFlashCustomFirmware()");
	if ( isHex ) {
		// Load the .hex file, populate iicBuf:
		bStatus = bufInitialise(&fwData, 8192, 0x00, error);
		CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flFlashCustomFirmware()");
		bStatus = bufInitialise(&fwMask, 8192, 0x00, error);
		CHECK_STATUS(bStatus, FL_ALLOC_ERR, cleanup, "flFlashCustomFirmware()");
		bStatus = bufReadFromIntelHexFile(&fwData, &fwMask, fwFile, error);
		CHECK_STATUS(bStatus, FL_FILE_ERR, cleanup, "flFlashCustomFirmware()");
		i2cInitialise(&iicBuf, 0x0000, 0x0000, 0x0000, CONFIG_BYTE_400KHZ);
		iStatus = i2cWritePromRecords(&iicBuf, &fwData, &fwMask, error);
		CHECK_STATUS(iStatus, FL_FX2_ERR, cleanup, "flFlashCustomFirmware()");
		iStatus = i2cFinalise(&iicBuf, error);
		CHECK_STATUS(iStatus, FL_FX2_ERR, cleanup);
	} else if ( isI2C ) {
		// Load the .iic file into the iicBuf:
		bStatus = bufAppendFromBinaryFile(&iicBuf, fwFile, error);
		CHECK_STATUS(bStatus, FL_FILE_ERR, cleanup, "flFlashCustomFirmware()");
	}
	fxStatus = fx2WriteEEPROM(handle->device, iicBuf.data, (uint32)iicBuf.length, error);
	CHECK_STATUS(fxStatus, FL_FX2_ERR, cleanup, "flFlashCustomFirmware()");
cleanup:
	bufDestroy(&iicBuf);
	bufDestroy(&fwMask);
	bufDestroy(&fwData);
	return retVal;
}
Пример #3
0
int main(int argc, const char *argv[]) {
	int retVal = 0;
	struct Buffer data = {0,};
	struct Buffer mask = {0,};
	struct Buffer i2c = {0,};
	BufferStatus bStatus;
	I2CStatus iStatus;
	int dStatus;
	uint8 configByte;
	const char *error = NULL;

	if ( argc != 4 ) {
		usage(argv[0]);
		FAIL(1, cleanup);
	}

	if ( strstr(argv[2], "WithBoot") ) {
		// Boot firmware explicitly connects
		configByte = CONFIG_BYTE_400KHZ | CONFIG_BYTE_DISCON;
	} else {
		// NonBoot firmwares are connected automatically
		configByte = CONFIG_BYTE_400KHZ;
	}

	bStatus = bufInitialise(&data, 0x4000, 0x00, &error);
	CHECK_STATUS(bStatus, 2, cleanup);
	bStatus = bufInitialise(&mask, 0x4000, 0x00, &error);
	CHECK_STATUS(bStatus, 3, cleanup);
	bStatus = bufReadFromIntelHexFile(&data, &mask, argv[1], &error);
	CHECK_STATUS(bStatus, 4, cleanup);

	if ( !strcmp("iic", argv[3]) ) {
		// Get i2c records
		bStatus = bufInitialise(&i2c, 0x4000, 0x00, &error);
		CHECK_STATUS(bStatus, 5, cleanup);
		i2cInitialise(&i2c, 0x0000, 0x0000, 0x0000, configByte);
		iStatus = i2cWritePromRecords(&i2c, &data, &mask, &error);
		CHECK_STATUS(iStatus, 6, cleanup);
		iStatus = i2cFinalise(&i2c, &error);
		CHECK_STATUS(iStatus, 7, cleanup);

		// Dump the code
		dStatus = dumpCode(argv[0], argv[2], &i2c);
		CHECK_STATUS(dStatus, dStatus, cleanup);
	} else if ( !strcmp("bix", argv[3]) ) {
		// Dump the code
		dStatus = dumpCode(argv[0], argv[2], &data);
		CHECK_STATUS(dStatus, dStatus, cleanup);
	} else {
		usage(argv[0]);
		FAIL(8, cleanup);
	}

cleanup:
	if ( error ) {
		fprintf(stderr, "%s: %s\n", argv[0], error);
		errFree(error);
	}
	bufDestroy(&i2c);
	bufDestroy(&mask);
	bufDestroy(&data);
	return retVal;
}
Пример #4
0
int main(int argc, const char *argv[]) {
	int returnCode = 0;
	struct Buffer data1 = {0,};
	struct Buffer mask1 = {0,};
	struct Buffer data2 = {0,};
	struct Buffer mask2 = {0,};
	struct Buffer i2c1 = {0,};
	struct Buffer i2c2 = {0,};
	BufferStatus bStatus;
	I2CStatus iStatus;
	int dStatus;
	uint8 configByte;
	const char *error = NULL;

	if ( argc != 5 ) { //&& argc != 6 ) {
		usage(argv[0]);
		FAIL(1);
	}

	if ( strstr(argv[3], "WithBoot") ) {
		// Boot firmware explicitly connects
		configByte = CONFIG_BYTE_400KHZ | CONFIG_BYTE_DISCON;
	} else {
		// NonBoot firmwares are connected automatically
		configByte = CONFIG_BYTE_400KHZ;
	}

	bStatus = bufInitialise(&data1, 0x4000, 0x00, &error);
	CHECK(bStatus, 2);
	bStatus = bufInitialise(&mask1, 0x4000, 0x00, &error);
	CHECK(bStatus, 3);
	bStatus = bufReadFromIntelHexFile(&data1, &mask1, argv[1], &error);
	CHECK(bStatus, 4);

	bStatus = bufInitialise(&data2, 0x4000, 0x00, &error);
	CHECK(bStatus, 5);
	bStatus = bufInitialise(&mask2, 0x4000, 0x00, &error);
	CHECK(bStatus, 6);
	bStatus = bufReadFromIntelHexFile(&data2, &mask2, argv[2], &error);
	CHECK(bStatus, 7);

	if ( !strcmp("iic", argv[4]) ) {
		// Get i2c records from first build
		bStatus = bufInitialise(&i2c1, 0x4000, 0x00, &error);
		CHECK(bStatus, 8);
		i2cInitialise(&i2c1, 0x0000, 0x0000, 0x0000, configByte);
		iStatus = i2cWritePromRecords(&i2c1, &data1, &mask1, &error);
		CHECK(iStatus, 9);
		iStatus = i2cFinalise(&i2c1, &error);
		CHECK(iStatus, 10);

		// Get i2c records from second build
		bStatus = bufInitialise(&i2c2, 0x4000, 0x00, &error);
		CHECK(bStatus, 11);
		i2cInitialise(&i2c2, 0x0000, 0x0000, 0x0000, configByte);
		iStatus = i2cWritePromRecords(&i2c2, &data2, &mask2, &error);
		CHECK(iStatus, 12);
		iStatus = i2cFinalise(&i2c2, &error);
		CHECK(iStatus, 13);
		
		// Dump the code
		dStatus = dumpCode(argv[0], argv[3], &i2c1, &i2c2);
		CHECK(dStatus, dStatus);
	} else if ( !strcmp("bix", argv[4]) ) {
		// Dump the code
		dStatus = dumpCode(argv[0], argv[3], &data1, &data2);
		CHECK(dStatus, dStatus);
	} else {
		usage(argv[0]);
		FAIL(14);
	}

cleanup:
	if ( error ) {
		fprintf(stderr, "%s: %s\n", argv[0], error);
		errFree(error);
	}
	bufDestroy(&i2c2);
	bufDestroy(&i2c1);
	bufDestroy(&mask2);
	bufDestroy(&data2);
	bufDestroy(&mask1);
	bufDestroy(&data1);
	return returnCode;
}