16 #define IPDBG_BUFFER_SIZE 16384
17 #define IPDBG_MIN_NUM_OF_OPTIONS 4
18 #define IPDBG_MAX_NUM_OF_OPTIONS 14
19 #define IPDBG_MIN_DR_LENGTH 11
20 #define IPDBG_MAX_DR_LENGTH 13
21 #define IPDBG_TCP_PORT_STR_MAX_LENGTH 6
79 return fifo->
count == 0;
93 for (
size_t idx = 0 ; idx < fifo->
count ; ++idx)
127 if (bytes_written != fifo->
count) {
128 LOG_ERROR(
"error during write: %zu != %zu", bytes_written, fifo->
count);
133 fifo->
count -= bytes_written;
141 data_register_length -= 10;
142 while (data_register_length--)
146 return max_tools - 1;
178 (*service)->hub =
hub;
179 (*service)->tool =
tool;
180 (*service)->port =
port;
285 if (hub == ihub->
next) {
286 ihub->next = hub->
next;
388 const bool valid_up_data = up & hub->
valid_mask;
392 const size_t tool = (up >> 8) & hub->
tool_mask;
394 const uint8_t xon_cmd = up & 0x00ff;
396 LOG_INFO(
"received xon cmd: %d\n", xon_cmd);
449 unsigned int num_transfers = 0;
450 for (
size_t tool = 0 ; tool < hub->
max_tools ; ++tool) {
464 while (num_transfers++ < hub->
max_tools) {
478 for (
size_t tool = 0 ; tool < hub->
max_tools ; ++tool) {
519 const int time_ms = 20;
520 const int periodic = 1;
548 LOG_ERROR(
"BUG: ipdbg_start_polling failed");
553 conn->closed =
false;
570 if (bytes_read <= 0) {
572 LOG_ERROR(
"error during read: %s", strerror(errno));
576 fifo->
count += bytes_read;
585 LOG_INFO(
"Closed IPDBG Connection");
592 .new_connection_during_keep_alive_handler =
NULL,
596 .keep_client_alive_handler =
NULL,
602 LOG_INFO(
"starting ipdbg service on port %d for tool %d", port, tool);
608 LOG_DEBUG(
"hub must have the same data_register_length for all tools");
659 LOG_ERROR(
"BUG: ipdbg_remove_service failed");
676 LOG_ERROR(
"BUG: ipdbg_remove_hub failed");
687 uint16_t port = 4242;
689 uint32_t user_instruction = 0x00;
692 bool hub_configured =
false;
693 bool has_virtual_ir =
false;
694 uint32_t virtual_ir_instruction = 0x00e;
695 uint32_t virtual_ir_length = 5;
696 uint32_t virtual_ir_value = 0x11;
702 for (
unsigned int i = 0; i <
CMD_ARGC; ++i) {
703 if (strcmp(
CMD_ARGV[i],
"-tap") == 0) {
714 }
else if (strcmp(
CMD_ARGV[i],
"-hub") == 0) {
716 hub_configured =
true;
720 command_print(
CMD,
"length of \"user\"-data register must be at least %d and at most %d.",
724 }
else if (strcmp(
CMD_ARGV[i],
"-vir") == 0) {
728 has_virtual_ir =
true;
729 }
else if (strcmp(
CMD_ARGV[i],
"-port") == 0) {
731 }
else if (strcmp(
CMD_ARGV[i],
"-tool") == 0) {
733 }
else if (strcmp(
CMD_ARGV[i],
"-stop") == 0) {
735 }
else if (strcmp(
CMD_ARGV[i],
"-start") == 0) {
748 if (!hub_configured) {
758 if (has_virtual_ir) {
765 virtual_ir->
length = virtual_ir_length;
766 virtual_ir->
value = virtual_ir_value;
770 return ipdbg_start(port, tap, user_instruction, data_register_length, virtual_ir, tool);
772 return ipdbg_stop(tap, user_instruction, virtual_ir, tool);
778 .handler = handle_ipdbg_command,
780 .help =
"Starts or stops an IPDBG JTAG-Host server.",
781 .usage =
"[-start|-stop] -tap device.tap -hub ir_value [dr_length]"
782 " [-port number] [-tool number] [-vir [vir_value [length [instr_code]]]]",
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print(struct command_invocation *cmd, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#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 COMMAND_PARSE_ADDITIONAL_NUMBER(type, argn, out, name_str)
parses the command argument at position argn into out as a type, or prints a command error referring ...
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
#define COMMAND_PARSE_OPTIONAL_NUMBER(type, argn, out)
parses the command argument at position argn into out as a type if the argument argn does not start w...
static struct esp_usb_jtag * priv
static int ipdbg_create_service(struct ipdbg_hub *hub, uint8_t tool, struct ipdbg_service **service, uint16_t port)
static void ipdbg_add_service(struct ipdbg_service *service)
static int ipdbg_remove_service(struct ipdbg_service *service)
static int ipdbg_polling_callback(void *priv)
#define IPDBG_BUFFER_SIZE
static int ipdbg_start(uint16_t port, struct jtag_tap *tap, uint32_t user_instruction, uint8_t data_register_length, struct ipdbg_virtual_ir_info *virtual_ir, uint8_t tool)
#define IPDBG_MIN_NUM_OF_OPTIONS
static bool ipdbg_fifo_is_empty(struct ipdbg_fifo *fifo)
static struct ipdbg_hub * ipdbg_first_hub
static int ipdbg_shift_vir(struct ipdbg_hub *hub)
static struct ipdbg_hub * ipdbg_find_hub(struct jtag_tap *tap, uint32_t user_instruction, struct ipdbg_virtual_ir_info *virtual_ir)
static struct ipdbg_service * ipdbg_find_service(struct ipdbg_hub *hub, uint8_t tool)
static void ipdbg_free_hub(struct ipdbg_hub *hub)
#define IPDBG_MAX_NUM_OF_OPTIONS
static int ipdbg_shift_instr(struct ipdbg_hub *hub, uint32_t instr)
static int ipdbg_move_buffer_to_connection(struct connection *conn, struct ipdbg_fifo *fifo)
#define IPDBG_TCP_PORT_STR_MAX_LENGTH
static int ipdbg_shift_data(struct ipdbg_hub *hub, uint32_t dn_data, uint32_t *up_data)
static void ipdbg_init_fifo(struct ipdbg_fifo *fifo)
static int ipdbg_on_connection_input(struct connection *connection)
int ipdbg_register_commands(struct command_context *cmd_ctx)
static int ipdbg_remove_hub(struct ipdbg_hub *hub)
static int ipdbg_on_new_connection(struct connection *connection)
static void ipdbg_add_hub(struct ipdbg_hub *hub)
#define IPDBG_MIN_DR_LENGTH
static int ipdbg_jtag_transfer_byte(struct ipdbg_hub *hub, size_t tool, struct ipdbg_connection *connection)
#define IPDBG_MAX_DR_LENGTH
static int ipdbg_create_hub(struct jtag_tap *tap, uint32_t user_instruction, uint8_t data_register_length, struct ipdbg_virtual_ir_info *virtual_ir, struct ipdbg_hub **hub)
static const struct command_registration ipdbg_command_handlers[]
static int ipdbg_start_polling(struct ipdbg_service *service, struct connection *connection)
static const struct service_driver ipdbg_service_driver
static int ipdbg_stop_polling(struct ipdbg_service *service)
static bool ipdbg_fifo_is_full(struct ipdbg_fifo *fifo)
COMMAND_HANDLER(handle_ipdbg_command)
static int ipdbg_on_connection_closed(struct connection *connection)
static int ipdbg_max_tools_from_data_register_length(uint8_t data_register_length)
static void ipdbg_zero_rd_idx(struct ipdbg_fifo *fifo)
static void ipdbg_append_to_fifo(struct ipdbg_fifo *fifo, char data)
static void ipdbg_init_scan_field(struct scan_field *fields, uint8_t *in_value, int num_bits, const uint8_t *out_value)
static struct ipdbg_service * ipdbg_first_service
static char ipdbg_get_from_fifo(struct ipdbg_fifo *fifo)
static int ipdbg_distribute_data_from_hub(struct ipdbg_hub *hub, uint32_t up)
static int ipdbg_stop(struct jtag_tap *tap, uint32_t user_instruction, struct ipdbg_virtual_ir_info *virtual_ir, uint8_t tool)
static struct jaylink_connection conn
struct jtag_tap * jtag_tap_by_string(const char *s)
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
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.
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
int connection_write(struct connection *connection, const void *data, int len)
int connection_read(struct connection *connection, void *data, int len)
int remove_service(const char *name, const char *port)
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
#define ERROR_SERVER_REMOTE_CLOSED
struct ipdbg_fifo up_fifo
struct ipdbg_fifo dn_fifo
char buffer[IPDBG_BUFFER_SIZE]
struct ipdbg_virtual_ir_info * virtual_ir
struct connection ** connections
uint8_t data_register_length
uint32_t active_connections
uint32_t user_instruction
struct ipdbg_service * next
uint8_t * cur_instr
current instruction
int ir_length
size of instruction register
This structure defines a single scan field in the scan.
int num_bits
The number of bits this field specifies.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
uint8_t * check_value
The value used to check the data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
uint8_t * check_mask
The mask to go with check_value.
const char * name
the name of the server
int target_unregister_timer_callback(int(*callback)(void *priv), void *priv)
int target_register_timer_callback(int(*callback)(void *priv), unsigned int time_ms, enum target_timer_type type, void *priv)
The period is very approximate, the callback can happen much more often or much more rarely than spec...
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.