29 #define JSP_BANNER "\n\r" \
30 "******************************\n\r" \
31 "** JTAG Serial Port **\n\r" \
32 "******************************\n\r" \
42 #define ADBG_USE_HISPEED 1
48 #define ENABLE_JSP_SERVER 2
53 #define ENABLE_JSP_MULTI 4
58 #define DBG_MODULE_SELECT_REG_SIZE 2
59 #define DBG_MAX_MODULES 4
68 #define DBG_CPU_CR_STALL 0x01
69 #define DBG_CPU_CR_RESET 0x02
75 #define DBG_WB_REG_SEL_LEN 1
76 #define DBG_WB_REG_ERROR 0
79 #define DBG_WB_OPCODE_LEN 4
80 #define DBG_WB_CMD_NOP 0x0
81 #define DBG_WB_CMD_BWRITE8 0x1
82 #define DBG_WB_CMD_BWRITE16 0x2
83 #define DBG_WB_CMD_BWRITE32 0x3
84 #define DBG_WB_CMD_BREAD8 0x5
85 #define DBG_WB_CMD_BREAD16 0x6
86 #define DBG_WB_CMD_BREAD32 0x7
87 #define DBG_WB_CMD_IREG_WR 0x9
88 #define DBG_WB_CMD_IREG_SEL 0xd
91 #define DBG_CPU0_REG_SEL_LEN 1
92 #define DBG_CPU0_REG_STATUS 0
95 #define DBG_CPU0_OPCODE_LEN 4
96 #define DBG_CPU0_CMD_NOP 0x0
97 #define DBG_CPU0_CMD_BWRITE32 0x3
98 #define DBG_CPU0_CMD_BREAD32 0x7
99 #define DBG_CPU0_CMD_IREG_WR 0x9
100 #define DBG_CPU0_CMD_IREG_SEL 0xd
103 #define DBG_CPU1_REG_SEL_LEN 1
104 #define DBG_CPU1_REG_STATUS 0
107 #define DBG_CPU1_OPCODE_LEN 4
108 #define DBG_CPU1_CMD_NOP 0x0
109 #define DBG_CPU1_CMD_BWRITE32 0x3
110 #define DBG_CPU1_CMD_BREAD32 0x7
111 #define DBG_CPU1_CMD_IREG_WR 0x9
112 #define DBG_CPU1_CMD_IREG_SEL 0xd
114 #define MAX_READ_STATUS_WAIT 10
115 #define MAX_READ_BUSY_RETRY 2
116 #define MAX_READ_CRC_RETRY 2
117 #define MAX_WRITE_CRC_RETRY 2
118 #define BURST_READ_READY 1
119 #define MAX_BUS_ERRORS 2
121 #define MAX_BURST_SIZE (4 * 1024)
123 #define STATUS_BYTES 1
128 static const char *
const chain_name[] = {
"WISHBONE",
"CPU0",
"CPU1",
"JSP"};
137 while (!(buf[i] & (1 <<
count++)) && (i < len)) {
145 ret = (i * 8) +
count;
154 int retval = tap_ip->
init(jtag_info);
170 LOG_INFO(
"adv debug unit is configured with option ADBG_USE_HISPEED");
174 LOG_INFO(
"adv debug unit is configured with option ENABLE_JSP_MULTI");
175 LOG_INFO(
"adv debug unit is configured with option ENABLE_JSP_SERVER");
178 LOG_ERROR(
"Couldn't start the JSP server");
252 LOG_ERROR(
"Illegal debug chain selected (%i) while selecting control register",
258 uint32_t data = (opcode & ~(1 << opcode_len)) << index_len;
263 field.
num_bits = (opcode_len + 1) + index_len;
279 uint32_t *cmd_data,
int length_bits)
285 LOG_DEBUG(
"Write control register %" PRId8
": 0x%08" PRIx32, regidx, cmd_data[0]);
289 LOG_ERROR(
"Error while calling adbg_select_ctrl_reg");
310 LOG_ERROR(
"Illegal debug chain selected (%i) while doing control write",
318 uint32_t data = (opcode & ~(1 << opcode_len)) << index_len;
322 field[0].
out_value = (uint8_t *)cmd_data;
325 field[1].
num_bits = (opcode_len + 1) + index_len;
336 uint32_t *data,
int length_bits)
341 LOG_ERROR(
"Error while calling adbg_select_ctrl_reg");
363 LOG_ERROR(
"Illegal debug chain selected (%i) while doing control read",
369 uint32_t outdata = opcode & ~(0x1 << opcode_len);
375 field[0].
in_value = (uint8_t *)data;
378 field[1].
out_value = (uint8_t *)&outdata;
393 uint32_t address, uint16_t length_words)
398 data[0] = length_words | (address << 16);
400 data[1] = ((address >> 16) | ((opcode & 0xf) << 16)) & ~(0x1 << 20);
414 int count, uint32_t start_address, uint8_t *data)
416 int retry_full_crc = 0;
417 int retry_full_busy = 0;
421 LOG_DEBUG(
"Doing burst read, word size %d, word count %d, start address 0x%08" PRIx32,
434 LOG_WARNING(
"Tried burst read with invalid word size (%d),"
435 "defaulting to 4-byte words",
size);
443 LOG_WARNING(
"Tried burst read with invalid word size (%d),"
444 "defaulting to 4-byte words",
size);
452 LOG_WARNING(
"Tried burst read with invalid word size (%d),"
453 "defaulting to 4-byte words",
size);
458 LOG_ERROR(
"Illegal debug chain selected (%i) while doing burst read",
491 goto retry_read_full;
502 memcpy(data, in_buffer, total_size_bytes);
503 memcpy(&crc_read, &in_buffer[total_size_bytes], 4);
508 if (crc_calc != crc_read) {
509 LOG_WARNING(
"CRC ERROR! Computed 0x%08" PRIx32
", read CRC 0x%08" PRIx32, crc_calc, crc_read);
511 goto retry_read_full;
524 uint32_t err_data[2] = {0, 0};
526 int bus_error_retries = 0;
534 if (err_data[0] & 0x1) {
540 addr = (err_data[0] >> 1) | (err_data[1] << 31);
541 LOG_WARNING(
"WB bus error during burst read, address 0x%08" PRIx32
", retrying!",
addr);
545 LOG_ERROR(
"Max WB bus errors reached during burst read");
557 goto retry_read_full;
569 int count,
unsigned long start_address)
571 int retry_full_crc = 0;
575 LOG_DEBUG(
"Doing burst write, word size %d, word count %d,"
576 "start address 0x%08lx",
size,
count, start_address);
588 LOG_DEBUG(
"Tried WB burst write with invalid word size (%d),"
589 "defaulting to 4-byte words",
size);
597 LOG_DEBUG(
"Tried CPU0 burst write with invalid word size (%d),"
598 "defaulting to 4-byte words",
size);
606 LOG_DEBUG(
"Tried CPU1 burst write with invalid word size (%d),"
607 "defaulting to 4-byte words",
size);
612 LOG_ERROR(
"Illegal debug chain selected (%i) while doing burst write",
640 field[2].
out_value = (uint8_t *)&crc_calc;
656 LOG_WARNING(
"CRC ERROR! match bit after write is %" PRIi8
" (computed CRC 0x%08" PRIx32
")", value, crc_calc);
658 goto retry_full_write;
668 int bus_error_retries = 0;
669 uint32_t err_data[2] = {0, 0};
677 if (err_data[0] & 0x1) {
683 addr = (err_data[0] >> 1) | (err_data[1] << 31);
684 LOG_WARNING(
"WB bus error during burst write, address 0x%08" PRIx32
", retrying!",
addr);
688 LOG_ERROR(
"Max WB bus errors reached during burst read");
700 goto retry_full_write;
709 uint32_t
addr,
int count, uint32_t *value)
726 uint32_t
addr,
int count,
const uint32_t *value)
852 int block_count_left =
count;
853 uint32_t block_count_address =
addr;
854 uint8_t *block_count_buffer =
buffer;
856 while (block_count_left) {
862 block_count_address, block_count_buffer);
866 block_count_left -= blocks_this_round;
915 t = calloc(
count *
size,
sizeof(uint8_t));
935 int block_count_left =
count;
936 uint32_t block_count_address =
addr;
937 uint8_t *block_count_buffer = (uint8_t *)
buffer;
939 while (block_count_left) {
945 size, blocks_this_round,
946 block_count_address);
952 block_count_left -= blocks_this_round;
962 int *out_len,
unsigned char *out_buffer,
963 int *in_len,
unsigned char *in_buffer)
982 uint8_t out_data[10];
985 int startbit, stopbit, wrapbit;
987 memset(out_data, 0, 10);
992 wrapbit = (xmitsize >> 3) & 0x1;
993 out_data[0] = (xmitsize << 5) | 0x1;
997 for (i = 0; i < xmitsize; i++) {
998 out_data[i + 1] = (out_buffer[i] << 1) | wrapbit;
999 wrapbit = (out_buffer[i] >> 7) & 0x1;
1003 out_data[i + 1] = wrapbit;
1005 out_data[9] = wrapbit;
1010 stopbit = !!(out_data[9] & 0x01);
1015 out_data[0] = 0x0 | (xmitsize << 4);
1017 memcpy(&out_data[1], out_buffer, xmitsize);
1022 stopbit = !!(out_data[8] & 0x80);
1025 field.
num_bits = 72 + startbit + stopbit;
1036 *in_len = (in_data[0] >> 4) & 0xF;
1037 memcpy(in_buffer, &in_data[1], *in_len);
1039 int bytes_free = in_data[0] & 0x0F;
1040 *out_len = (bytes_free < xmitsize) ? bytes_free : xmitsize;
#define CPU_RESET
Value to write into CPUCS to put EZ-USB ANGIE into reset.
void buffer_shr(void *_buf, unsigned int buf_len, unsigned int count)
uint32_t crc32_le(uint32_t poly, uint32_t seed, const void *_data, size_t data_len)
Calculate the CRC32 value of the given data.
A generic CRC32 implementation.
#define CRC32_POLY_LE
CRC32 polynomial commonly used for little endian CRC32.
int jsp_init(struct or1k_jtag *jtag_info, char *banner)
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
The JTAG interface can be implemented with a software or hardware fifo.
static void list_add_tail(struct list_head *new, struct list_head *head)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
#define DBG_WB_CMD_BREAD8
#define DBG_WB_OPCODE_LEN
static int or1k_adv_jtag_read_cpu(struct or1k_jtag *jtag_info, uint32_t addr, int count, uint32_t *value)
#define DBG_CPU0_CMD_BWRITE32
#define DBG_CPU1_CMD_IREG_SEL
#define DBG_CPU1_CMD_IREG_WR
#define DBG_CPU1_CMD_BREAD32
#define DBG_WB_CMD_BREAD32
int or1k_du_adv_register(void)
int or1k_adv_jtag_jsp_xfer(struct or1k_jtag *jtag_info, int *out_len, unsigned char *out_buffer, int *in_len, unsigned char *in_buffer)
#define DBG_WB_CMD_BWRITE16
#define DBG_CPU0_OPCODE_LEN
static int adbg_wb_burst_read(struct or1k_jtag *jtag_info, int size, int count, uint32_t start_address, uint8_t *data)
static int adbg_ctrl_write(struct or1k_jtag *jtag_info, uint8_t regidx, uint32_t *cmd_data, int length_bits)
#define DBG_CPU0_REG_SEL_LEN
static int adbg_select_module(struct or1k_jtag *jtag_info, int chain)
static int or1k_adv_is_cpu_running(struct or1k_jtag *jtag_info, int *running)
static int or1k_adv_jtag_read_memory(struct or1k_jtag *jtag_info, uint32_t addr, uint32_t size, int count, uint8_t *buffer)
#define DBG_CPU0_CMD_IREG_SEL
static int or1k_adv_cpu_reset(struct or1k_jtag *jtag_info, int action)
#define DBG_WB_CMD_BWRITE32
#define MAX_WRITE_CRC_RETRY
static int or1k_adv_jtag_write_cpu(struct or1k_jtag *jtag_info, uint32_t addr, int count, const uint32_t *value)
static int adbg_burst_command(struct or1k_jtag *jtag_info, uint32_t opcode, uint32_t address, uint16_t length_words)
#define DBG_WB_REG_SEL_LEN
static int find_status_bit(void *_buf, int len)
static struct or1k_du or1k_du_adv
static int or1k_adv_jtag_write_memory(struct or1k_jtag *jtag_info, uint32_t addr, uint32_t size, int count, const uint8_t *buffer)
#define DBG_CPU1_REG_SEL_LEN
#define DBG_WB_CMD_IREG_WR
#define DBG_WB_CMD_BREAD16
#define DBG_MODULE_SELECT_REG_SIZE
static int adbg_ctrl_read(struct or1k_jtag *jtag_info, uint32_t regidx, uint32_t *data, int length_bits)
#define DBG_CPU1_CMD_BWRITE32
#define MAX_READ_CRC_RETRY
static int or1k_adv_jtag_init(struct or1k_jtag *jtag_info)
#define DBG_WB_CMD_BWRITE8
static int adbg_select_ctrl_reg(struct or1k_jtag *jtag_info, uint8_t regidx)
static const char *const chain_name[]
#define DBG_CPU0_REG_STATUS
#define ENABLE_JSP_SERVER
#define DBG_CPU1_OPCODE_LEN
#define DBG_WB_CMD_IREG_SEL
static int adbg_wb_burst_write(struct or1k_jtag *jtag_info, const uint8_t *data, int size, int count, unsigned long start_address)
#define DBG_CPU0_CMD_BREAD32
#define DBG_CPU0_CMD_IREG_WR
#define MAX_READ_BUSY_RETRY
static int or1k_adv_cpu_stall(struct or1k_jtag *jtag_info, int action)
target_addr_t addr
Start address to search for the control block.
size_t size
Size of the control block search area.
uint8_t * current_reg_idx
int or1k_jtag_module_selected
struct or1k_tap_ip * tap_ip
int(* init)(struct or1k_jtag *jtag_info)
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
enum target_endianness endianness
#define ERROR_TARGET_FAILURE
static void buf_bswap16(uint8_t *dst, const uint8_t *src, size_t len)
Byte-swap buffer 16-bit.
static void buf_bswap32(uint8_t *dst, const uint8_t *src, size_t len)
Byte-swap buffer 32-bit.