21 #define USBBLASTER_CTRL_READ_REV 0x94
22 #define USBBLASTER_CTRL_LOAD_FIRM 0xA0
23 #define USBBLASTER_EPOUT 4
24 #define USBBLASTER_EPIN 8
26 #define EZUSB_CPUCS 0xe600
30 #define SECTION_BUFFERSIZE 16384
33 unsigned size, uint32_t *bytes_read)
49 int size, uint32_t *bytes_written)
66 struct image *firmware_image,
int section_index)
70 uint8_t *data_ptr = data;
76 LOG_DEBUG(
"section %02i at addr 0x%04x (size 0x%04x)", section_index,
addr,
89 uint16_t bytes_remaining =
size;
92 while (bytes_remaining > 0) {
93 if (bytes_remaining > 64)
96 chunk_size = bytes_remaining;
99 LIBUSB_REQUEST_TYPE_VENDOR |
108 bytes_remaining -= chunk_size;
110 data_ptr += chunk_size;
119 struct image ublast2_firmware_image;
126 if (libusb_claim_interface(libusb_dev, 0)) {
136 LOG_ERROR(
"Could not load firmware image");
137 goto error_release_usb;
150 LIBUSB_REQUEST_TYPE_VENDOR |
160 for (
unsigned int i = 0; i < ublast2_firmware_image.
num_sections; i++) {
162 &ublast2_firmware_image, i);
164 LOG_ERROR(
"Error while downloading the firmware");
165 goto error_close_firmware;
171 LIBUSB_REQUEST_TYPE_VENDOR |
180 error_close_firmware:
189 libusb_release_interface(libusb_dev, 0);
198 struct libusb_device_handle *temp;
199 bool renumeration =
false;
203 LOG_INFO(
"Altera USB-Blaster II (uninitialized) found");
215 if (renumeration ==
false) {
217 LOG_ERROR(
"Altera USB-Blaster II not found");
224 LOG_INFO(
"Waiting for reenumerate...");
228 LOG_ERROR(
"Altera USB-Blaster II not found");
241 LIBUSB_REQUEST_TYPE_VENDOR |
250 LOG_INFO(
"Altera USB-Blaster II found (Firm. rev. = %s)",
buffer);
258 LOG_ERROR(
"usb release interface failed");
void image_close(struct image *image)
int image_read_section(struct image *image, int section, target_addr_t offset, uint32_t size, uint8_t *buffer, size_t *size_read)
int image_open(struct image *image, const char *url, const char *type_string)
#define ERROR_JTAG_INIT_FAILED
int jtag_libusb_bulk_write(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_control_transfer(struct libusb_device_handle *dev, uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, char *bytes, uint16_t size, unsigned int timeout)
void jtag_libusb_close(struct libusb_device_handle *dev)
int jtag_libusb_bulk_read(struct libusb_device_handle *dev, int ep, char *bytes, int size, int timeout, int *transferred)
int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[], struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
size_t size
Size of the control block search area.
unsigned int num_sections
struct imagesection * sections
target_addr_t base_address
uint16_t ublast_pid_uninit
int(* open)(struct ublast_lowlevel *low)
struct libusb_device_handle * libusb_dev
uint16_t ublast_vid_uninit
#define SECTION_BUFFERSIZE
Maximum size of a single firmware section.
static int ublast2_libusb_write(struct ublast_lowlevel *low, uint8_t *buf, int size, uint32_t *bytes_written)
#define USBBLASTER_CTRL_LOAD_FIRM
static int ublast2_write_firmware_section(struct libusb_device_handle *libusb_dev, struct image *firmware_image, int section_index)
static int ublast2_libusb_read(struct ublast_lowlevel *low, uint8_t *buf, unsigned size, uint32_t *bytes_read)
static int ublast2_libusb_quit(struct ublast_lowlevel *low)
static int ublast2_libusb_init(struct ublast_lowlevel *low)
struct ublast_lowlevel * ublast2_register_libusb(void)
static struct ublast_lowlevel low
#define USBBLASTER_CTRL_READ_REV
static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, struct ublast_lowlevel *low)