Beispiel #1
0
int load_pic(struct astribank *ab, int numfiles, char *filelist[])
{
	int		i;
	const char	*devstr;

	devstr = xusb_devpath(xusb_dev_of_astribank(ab));
	DBG("%s: Loading %d PIC files...\n", devstr, numfiles);
	for(i = 0; i < numfiles; i++) {
		struct hexdata	*picdata;
		const char	*curr = filelist[i];

		DBG("%s\n", curr);
		if((picdata = parse_hexfile(curr, MAX_HEX_LINES)) == NULL) {
			perror(curr);
			return -errno;
		}
		if(!pic_burn(ab, picdata)) {
			ERR("%s: PIC %s burning failed\n", devstr, curr);
			return -ENODEV;
		}
		free_hexdata(picdata);
	}
	if((i = send_picline(ab, 0, PIC_ENDS_FLAG, 0, NULL, 0)) != 0) {
		ERR("%s: PIC end burning failed\n", devstr);
		return -ENODEV;
	}
	return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	struct hexdata	*hd;
	int		i;

	if(argc < 2) {
		fprintf(stderr, "Usage: program hexfile...\n");
		return 1;
	}
	parse_hexfile_set_reporting(default_report_func);
	for(i = 1; i < argc; i++) {
		hd = parse_hexfile(argv[i], 2000);
		if(!hd) {
			fprintf(stderr, "Parsing failed\n");
			return 1;
		}
		fprintf(stderr, "=== %s === (version: %s)\n", argv[i], hd->version_info);
		dump_hexfile2(hd, "-", 60 );
		free_hexdata(hd);
	}
	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	const struct astribank_type	*abtype;
	struct my_usb_device	mydev;
	const char		*devpath = NULL;
	const char		*binfile = NULL;
	const char		*inhexfile = NULL;
	const char		*outhexfile = NULL;
	struct hexdata		*hexdata = NULL;
	int			opt_reset = 0;
	int			opt_info = 0;
	int			opt_read_eeprom = 0;
	int			opt_output_width = 0;
	int			output_is_set = 0;
#ifdef	XORCOM_INTERNAL
	int			opt_write_eeprom = 0;
	char			*vendor = NULL;
	char			*source = NULL;
	char			*product = NULL;
	char			*release = NULL;
	char			*label = NULL;
	const char		options[] = "rib:D:ghH:I:vw:C:V:P:R:S:";
#else
	const char		options[] = "rib:D:ghH:I:vw:";
#endif
	int			ret = 0;

	progname = argv[0];
	assert(sizeof(struct fpga_packet_header) <= PACKET_SIZE);
	assert(sizeof(struct myeeprom) == EEPROM_SIZE);
	while (1) {
		int	c;

		c = getopt (argc, argv, options);
		if (c == -1)
			break;

		switch (c) {
			case 'D':
				devpath = optarg;
				if(output_is_set++) {
					ERR("Cannot set -D. Another output option is already selected\n");
					return 1;
				}
				break;
			case 'r':
				opt_reset = 1;
				break;
			case 'i':
				opt_info = 1;
				break;
			case 'b':
				binfile = optarg;
				if(output_is_set++) {
					ERR("Cannot set -b. Another output option is already selected\n");
					return 1;
				}
				break;
			case 'g':
				opt_read_eeprom = 1;
				break;
			case 'H':
				outhexfile = optarg;
				if(output_is_set++) {
					ERR("Cannot set -H. Another output option is already selected\n");
					return 1;
				}
				break;
			case 'I':
				inhexfile = optarg;
				break;
#ifdef	XORCOM_INTERNAL
			case 'V':
				vendor = optarg;
				break;
			case 'C':
				source = optarg;
				break;
			case 'P':
				product = optarg;
				break;
			case 'R':
				release = optarg;
				break;
			case 'S':
				label = optarg;
				{
					const char	GOOD_CHARS[] =
						"abcdefghijklmnopqrstuvwxyz"
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
						"0123456789"
						"-_.";
					int	len = strlen(label);
					int	goodlen = strspn(label, GOOD_CHARS);

					if(len > LABEL_SIZE) {
						ERR("Label too long (%d > %d)\n", len, LABEL_SIZE);
						usage();
					}
					if(goodlen != len) {
						ERR("Bad character in label number (pos=%d)\n", goodlen);
						usage();
					}
				}
				break;
#endif
			case 'w':
				opt_output_width = strtoul(optarg, NULL, 0);
				break;
			case 'v':
				verbose++;
				break;
			case 'h':
			default:
				ERR("Unknown option '%c'\n", c);
				usage();
		}
	}

	if (optind != argc) {
		usage();
	}
	if(inhexfile) {
#ifdef	XORCOM_INTERNAL
		if(vendor || product || release || label || source ) {
			ERR("The -I option is exclusive of -[VPRSC]\n");
			return 1;
		}
#endif
		parse_hexfile_set_reporting(parse_report_func);
		hexdata = parse_hexfile(inhexfile, MAX_HEX_LINES);
		if(!hexdata) {
			ERR("Bailing out\n");
			exit(1);
		}
		if(opt_info) {
			printf("%s: Version=%s Checksum=%d\n",
					inhexfile, hexdata->version_info,
					bsd_checksum(hexdata));
		}
		if(binfile) {
			dump_binary(hexdata, binfile);
			return 0;
		}
		if(outhexfile) {
			if(opt_output_width)
				dump_hexfile2(hexdata, outhexfile, opt_output_width);
			else
				dump_hexfile(hexdata, outhexfile);
			return 0;
		}
	}
#ifdef	XORCOM_INTERNAL
	else if(vendor || product || release || label || source ) {
		if(outhexfile) {
			FILE	*fp;

			if(strcmp(outhexfile, "-") == 0)
				fp = stdout;
			else if((fp = fopen(outhexfile, "w")) == NULL) {
				perror(outhexfile);
				return 1;
			}
			memset(&mydev.eeprom, 0, sizeof(struct myeeprom));
			eeprom_fill(&mydev.eeprom, vendor, product, release, label, source);
			gen_hexline((uint8_t *)&mydev.eeprom, 0, sizeof(mydev.eeprom), fp);
			gen_hexline(NULL, 0, 0, fp);	/* EOF */
			return 0;
		}
	}
#endif
	if(!devpath) {
		ERR("Missing device path\n");
		usage();
	}
	DBG("Startup %s\n", devpath);
	if((abtype = my_usb_device_identify(devpath, &mydev)) == NULL) {
		ERR("Bad device. Does not match our types.\n");
		usage();
	}
	INFO("FIRMWARE: %s (type=%d)\n", abtype->name, abtype->type_code);
	if(!my_usb_device_init(devpath, &mydev, abtype)) {
		ERR("Failed to initialize USB device '%s'\n", devpath);
		ret = -ENODEV;
		goto dev_err;
	}
	ret = eeprom_get(&mydev);
	if(ret < 0) {
		ERR("Failed reading eeprom\n");
		goto dev_err;
	}
#ifdef	XORCOM_INTERNAL
	if(vendor || product || release || label || source ) {
		eeprom_fill(&mydev.eeprom, vendor, product, release, label, source);
		opt_write_eeprom = 1;
		opt_read_eeprom = 1;
	}
#endif
	if(opt_read_eeprom) {
		show_device_info(&mydev);
	}
	if(hexdata) {
		if (!mydev.is_usb2)
			INFO("Warning: working on a low end USB1 backend\n");
		if(!fpga_load(&mydev, hexdata)) {
			ERR("FPGA loading failed\n");
			ret = -ENODEV;
			goto dev_err;
		}
		ret = renumerate_device(&mydev, PT_RENUMERATE);
		if(ret < 0) {
			ERR("Renumeration failed: errno=%d\n", ret);
			goto dev_err;
		}
	}
#ifdef XORCOM_INTERNAL
	else if(opt_write_eeprom) {
		if(abtype->type_code == USB_FIRMWARE_II) {
			ERR("No EEPROM burning command in %s. Use fxload for that\n",
				abtype->name);
			goto dev_err;
		}
		ret = eeprom_set(&mydev, &mydev.eeprom);
		if(ret < 0) {
			ERR("Failed writing eeprom: %s\n", strerror(-ret));
			goto dev_err;
		}
		printf("------- RESULTS -------\n");
		show_device_info(&mydev);
	}
#endif
	if(opt_reset) {
		DBG("Reseting to default\n");
		ret = renumerate_device(&mydev, PT_RESET);
		if(ret < 0) {
			ERR("Renumeration to default failed: errno=%d\n", ret);
			goto dev_err;
		}
	}
	DBG("Exiting\n");
dev_err:
	my_usb_device_cleanup(&mydev);
	return ret;
}