예제 #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;
}
예제 #2
0
static int run_spec(int i, xusb_filter_t filter, char *devpath)
{
	struct xusb_iface_description *desc = &test_specs[i];
	struct xusb_spec	*s = &desc->spec;
	struct xlist_node	*xlist;
	struct xlist_node	*curr;
	int interface_num = desc->interface_num;
	int num_devs;

	if (!s->name)
		return 0;
	xlist = xusb_find_byproduct(s, 1, filter, devpath);
	num_devs = (xlist) ? xlist_length(xlist) : 0;
	INFO("total %d devices of type %s (interface=%d)\n",
		num_devs, s->name, interface_num);
	for (curr = xlist_shift(xlist); curr; curr = xlist_shift(xlist)) {
		struct xusb_device	*xusb_device;
		struct xusb_iface	*iface;
                int ret;

		xusb_device = curr->data;
                ret = xusb_claim(xusb_device, interface_num, &iface);
                if (ret < 0) {
                        ERR("%s: xusb_claim() failed (ret = %d)\n",
                                xusb_devpath(xusb_device), ret);
                        continue;
                }
		xusb_showinfo(xusb_device);
                xusb_release(iface);
	}
	xlist_destroy(xlist, xusb_destructor);
	return 1;
}
예제 #3
0
/*
 * MP device handling
 */
void show_astribank_info(const struct astribank_device *astribank)
{
	struct xusb			*xusb;

	assert(astribank != NULL);
	xusb = astribank->xusb;
	assert(xusb != NULL);
	if(verbose <= LOG_INFO) {
		xusb_showinfo(xusb);
	} else {
		const struct xusb_spec	*spec;

		spec = xusb_spec(xusb);
		printf("USB    Bus/Device:    [%s]\n", xusb_devpath(xusb));
		printf("USB    Firmware Type: [%s]\n", spec->name);
		printf("USB    iSerialNumber: [%s]\n", xusb_serial(xusb));
		printf("USB    iManufacturer: [%s]\n", xusb_manufacturer(xusb));
		printf("USB    iProduct:      [%s]\n", xusb_product(xusb));
	}
}
예제 #4
0
/*
 * Returns: true on success, false on failure
 */
static int pic_burn(struct astribank *ab, const struct hexdata *hexdata)
{
	const char		*v = hexdata->version_info;
	const char		*basename;
	uint8_t			*data;
	unsigned char		check_sum = 0;
	uint8_t			card_type;
	int			ret;
	unsigned int		i;
	const char		*devstr;
	const struct xusb_device *xusb;

	v = (v[0]) ? v : "Unknown";
	assert(ab != NULL);
	assert(hexdata != NULL);
	xusb = xusb_dev_of_astribank(ab);
	devstr = xusb_devpath(xusb);
	i = xusb_packet_size(xusb);
	if(i != 512) {
		ERR("%s: Skip PIC burning (not USB2)\n", devstr);
		return 0;
	}
	INFO("%s [%s]: Loading PIC Firmware: %s (version %s)\n",
		devstr,
		xusb_serial(xusb),
		hexdata->fname,
		hexdata->version_info);
	basename = pic_basename(hexdata->fname, &card_type);
	if(!basename) {
		ERR("%s: Bad PIC filename '%s'. Abort.\n", devstr, hexdata->fname);
		return 0;
	}
	DBG("basename=%s card_type=%d maxlines=%d\n",
		basename, card_type, hexdata->maxlines);
	/*
	 * Try to read extra left-overs from USB controller
	 */
	for(i = 2; i; i--) {
		char    buf[PACKET_SIZE];

		if (astribank_recv(ab, 0, buf, sizeof(buf), TIMEOUT) <= 0)
			break;
	}
	if((ret = send_picline(ab, card_type, PIC_START_FLAG, 0, NULL, 0)) != 0) {
		perror("Failed sending start hexline");
		return 0;
	}
	for(i = 0; i < hexdata->maxlines; i++) { 
		struct hexline	*hexline;
		unsigned int	len;

		hexline = hexdata->lines[i];
		if(!hexline) {
			ERR("%s: hexdata finished early (line %d)", devstr, i);
			return 0;
		}
		if(hexline->d.content.header.tt == TT_DATA) {
			len = hexline->d.content.header.ll;	/* don't send checksum */
			if(len != 3) {
				ERR("%s: Bad line len %d\n", devstr, len);
				return 0;
			}
			data = hexline->d.content.tt_data.data;
			check_sum ^= data[0] ^ data[1] ^ data[2];
			ret = send_picline(ab, card_type, PIC_DATA_FLAG,
					hexline->d.content.header.offset, data, len);
			if(ret) {
				perror("Failed sending data hexline");
				return 0;
			}
		} else if(hexline->d.content.header.tt == TT_EOF) {
			break;
		} else {
			ERR("%s: Unexpected TT = %d in line %d\n",
					devstr, hexline->d.content.header.tt, i);
			return 0;
		}
	}
	if((ret = send_picline(ab, card_type, PIC_END_FLAG, 0, &check_sum, 1)) != 0) {
		perror("Failed sending end hexline");
		return 0;
	}
	DBG("Finished...\n");
	return 1;
}