int SPI_DOWNLOAD_THREAD::get_fx3_prog_handle()
{
    char *progfile_p, *tmp;
    cyusb_handle *handle;
    int i, j, r;
    struct stat filestat;
#if 0
    r = check_fx3_flashprog(h);
    if ( r == 0 )
        //return 0;
    tmp = getenv("CYUSB_ROOT");
    if (tmp != NULL) {
        i = strlen(tmp);
        progfile_p = (char *)malloc(i + 32);
        strcpy(progfile_p, tmp);
        strcat(progfile_p, "/fx3_images/cyfxflashprog.img");
    }
    else {
        progfile_p = (char *)malloc (32);
        strcpy (progfile_p, "fx3_images/cyfxflashprog.img");
    }

    r = stat(progfile_p, &filestat);
    if ( r != 0 ) {
        printf("Failed to find cyfxflashprog.img file\n");
        //return -1;
    }
#endif
    r = fx3_usbboot_download( qPrintable(QString("/home/linux/app/cyfxflashprog.img")));
   // free (progfile_p);
    if ( r != 0 ) {
        printf("Failed to download flash prog utility\n");
        return -1;
    }

    // Now wait for the flash programmer to enumerate, and get a handle to it.
    for ( j = 0; j < GETHANDLE_TIMEOUT; j++ ) {
        sleep (1);
        for ( i = 0; i < num_devices_detected; i++ ) {
            handle = cyusb_gethandle(i);
            if ( cyusb_getvendor(handle) == FLASHPROG_VID ) {
                r = check_fx3_flashprog(handle);
                if ( r == 0 ) {
                    h = handle;
                    return 0;
                }
            }
        }
    }

    printf("Failed to get handle to flash programmer\n");
    return -2;
}
Beispiel #2
0
int main (
		int    argc,
		char **argv)
{
	cyusb_handle *h;
	char         *filename = NULL;
	char         *tgt_str  = NULL;
	fx3_fw_target tgt = FW_TARGET_NONE;
	int r, i;

	/* Parse command line arguments. */
	for (i = 1; i < argc; i++) {
		if ((strcasecmp (argv[i], "-h") == 0) || (strcasecmp (argv[i], "--help") == 0)) {
			print_usage_info (argv[0]);
			return 0;
		} else {
			if ((strcasecmp (argv[i], "-t") == 0) || (strcasecmp (argv[i], "--target") == 0)) {
				if (argc > (i + 1)) {
					tgt_str = argv[i + 1];
					if (strcasecmp (argv[i + 1], "ram") == 0)
						tgt = FW_TARGET_RAM;
					if (strcasecmp (argv[i + 1], "i2c") == 0)
						tgt = FW_TARGET_I2C;
					if (strcasecmp (argv[i + 1], "spi") == 0)
						tgt = FW_TARGET_SPI;
					if (tgt == FW_TARGET_NONE) {
						fprintf (stderr, "Error: Unknown target %s\n", argv[i + 1]);
						print_usage_info (argv[0]);
						return -EINVAL;
					}
				}
				i++;
			} else {
				if ((strcmp (argv[i], "-i") == 0) || (strcmp (argv[i], "--image") == 0)) {
					if (argc > (i + 1))
						filename = argv[i + 1];
					i++;
				} else {
					fprintf (stderr, "Error: Unknown parameter %s\n", argv[i]);
					print_usage_info (argv[0]);
					return -EINVAL;
				}
			}
		}
	}
	if ((filename == NULL) || (tgt == FW_TARGET_NONE)) {
		fprintf (stderr, "Error: Firmware binary or target not specified\n");
		print_usage_info (argv[0]);
		return -EINVAL;
	}

	r = cyusb_open ();
	if (r < 0) {
	     fprintf (stderr, "Error opening library\n");
	     return -ENODEV;
	}
	else if (r == 0) {
	        fprintf (stderr, "Error: No FX3 device found\n");
		return -ENODEV;
	}
	else if (r > 1) {
		fprintf (stderr, "Error: More than one Cypress device found\n");
		return -EINVAL;
	}

	h = cyusb_gethandle (0);

	switch (tgt) {
		case FW_TARGET_RAM:
			r = fx3_usbboot_download (h, filename);
			break;
		case FW_TARGET_I2C:
			r = fx3_i2cboot_download (h, filename);
			break;
		case FW_TARGET_SPI:
			r = fx3_spiboot_download (h, filename);
			break;
		default:
			break;
	}
	if (r != 0) {
		fprintf (stderr, "Error: FX3 firmware programming failed\n");
	} else {
		printf ("FX3 firmware programming to %s completed\n", tgt_str);
	}

	return r;
}
Beispiel #3
0
/* Get the handle to the FX3 flash programmer device, if found. */
static int
get_fx3_prog_handle (
		cyusb_handle **h)
{
	char *progfile_p, *tmp;
	cyusb_handle *handle;
	int i, j, r;
	struct stat filestat;

	handle = *h;
	r = check_fx3_flashprog (handle);
	if (r == 0)
		return 0;

	printf ("Info: Trying to download flash programmer to RAM\n");

	tmp = getenv ("CYUSB_ROOT");
	if (tmp != NULL) {
		i = strlen (tmp);
		progfile_p = (char *)malloc (i + 32);
		strcpy (progfile_p, tmp);
		strcat (progfile_p, "/fx3_images/cyfxflashprog.img");
	}
	else {
		progfile_p = (char *)malloc (32);
		strcpy (progfile_p, "fx3_images/cyfxflashprog.img");
	}

	r = stat (progfile_p, &filestat);
	if (r != 0) {
		fprintf (stderr, "Error: Failed to find cyfxflashprog.img file\n");
		return -1;
	}

	r = fx3_usbboot_download (handle, progfile_p);
	free (progfile_p);
	if (r != 0) {
		fprintf (stderr, "Error: Failed to download flash prog utility\n");
		return -1;
	}

	cyusb_close ();
	*h = NULL;

	// Now wait for the flash programmer to enumerate, and get a handle to it.
	for (j = 0; j < GETHANDLE_TIMEOUT; j++) {
		sleep (1);
		r = cyusb_open ();
		if (r > 0) {
			for (i = 0; i < r; i++) {
				handle = cyusb_gethandle (i);
				if (cyusb_getvendor (handle) == FLASHPROG_VID) {
					r = check_fx3_flashprog (handle);
					if (r == 0) {
						printf ("Info: Got handle to FX3 flash programmer\n");
						*h = handle;
						return 0;
					}
				}
			}
			cyusb_close ();
		}
	}

	fprintf (stderr, "Error: Failed to get handle to flash programmer\n");
	return -2;
}