80 #define MAX_PACKET_SIZE 64
90 #define CMD_COPY_TDO_BUFFER 0x5F
122 .ublast_pid = 0x6001,
123 .lowlevel_name =
NULL,
124 .srst_asserted =
false,
125 .trst_asserted =
false,
139 #if BUILD_USB_BLASTER
142 #if BUILD_USB_BLASTER_2
154 char *str = calloc(
size * 2 + 1, 1);
156 for (i = 0; i <
size; i++)
157 sprintf(str + 2*i,
"%02x", buf[i]);
164 char *str =
hexdump(buf, *bytes_read);
175 char *str =
hexdump(buf, *bytes_written);
239 #define READ (1 << 6)
240 #define SHMODE (1 << 7)
241 #define READ_TDO (1 << 0)
418 LOG_ERROR(
"buggy code, should never queue more that %d bytes",
422 LOG_DEBUG_IO(
"(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes,
423 bytes ? bytes[0] : 0);
450 for (i = skip; i < nb_bits; i++)
478 cmd->num_states,
cmd->path[
cmd->num_states - 1]);
479 for (
unsigned int i = 0; i <
cmd->num_states; i++) {
531 LOG_DEBUG_IO(
"%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8);
533 while (ret ==
ERROR_OK && nb_bytes > 0) {
563 LOG_DEBUG_IO(
"%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits);
572 for (i = 0; ret ==
ERROR_OK && i < nb1; i++)
601 int nb8 = nb_bits / 8;
602 int nb1 = nb_bits % 8;
603 int nbfree_in_packet, i, trans = 0, read_tdos;
604 uint8_t *tdos = calloc(1, nb_bits / 8 + 1);
616 if (nb8 > 0 && nb1 == 0) {
622 for (i = 0; i < nb8; i += trans) {
627 trans =
MIN(nbfree_in_packet - 1, nb8 - i);
653 for (i = 0; i < nb1; i++) {
654 int tdi =
bits ?
bits[nb8 + i / 8] & (1 << i) : 0;
655 if (
bits && i == nb1 - 1)
660 if (nb1 && read_tdos) {
705 static const char *
const type2str[] = {
"",
"SCAN_IN",
"SCAN_OUT",
"SCAN_IO" };
706 char *log_buf =
NULL;
717 LOG_DEBUG_IO(
"%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__,
718 cmd->ir_scan ?
"IRSCAN" :
"DRSCAN",
720 scan_bits, log_buf,
cmd->end_state);
744 static uint8_t tms_reset = 0xff;
751 info.
buf[i] = out_value | ((i % 2) ?
TCK : 0);
769 static int first_call = 1;
785 cmd->cmd.runtest->end_state);
806 LOG_ERROR(
"BUG: unknown JTAG command type 0x%X",
835 LOG_ERROR(
"Error registering lowlevel driver \"%s\"",
852 LOG_ERROR(
"No lowlevel driver available");
899 LOG_WARNING(
"ignoring extra IDs in ublast_vid_pid "
900 "(maximum is 2 pairs)");
908 LOG_WARNING(
"incomplete ublast_vid_pid configuration");
915 LOG_WARNING(
"incomplete ublast_vid_pid configuration");
924 const char *
const pin_name =
CMD_ARGV[0];
926 static const char *
const pin_val_str[] = {
929 [
SRST] =
"SRST driven",
930 [
TRST] =
"TRST driven",
938 if (!strcmp(pin_name,
"pin6"))
940 if (!strcmp(pin_name,
"pin8"))
943 LOG_ERROR(
"%s: pin name must be \"pin6\" or \"pin8\"",
950 pin_val_str[*steer]);
954 const char *
const pin_value =
CMD_ARGV[1];
955 char val = pin_value[0];
957 if (strlen(pin_value) > 1)
959 switch (tolower((
unsigned char)val)) {
973 LOG_ERROR(
"%s: pin value must be 0, 1, s (SRST) or t (TRST)",
1011 .handler = ublast_handle_vid_pid_command,
1013 .help =
"the vendor ID and product ID of the USB-Blaster and "
1014 "vendor ID and product ID of the uninitialized device "
1015 "for USB-Blaster II",
1016 .usage =
"vid pid vid_uninit pid_uninit",
1019 .name =
"lowlevel_driver",
1020 .handler = ublast_handle_lowlevel_drv_command,
1022 .help =
"set the lowlevel access for the USB Blaster (ftdi, ublast2)",
1023 .usage =
"(ftdi|ublast2)",
1027 .handler = ublast_handle_pin_command,
1029 .help =
"show or set pin state for the unused GPIO pins",
1030 .usage =
"(pin6|pin8) (0|1|s|t)",
1034 .handler = &ublast_firmware_command,
1036 .help =
"configure the USB-Blaster II firmware location",
1037 .usage =
"path/to/blaster_xxxx.hex",
1044 .
name =
"usb_blaster",
1046 .help =
"perform usb_blaster management",
1059 .
name =
"usb_blaster",
const char *const jtag_only[]
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer)
enum scan_type jtag_scan_type(const struct scan_command *cmd)
int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd)
scan_type
The inferred type of a scan_command structure, indicating whether the command has the host scan in fr...
@ SCAN_IN
From device to host,.
@ SCAN_OUT
From host to device,.
@ SCAN_IO
Full-duplex scan.
tap_state_t tap_state_transition(tap_state_t cur_state, bool tms)
Function tap_state_transition takes a current TAP state and returns the next state according to the t...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
int tap_get_tms_path(tap_state_t from, tap_state_t to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
int tap_get_tms_path_len(tap_state_t from, tap_state_t to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
tap_state_t tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
#define DEBUG_CAP_TMS_SEQ
#define tap_set_state(new_state)
This function sets the state of a "state follower" which tracks the state of the TAPs connected to th...
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_DEVICE_ERROR
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
static struct scan_blk scan
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
size_t size
Size of the control block search area.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
const char * usage
a string listing the options and arguments, required or optional
struct ublast_lowlevel *(* drv_register)(void)
Represents a driver for a debugging interface.
unsigned int supported
Bit vector listing capabilities exposed by this driver.
The scan_command provide a means of encapsulating a set of scan_field structures that should be scann...
Encapsulates a series of bits to be clocked out, affecting state and mode of the interface.
uint16_t ublast_pid_uninit
uint16_t ublast_vid_uninit
struct ublast_lowlevel * drv
uint16_t ublast_pid_uninit
int(* open)(struct ublast_lowlevel *low)
int(* write)(struct ublast_lowlevel *low, uint8_t *buf, int size, uint32_t *bytes_written)
int(* read)(struct ublast_lowlevel *low, uint8_t *buf, unsigned int size, uint32_t *bytes_read)
uint16_t ublast_vid_uninit
int(* close)(struct ublast_lowlevel *low)
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
struct ublast_lowlevel * ublast2_register_libusb(void)
struct ublast_lowlevel * ublast_register_ftdi(void)
ublast_register_ftdi - get a lowlevel USB Blaster driver ublast2_register_libusb - get a lowlevel USB...
static int ublast_scan(struct scan_command *cmd)
ublast_scan - launches a DR-scan or IR-scan
static char * hexdump(uint8_t *buf, unsigned int size)
static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan)
ublast_queue_tdi - short description
struct adapter_driver usb_blaster_adapter_driver
static const struct command_registration ublast_subcommand_handlers[]
static const struct command_registration ublast_command_handlers[]
static int ublast_init(void)
ublast_init - Initialize the Altera device
static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes)
ublast_read_byteshifted_tdos - read TDO of byteshift writes
static uint8_t ublast_build_out(enum scan_type type)
ublast_build_out - build bitbang mode output byte
#define CMD_COPY_TDO_BUFFER
static void ublast_tms(struct tms_command *cmd)
ublast_tms - write a tms command
static void ublast_initial_wipeout(void)
static void ublast_clock_tms(int tms)
ublast_clock_tms - clock a TMS transition
static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written)
static int ublast_quit(void)
ublast_quit - Release the Altera device
static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip)
ublast_tms_seq - write a TMS sequence transition to JTAG
static struct drvs_map lowlevel_drivers_map[]
static void ublast_path_move(struct pathmove_command *cmd)
ublast_path_move - write a TMS sequence transition to JTAG
static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits)
ublast_read_bitbang_tdos - read TDO of bitbang writes
static void ublast_usleep(int us)
static struct jtag_interface usb_blaster_interface
static int ublast_execute_queue(struct jtag_command *cmd_queue)
static void ublast_flush_buffer(void)
static void ublast_reset(int trst, int srst)
ublast_reset - reset the JTAG device is possible
static void ublast_idle_clock(void)
ublast_idle_clock - put back TCK to low level
static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes)
ublast_queue_bytes - queue bytes for the USB Blaster
static struct ublast_info info
static int ublast_buf_read(uint8_t *buf, unsigned int size, uint32_t *bytes_read)
static void ublast_runtest(unsigned int num_cycles, tap_state_t state)
static void ublast_stableclocks(unsigned int num_cycles)
static void ublast_clock_tdi(int tdi, enum scan_type type)
ublast_clock_tdi - Output a TDI with bitbang mode
static void ublast_state_move(tap_state_t state, int skip)
ublast_state_move - move JTAG state to the target state
static bool ublast_compute_pin(enum gpio_steer steer)
ublast_compute_pin - compute if gpio should be asserted
static void ublast_queue_byte(uint8_t abyte)
ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster
static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type)
ublast_clock_tdi_flip_tms - Output a TDI with bitbang mode, change JTAG state
COMMAND_HANDLER(ublast_handle_vid_pid_command)
static int nb_buf_remaining(void)