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 int 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 |
109 bytes_remaining -= chunk_size;
111 data_ptr += chunk_size;
120 struct image ublast2_firmware_image;
127 if (libusb_claim_interface(libusb_dev, 0)) {
137 LOG_ERROR(
"Could not load firmware image");
138 goto error_release_usb;
151 LIBUSB_REQUEST_TYPE_VENDOR |
162 for (
unsigned int i = 0; i < ublast2_firmware_image.
num_sections; i++) {
164 &ublast2_firmware_image, i);
166 LOG_ERROR(
"Error while downloading the firmware");
167 goto error_close_firmware;
173 LIBUSB_REQUEST_TYPE_VENDOR |
183 error_close_firmware:
192 libusb_release_interface(libusb_dev, 0);
201 struct libusb_device_handle *temp;
202 bool renumeration =
false;
206 LOG_INFO(
"Altera USB-Blaster II (uninitialized) found");
220 LOG_ERROR(
"Altera USB-Blaster II not found");
227 LOG_INFO(
"Waiting for reenumerate...");
231 LOG_ERROR(
"Altera USB-Blaster II not found");
244 LIBUSB_REQUEST_TYPE_VENDOR |
254 LOG_INFO(
"Altera USB-Blaster II found (Firm. rev. = %s)",
buffer);
262 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_open(const uint16_t vids[], const uint16_t pids[], const char *product, struct libusb_device_handle **out, adapter_get_alternate_serial_fn adapter_get_alternate_serial)
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, int *transferred)
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)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
target_addr_t addr
Start address to search for the control block.
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_quit(struct ublast_lowlevel *low)
static int ublast2_libusb_init(struct ublast_lowlevel *low)
struct ublast_lowlevel * ublast2_register_libusb(void)
static int ublast2_libusb_read(struct ublast_lowlevel *low, uint8_t *buf, unsigned int size, uint32_t *bytes_read)
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)