OpenOCD
ipdbg.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright (C) 2020 by Daniel Anselmi <danselmi@gmx.ch> */
3 
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7 
8 #include <helper/bits.h>
9 #include <helper/time_support.h>
10 #include <jtag/jtag.h>
11 #include <server/server.h>
12 #include <target/target.h>
13 #include <pld/pld.h>
14 
15 #include "ipdbg.h"
16 
17 #define IPDBG_BUFFER_SIZE 16384
18 #define IPDBG_MIN_NUM_OF_CREATE_OPTIONS 3
19 #define IPDBG_MAX_NUM_OF_CREATE_OPTIONS 10
20 #define IPDBG_NUM_OF_START_OPTIONS 4
21 #define IPDBG_NUM_OF_STOP_OPTIONS 2
22 #define IPDBG_NUM_OF_QUEUE_OPTIONS 2
23 #define IPDBG_MIN_DR_LENGTH 11
24 #define IPDBG_MAX_DR_LENGTH 13
25 #define IPDBG_TCP_PORT_STR_MAX_LENGTH 6
26 #define IPDBG_SCRATCH_MEMORY_SIZE 1024
27 
28 /* private connection data for IPDBG */
29 struct ipdbg_fifo {
30  size_t count;
31  size_t rd_idx;
33 };
34 
36  struct ipdbg_fifo dn_fifo;
37  struct ipdbg_fifo up_fifo;
38  bool closed;
39 };
40 
41 struct ipdbg_service {
42  struct ipdbg_hub *hub;
44  uint16_t port;
46  uint8_t tool;
47 };
48 
50  uint32_t instruction;
51  uint32_t length;
52  uint32_t value;
53 };
54 
56  uint8_t *dr_out_vals;
57  uint8_t *dr_in_vals;
58  uint8_t *vir_out_val;
59  struct scan_field *fields;
60 };
61 
62 struct ipdbg_hub {
63  uint32_t user_instruction;
64  uint32_t max_tools;
66  uint32_t active_services;
67  uint32_t valid_mask;
68  uint32_t xoff_mask;
69  uint32_t tool_mask;
70  uint32_t last_dn_tool;
71  char *name;
73  struct ipdbg_hub *next;
74  struct jtag_tap *tap;
77  uint8_t dn_xoff;
81 };
82 
83 static struct ipdbg_hub *ipdbg_first_hub;
84 
86 
87 static void ipdbg_init_fifo(struct ipdbg_fifo *fifo)
88 {
89  fifo->count = 0;
90  fifo->rd_idx = 0;
91 }
92 
93 static bool ipdbg_fifo_is_empty(struct ipdbg_fifo *fifo)
94 {
95  return fifo->count == 0;
96 }
97 
98 static bool ipdbg_fifo_is_full(struct ipdbg_fifo *fifo)
99 {
100  return fifo->count == IPDBG_BUFFER_SIZE;
101 }
102 
103 static void ipdbg_zero_rd_idx(struct ipdbg_fifo *fifo)
104 {
105  if (fifo->rd_idx == 0)
106  return;
107 
108  size_t ri = fifo->rd_idx;
109  for (size_t idx = 0; idx < fifo->count; ++idx)
110  fifo->buffer[idx] = fifo->buffer[ri++];
111  fifo->rd_idx = 0;
112 }
113 
114 static void ipdbg_append_to_fifo(struct ipdbg_fifo *fifo, char data)
115 {
116  if (ipdbg_fifo_is_full(fifo))
117  return;
118 
119  ipdbg_zero_rd_idx(fifo);
120  fifo->buffer[fifo->count++] = data;
121 }
122 
123 static char ipdbg_get_from_fifo(struct ipdbg_fifo *fifo)
124 {
125  if (ipdbg_fifo_is_empty(fifo))
126  return 0;
127 
128  fifo->count--;
129  return fifo->buffer[fifo->rd_idx++];
130 }
131 
133 {
134  if (ipdbg_fifo_is_empty(fifo))
135  return ERROR_OK;
136 
137  struct ipdbg_connection *connection = conn->priv;
138  if (connection->closed)
140 
141  ipdbg_zero_rd_idx(fifo);
142  size_t bytes_written = connection_write(conn, fifo->buffer, fifo->count);
143  if (bytes_written != fifo->count) {
144  LOG_ERROR("error during write: %zu != %zu", bytes_written, fifo->count);
145  connection->closed = true;
147  }
148 
149  fifo->count -= bytes_written;
150 
151  return ERROR_OK;
152 }
153 
154 static int ipdbg_max_tools_from_data_register_length(uint8_t data_register_length)
155 {
156  int max_tools = 1;
157  data_register_length -= 10; /* 8 bit payload, 1 xoff-flag, 1 valid-flag; remaining bits used to select tool*/
158  while (data_register_length--)
159  max_tools *= 2;
160 
161  /* last tool is used to reset JtagCDC and transfer "XON" to host*/
162  return max_tools - 1;
163 }
164 
165 static struct ipdbg_service *ipdbg_find_service(struct ipdbg_hub *hub, uint8_t tool)
166 {
167  struct ipdbg_service *service;
169  if (service->hub == hub && service->tool == tool)
170  break;
171  }
172  return service;
173 }
174 
176 {
177  struct ipdbg_service *iservice;
178  if (ipdbg_first_service) {
179  for (iservice = ipdbg_first_service; iservice->next; iservice = iservice->next)
180  ;
181  iservice->next = service;
182  } else
184 }
185 
186 static int ipdbg_create_service(struct ipdbg_hub *hub, uint8_t tool, struct ipdbg_service **service, uint16_t port)
187 {
188  *service = calloc(1, sizeof(struct ipdbg_service));
189  if (!*service) {
190  LOG_ERROR("Out of memory");
191  return ERROR_FAIL;
192  }
193 
194  (*service)->hub = hub;
195  (*service)->tool = tool;
196  (*service)->port = port;
197 
198  return ERROR_OK;
199 }
200 
202 {
203  if (!ipdbg_first_service)
204  return ERROR_FAIL;
205 
206  if (service == ipdbg_first_service) {
208  return ERROR_OK;
209  }
210 
211  for (struct ipdbg_service *iservice = ipdbg_first_service; iservice->next; iservice = iservice->next) {
212  if (service == iservice->next) {
213  iservice->next = service->next;
214  return ERROR_OK;
215  }
216  }
217  return ERROR_FAIL;
218 }
219 
220 static struct ipdbg_hub *ipdbg_find_hub(struct jtag_tap *tap,
222 {
223  struct ipdbg_hub *hub = NULL;
224  for (hub = ipdbg_first_hub; hub; hub = hub->next) {
225  if (hub->tap == tap && hub->user_instruction == user_instruction) {
226  if ((!virtual_ir && !hub->virtual_ir) ||
227  (virtual_ir && hub->virtual_ir &&
229  virtual_ir->length == hub->virtual_ir->length &&
230  virtual_ir->value == hub->virtual_ir->value)) {
231  break;
232  }
233  }
234  }
235  return hub;
236 }
237 
238 static void ipdbg_add_hub(struct ipdbg_hub *hub)
239 {
240  struct ipdbg_hub *ihub;
241  if (ipdbg_first_hub) {
242  for (ihub = ipdbg_first_hub; ihub->next; ihub = ihub->next)
243  ;
244  ihub->next = hub;
245  } else {
246  ipdbg_first_hub = hub;
247  }
248 }
249 
250 static int ipdbg_remove_hub(struct ipdbg_hub *hub)
251 {
252  if (!ipdbg_first_hub)
253  return ERROR_FAIL;
254  if (hub == ipdbg_first_hub) {
256  return ERROR_OK;
257  }
258 
259  for (struct ipdbg_hub *ihub = ipdbg_first_hub; ihub->next; ihub = ihub->next) {
260  if (hub == ihub->next) {
261  ihub->next = hub->next;
262  return ERROR_OK;
263  }
264  }
265 
266  return ERROR_FAIL;
267 }
268 
269 static void ipdbg_free_hub(struct ipdbg_hub *hub)
270 {
271  if (!hub)
272  return;
273  free(hub->connections);
274  free(hub->virtual_ir);
275  free(hub->name);
276  free(hub->scratch_memory.dr_out_vals);
277  free(hub->scratch_memory.dr_in_vals);
278  free(hub->scratch_memory.fields);
279  free(hub->scratch_memory.vir_out_val);
280  free(hub);
281 }
282 
284  const char *name)
285 {
286  struct ipdbg_hub *new_hub = calloc(1, sizeof(struct ipdbg_hub));
287  if (!new_hub) {
288  LOG_ERROR("Out of memory");
289  return NULL;
290  }
291 
292  new_hub->name = strdup(name);
293  if (!new_hub->name) {
294  free(new_hub);
295  LOG_ERROR("Out of memory");
296  return NULL;
297  }
298 
299  const size_t dreg_buffer_size = DIV_ROUND_UP(data_register_length, 8);
301 
302  new_hub->scratch_memory.dr_out_vals = calloc(IPDBG_SCRATCH_MEMORY_SIZE, dreg_buffer_size);
303  new_hub->scratch_memory.dr_in_vals = calloc(IPDBG_SCRATCH_MEMORY_SIZE, dreg_buffer_size);
304  new_hub->scratch_memory.fields = calloc(IPDBG_SCRATCH_MEMORY_SIZE, sizeof(struct scan_field));
305  new_hub->connections = calloc(max_tools, sizeof(struct connection *));
306 
307  if (virtual_ir)
308  new_hub->scratch_memory.vir_out_val = calloc(1, DIV_ROUND_UP(virtual_ir->length, 8));
309 
310  if (!new_hub->scratch_memory.dr_out_vals || !new_hub->scratch_memory.dr_in_vals ||
311  !new_hub->scratch_memory.fields || (virtual_ir && !new_hub->scratch_memory.vir_out_val) ||
312  !new_hub->connections) {
313  ipdbg_free_hub(new_hub);
314  LOG_ERROR("Out of memory");
315  return NULL;
316  }
317 
318  return new_hub;
319 }
320 
321 static void ipdbg_init_scan_field(struct scan_field *fields, uint8_t *in_value, int num_bits, const uint8_t *out_value)
322 {
323  fields->check_mask = NULL;
324  fields->check_value = NULL;
325  fields->in_value = in_value;
326  fields->num_bits = num_bits;
327  fields->out_value = out_value;
328 }
329 
330 static int ipdbg_shift_instr(struct ipdbg_hub *hub, uint32_t instr)
331 {
332  if (!hub)
333  return ERROR_FAIL;
334 
335  struct jtag_tap *tap = hub->tap;
336  if (!tap)
337  return ERROR_FAIL;
338 
339  if (buf_get_u32(tap->cur_instr, 0, tap->ir_length) == instr) {
340  /* there is already the requested instruction in the ir */
341  return ERROR_OK;
342  }
343 
344  uint8_t *ir_out_val = calloc(DIV_ROUND_UP(tap->ir_length, 8), 1);
345  if (!ir_out_val) {
346  LOG_ERROR("Out of memory");
347  return ERROR_FAIL;
348  }
349  buf_set_u32(ir_out_val, 0, tap->ir_length, instr);
350 
351  struct scan_field fields;
352  ipdbg_init_scan_field(&fields, NULL, tap->ir_length, ir_out_val);
353  jtag_add_ir_scan(tap, &fields, TAP_IDLE);
354  int retval = jtag_execute_queue();
355 
356  free(ir_out_val);
357 
358  return retval;
359 }
360 
361 static int ipdbg_shift_vir(struct ipdbg_hub *hub)
362 {
363  if (!hub)
364  return ERROR_FAIL;
365 
366  if (!hub->virtual_ir)
367  return ERROR_OK;
368 
369  int retval = ipdbg_shift_instr(hub, hub->virtual_ir->instruction);
370  if (retval != ERROR_OK)
371  return retval;
372 
373  struct jtag_tap *tap = hub->tap;
374  if (!tap)
375  return ERROR_FAIL;
376 
380  retval = jtag_execute_queue();
381 
382  return retval;
383 }
384 
385 static int ipdbg_shift_data(struct ipdbg_hub *hub, uint32_t dn_data, uint32_t *up_data)
386 {
387  if (!hub)
388  return ERROR_FAIL;
389 
390  struct jtag_tap *tap = hub->tap;
391  if (!tap)
392  return ERROR_FAIL;
393 
395 
399  int retval = jtag_execute_queue();
400 
401  if (up_data && retval == ERROR_OK)
402  *up_data = buf_get_u32(hub->scratch_memory.dr_in_vals, 0, hub->data_register_length);
403 
404  return retval;
405 }
406 
407 static int ipdbg_distribute_data_from_hub(struct ipdbg_hub *hub, uint32_t up)
408 {
409  const bool valid_up_data = up & hub->valid_mask;
410  if (!valid_up_data)
411  return ERROR_OK;
412 
413  const size_t tool = (up >> 8) & hub->tool_mask;
414  if (tool == hub->tool_mask) {
415  const uint8_t xon_cmd = up & 0x00ff;
416  hub->dn_xoff &= ~xon_cmd;
417  LOG_INFO("received xon cmd: %d\n", xon_cmd);
418  return ERROR_OK;
419  }
420 
421  struct connection *conn = hub->connections[tool];
422  if (conn) {
423  struct ipdbg_connection *connection = conn->priv;
424  if (ipdbg_fifo_is_full(&connection->up_fifo)) {
425  int retval = ipdbg_move_buffer_to_connection(conn, &connection->up_fifo);
426  if (retval != ERROR_OK)
427  return retval;
428  }
429  ipdbg_append_to_fifo(&connection->up_fifo, up);
430  }
431  return ERROR_OK;
432 }
433 
434 static void ipdbg_check_for_xoff(struct ipdbg_hub *hub, size_t tool,
435  uint32_t rx_data)
436 {
437  if ((rx_data & hub->xoff_mask) && hub->last_dn_tool != hub->max_tools) {
438  hub->dn_xoff |= BIT(hub->last_dn_tool);
439  LOG_INFO("tool %d sent xoff", hub->last_dn_tool);
440  }
441 
442  hub->last_dn_tool = tool;
443 }
444 
445 static int ipdbg_shift_empty_data(struct ipdbg_hub *hub)
446 {
447  if (!hub)
448  return ERROR_FAIL;
449 
450  struct jtag_tap *tap = hub->tap;
451  if (!tap)
452  return ERROR_FAIL;
453 
454  const size_t dreg_buffer_size = DIV_ROUND_UP(hub->data_register_length, 8);
455  memset(hub->scratch_memory.dr_out_vals, 0, dreg_buffer_size);
456  for (size_t i = 0; i < hub->using_queue_size; ++i) {
458  hub->scratch_memory.dr_in_vals + i * dreg_buffer_size,
461  jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields + i, TAP_IDLE);
462  }
463 
464  int retval = jtag_execute_queue();
465 
466  if (retval == ERROR_OK) {
467  uint32_t up_data;
468  for (size_t i = 0; i < hub->using_queue_size; ++i) {
469  up_data = buf_get_u32(hub->scratch_memory.dr_in_vals +
470  i * dreg_buffer_size, 0,
471  hub->data_register_length);
472  int rv = ipdbg_distribute_data_from_hub(hub, up_data);
473  if (rv != ERROR_OK)
474  retval = rv;
475 
476  if (i == 0) {
477  /* check if xoff sent is only needed on the first transfer which
478  may contain the xoff of the prev down transfer.
479  */
480  ipdbg_check_for_xoff(hub, hub->max_tools, up_data);
481  }
482  }
483  }
484 
485  return retval;
486 }
487 
488 static int ipdbg_jtag_transfer_byte(struct ipdbg_hub *hub, size_t tool, struct ipdbg_connection *connection)
489 {
490  uint32_t dn = hub->valid_mask | ((tool & hub->tool_mask) << 8) |
491  (0x00fful & ipdbg_get_from_fifo(&connection->dn_fifo));
492  uint32_t up = 0;
493  int ret = ipdbg_shift_data(hub, dn, &up);
494  if (ret != ERROR_OK)
495  return ret;
496 
497  ret = ipdbg_distribute_data_from_hub(hub, up);
498  if (ret != ERROR_OK)
499  return ret;
500 
501  ipdbg_check_for_xoff(hub, tool, up);
502 
503  return ERROR_OK;
504 }
505 
506 static int ipdbg_jtag_transfer_bytes(struct ipdbg_hub *hub,
507  size_t tool, struct ipdbg_connection *connection)
508 {
509  if (!hub)
510  return ERROR_FAIL;
511 
512  struct jtag_tap *tap = hub->tap;
513  if (!tap)
514  return ERROR_FAIL;
515 
516  const size_t dreg_buffer_size = DIV_ROUND_UP(hub->data_register_length, 8);
517  size_t num_tx = (connection->dn_fifo.count < hub->using_queue_size) ?
518  connection->dn_fifo.count : hub->using_queue_size;
519 
520  for (size_t i = 0; i < num_tx; ++i) {
521  uint32_t dn_data = hub->valid_mask | ((tool & hub->tool_mask) << 8) |
522  (0x00fful & ipdbg_get_from_fifo(&connection->dn_fifo));
523  buf_set_u32(hub->scratch_memory.dr_out_vals + i * dreg_buffer_size, 0,
524  hub->data_register_length, dn_data);
525 
528  i * dreg_buffer_size,
531  i * dreg_buffer_size);
532  jtag_add_dr_scan(tap, 1, hub->scratch_memory.fields + i, TAP_IDLE);
533  }
534 
535  int retval = jtag_execute_queue();
536 
537  if (retval == ERROR_OK) {
538  uint32_t up_data;
539  for (size_t i = 0; i < num_tx; ++i) {
540  up_data = buf_get_u32(hub->scratch_memory.dr_in_vals +
541  i * dreg_buffer_size,
542  0, hub->data_register_length);
543  int rv = ipdbg_distribute_data_from_hub(hub, up_data);
544  if (rv != ERROR_OK)
545  retval = rv;
546  if (i == 0) {
547  /* check if xoff sent is only needed on the first transfer which
548  may contain the xoff of the prev down transfer.
549  No checks for this channel because this function is only
550  called for channels without enabled flow control.
551  */
552  ipdbg_check_for_xoff(hub, tool, up_data);
553  }
554  }
555  }
556 
557  return retval;
558 }
559 
560 static int ipdbg_polling_callback(void *priv)
561 {
562  struct ipdbg_hub *hub = priv;
563 
564  int ret = ipdbg_shift_vir(hub);
565  if (ret != ERROR_OK)
566  return ret;
567 
568  ret = ipdbg_shift_instr(hub, hub->user_instruction);
569  if (ret != ERROR_OK)
570  return ret;
571 
572  /* transfer dn buffers to jtag-hub */
573  for (size_t tool = 0; tool < hub->max_tools; ++tool) {
574  struct connection *conn = hub->connections[tool];
575  if (conn && conn->priv) {
576  struct ipdbg_connection *connection = conn->priv;
577  while (((hub->dn_xoff & BIT(tool)) == 0) && !ipdbg_fifo_is_empty(&connection->dn_fifo)) {
578  if (hub->flow_control_enabled & BIT(tool))
579  ret = ipdbg_jtag_transfer_byte(hub, tool, connection);
580  else
581  ret = ipdbg_jtag_transfer_bytes(hub, tool, connection);
582  if (ret != ERROR_OK)
583  return ret;
584  }
585  }
586  }
587 
588  /* some transfers to get data from jtag-hub in case there is no dn data */
589  ret = ipdbg_shift_empty_data(hub);
590  if (ret != ERROR_OK)
591  return ret;
592 
593  /* write from up fifos to sockets */
594  for (size_t tool = 0; tool < hub->max_tools; ++tool) {
595  struct connection *conn = hub->connections[tool];
596  if (conn && conn->priv) {
597  struct ipdbg_connection *connection = conn->priv;
598  int retval = ipdbg_move_buffer_to_connection(conn, &connection->up_fifo);
599  if (retval != ERROR_OK)
600  return retval;
601  }
602  }
603 
604  return ERROR_OK;
605 }
606 
608 {
609  uint32_t up_data;
610 
611  /* on older implementations the flow_control_enable_word is not sent to us.
612  so we don't know -> assume it's enabled on all channels */
613  hub->flow_control_enabled = 0x7f;
614 
615  int ret = ipdbg_shift_data(hub, 0UL, &up_data);
616  if (ret != ERROR_OK)
617  return ret;
618 
619  const bool valid_up_data = up_data & hub->valid_mask;
620  if (valid_up_data) {
621  const size_t tool = (up_data >> 8) & hub->tool_mask;
622  /* the first valid data from hub is flow_control_enable_word */
623  if (tool == hub->tool_mask)
624  hub->flow_control_enabled = up_data & 0x007f;
625  else
626  ipdbg_distribute_data_from_hub(hub, up_data);
627  }
628 
629  LOG_INFO("Flow control enabled on IPDBG JTAG Hub: 0x%02x", hub->flow_control_enabled);
630 
631  return ERROR_OK;
632 }
633 
635 {
636  struct ipdbg_hub *hub = service->hub;
637  hub->connections[service->tool] = connection;
638  hub->active_connections++;
639  if (hub->active_connections > 1) {
640  /* hub is already initialized */
641  return ERROR_OK;
642  }
643 
644  const uint32_t reset_hub = hub->valid_mask | ((hub->max_tools) << 8);
645 
646  int ret = ipdbg_shift_vir(hub);
647  if (ret != ERROR_OK)
648  return ret;
649 
650  ret = ipdbg_shift_instr(hub, hub->user_instruction);
651  if (ret != ERROR_OK)
652  return ret;
653 
654  ret = ipdbg_shift_data(hub, reset_hub, NULL);
655  hub->last_dn_tool = hub->tool_mask;
656  hub->dn_xoff = 0;
657  if (ret != ERROR_OK)
658  return ret;
659 
661  if (ret != ERROR_OK)
662  return ret;
663 
664  LOG_INFO("IPDBG start_polling");
665 
666  const int time_ms = 20;
667  const int periodic = 1;
668  return target_register_timer_callback(ipdbg_polling_callback, time_ms, periodic, hub);
669 }
670 
672 {
673  struct ipdbg_hub *hub = service->hub;
674  hub->connections[service->tool] = NULL;
675  hub->active_connections--;
676  if (hub->active_connections == 0) {
677  LOG_INFO("IPDBG stop_polling");
678 
680  }
681 
682  return ERROR_OK;
683 }
684 
686 {
688  connection->priv = &service->connection;
689  /* initialize ipdbg connection information */
690  ipdbg_init_fifo(&service->connection.up_fifo);
691  ipdbg_init_fifo(&service->connection.dn_fifo);
692 
693  int retval = ipdbg_start_polling(service, connection);
694  if (retval != ERROR_OK) {
695  LOG_ERROR("BUG: ipdbg_start_polling failed");
696  return retval;
697  }
698 
700  conn->closed = false;
701 
702  LOG_INFO("New IPDBG Connection");
703 
704  return ERROR_OK;
705 }
706 
708 {
710  struct ipdbg_fifo *fifo = &conn->dn_fifo;
711 
712  if (ipdbg_fifo_is_full(fifo))
713  return ERROR_OK;
714 
715  ipdbg_zero_rd_idx(fifo);
716  int bytes_read = connection_read(connection, fifo->buffer + fifo->count, IPDBG_BUFFER_SIZE - fifo->count);
717  if (bytes_read <= 0) {
718  if (bytes_read < 0)
719  LOG_ERROR("error during read: %s", strerror(errno));
721  }
722 
723  fifo->count += bytes_read;
724 
725  return ERROR_OK;
726 }
727 
729 {
731  conn->closed = true;
732  LOG_INFO("Closed IPDBG Connection");
733 
735 }
736 
737 static const struct service_driver ipdbg_service_driver = {
738  .name = "ipdbg",
739  .new_connection_during_keep_alive_handler = NULL,
740  .new_connection_handler = ipdbg_on_new_connection,
741  .input_handler = ipdbg_on_connection_input,
742  .connection_closed_handler = ipdbg_on_connection_closed,
743  .keep_client_alive_handler = NULL,
744 };
745 
746 static struct ipdbg_hub *ipdbg_get_hub_by_name(const char *name)
747 {
748  struct ipdbg_hub *hub = NULL;
749  for (hub = ipdbg_first_hub; hub; hub = hub->next) {
750  if (strcmp(hub->name, name) == 0)
751  break;
752  }
753  return hub;
754 };
755 
757 {
758  int retval = ipdbg_remove_service(service);
759  if (retval != ERROR_OK) {
760  LOG_ERROR("BUG: ipdbg_remove_service failed");
761  return retval;
762  }
763 
764  char port_str_buffer[IPDBG_TCP_PORT_STR_MAX_LENGTH];
765  snprintf(port_str_buffer, IPDBG_TCP_PORT_STR_MAX_LENGTH, "%u", service->port);
766  retval = remove_service("ipdbg", port_str_buffer);
767  /* The ipdbg_service structure is freed by server.c:remove_service().
768  There the "priv" pointer is freed.*/
769  if (retval != ERROR_OK) {
770  LOG_ERROR("BUG: remove_service failed");
771  return retval;
772  }
773  return ERROR_OK;
774 }
775 
777 {
778  int retval = ERROR_OK;
779  for (struct ipdbg_hub *hub = ipdbg_first_hub; hub;) {
780  for (uint8_t tool = 0; tool < hub->max_tools; ++tool) {
782  if (service) {
783  int new_retval = ipdbg_stop_service(service);
784  if (new_retval != ERROR_OK)
785  retval = new_retval;
786  hub->active_services--;
787  }
788  }
789  struct ipdbg_hub *next_hub = hub->next;
790  int new_retval = ipdbg_remove_hub(hub);
791  if (new_retval != ERROR_OK)
792  retval = new_retval;
793  ipdbg_free_hub(hub);
794  hub = next_hub;
795  }
796  return retval;
797 }
798 
799 static int ipdbg_start(struct ipdbg_hub *hub, uint16_t port, uint8_t tool)
800 {
801  LOG_INFO("starting ipdbg service on port %d for tool %d", port, tool);
802 
803  struct ipdbg_service *service = NULL;
804  int retval = ipdbg_create_service(hub, tool, &service, port);
805 
806  if (retval != ERROR_OK || !service) {
807  if (hub->active_services == 0 && hub->active_connections == 0)
809  return ERROR_FAIL;
810  }
811 
812  char port_str_buffer[IPDBG_TCP_PORT_STR_MAX_LENGTH];
813  snprintf(port_str_buffer, IPDBG_TCP_PORT_STR_MAX_LENGTH, "%u", port);
814  retval = add_service(&ipdbg_service_driver, port_str_buffer, 1, service);
815  if (retval != ERROR_OK) {
816  free(service);
817  return retval;
818  }
820  hub->active_services++;
821  return ERROR_OK;
822 }
823 
824 COMMAND_HANDLER(handle_ipdbg_start_command)
825 {
826  struct ipdbg_hub *hub = CMD_DATA;
827 
828  uint16_t port = 4242;
829  uint8_t tool = 1;
830 
833 
834  for (unsigned int i = 0; i < CMD_ARGC; ++i) {
835  if (strcmp(CMD_ARGV[i], "-port") == 0) {
836  COMMAND_PARSE_ADDITIONAL_NUMBER(u16, i, port, "port number");
837  } else if (strcmp(CMD_ARGV[i], "-tool") == 0) {
838  COMMAND_PARSE_ADDITIONAL_NUMBER(u8, i, tool, "tool");
839  } else {
840  command_print(CMD, "Unknown argument: %s", CMD_ARGV[i]);
841  return ERROR_FAIL;
842  }
843  }
844 
845  return ipdbg_start(hub, port, tool);
846 }
847 
848 static int ipdbg_stop(struct ipdbg_hub *hub, uint8_t tool)
849 {
851  if (!service) {
852  LOG_ERROR("No service for hub '%s'/tool %d found", hub->name, tool);
853  return ERROR_FAIL;
854  }
855 
856  int retval = ipdbg_stop_service(service);
857  hub->active_services--;
858 
859  LOG_INFO("stopped ipdbg service for tool %d", tool);
860  return retval;
861 }
862 
863 COMMAND_HANDLER(handle_ipdbg_stop_command)
864 {
865  struct ipdbg_hub *hub = CMD_DATA;
866 
867  uint8_t tool = 1;
868 
871 
872  for (unsigned int i = 0; i < CMD_ARGC; ++i) {
873  if (strcmp(CMD_ARGV[i], "-tool") == 0) {
874  COMMAND_PARSE_ADDITIONAL_NUMBER(u8, i, tool, "tool");
875  } else {
876  command_print(CMD, "Unknown argument: %s", CMD_ARGV[i]);
877  return ERROR_FAIL;
878  }
879  }
880 
881  return ipdbg_stop(hub, tool);
882 }
883 
885  {
886  .name = "start",
887  .mode = COMMAND_EXEC,
888  .handler = handle_ipdbg_start_command,
889  .help = "Starts a IPDBG Host server.",
890  .usage = "-tool number -port port"
891  }, {
892  .name = "stop",
893  .mode = COMMAND_EXEC,
894  .handler = handle_ipdbg_stop_command,
895  .help = "Stops a IPDBG Host server.",
896  .usage = "-tool number"
897  },
899 };
900 
901 static COMMAND_HELPER(ipdbg_config_queuing, struct ipdbg_hub *hub, unsigned int size)
902 {
903  if (!hub)
904  return ERROR_FAIL;
905 
906  if (hub->active_connections) {
907  command_print(CMD, "Configuration change not allowed when hub has active connections");
908  return ERROR_FAIL;
909  }
910 
911  if (size == 0 || size > IPDBG_SCRATCH_MEMORY_SIZE) {
912  command_print(CMD, "queuing size out of range! Must be 0 < size <= %d", IPDBG_SCRATCH_MEMORY_SIZE);
914  }
915 
916  hub->using_queue_size = size;
917  return ERROR_OK;
918 }
919 
920 COMMAND_HANDLER(handle_ipdbg_cfg_queuing_command)
921 {
922  struct ipdbg_hub *hub = CMD_DATA;
923 
924  unsigned int size;
925 
928 
929  for (unsigned int i = 0; i < CMD_ARGC; ++i) {
930  if (strcmp(CMD_ARGV[i], "-size") == 0) {
931  COMMAND_PARSE_ADDITIONAL_NUMBER(uint, i, size, "size");
932  } else {
933  command_print(CMD, "Unknown argument: %s", CMD_ARGV[i]);
934  return ERROR_FAIL;
935  }
936  }
937 
938  return CALL_COMMAND_HANDLER(ipdbg_config_queuing, hub, size);
939 }
940 
941 static const struct command_registration ipdbg_hub_subcommand_handlers[] = {
942  {
943  .name = "ipdbg",
944  .mode = COMMAND_EXEC,
945  .help = "IPDBG Hub commands.",
946  .usage = "",
948  },
949  {
950  .name = "queuing",
951  .handler = handle_ipdbg_cfg_queuing_command,
952  .mode = COMMAND_ANY,
953  .help = "configures queuing between IPDBG Host and Hub.",
954  .usage = "-size size",
955  },
957 };
958 
960 {
961  Jim_Interp *interp = CMD_CTX->interp;
962 
963  /* does this command exist? */
964  Jim_Cmd *jcmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, hub->name, -1), JIM_NONE);
965  if (jcmd) {
966  LOG_ERROR("cannot create Hub because a command with name '%s' already exists", hub->name);
967  return ERROR_FAIL;
968  }
969 
970  const struct command_registration obj_commands[] = {
971  {
972  .name = hub->name,
973  .mode = COMMAND_EXEC,
974  .help = "IPDBG Hub command group.",
975  .usage = "",
977  },
979  };
980 
981  return register_commands_with_data(CMD_CTX, NULL, obj_commands, hub);
982 }
983 
984 static int ipdbg_create_hub(struct jtag_tap *tap, uint32_t user_instruction, uint8_t data_register_length,
985  struct ipdbg_virtual_ir_info *virtual_ir, const char *name, struct command_invocation *cmd)
986 {
988  if (!new_hub)
989  return ERROR_FAIL;
990 
991  if (virtual_ir)
993  new_hub->tap = tap;
996  new_hub->valid_mask = BIT(data_register_length - 1);
997  new_hub->xoff_mask = BIT(data_register_length - 2);
998  new_hub->tool_mask = (new_hub->xoff_mask - 1) >> 8;
999  new_hub->last_dn_tool = new_hub->tool_mask;
1000  new_hub->virtual_ir = virtual_ir;
1003 
1004  int retval = ipdbg_register_hub_command(new_hub, cmd);
1005  if (retval != ERROR_OK) {
1006  LOG_ERROR("Creating hub failed");
1007  ipdbg_free_hub(new_hub);
1008  return ERROR_FAIL;
1009  }
1010 
1011  ipdbg_add_hub(new_hub);
1012 
1013  return ERROR_OK;
1014 }
1015 
1016 COMMAND_HANDLER(handle_ipdbg_create_hub_command)
1017 {
1018  struct jtag_tap *tap = NULL;
1019  uint32_t user_instruction = 0x00;
1020  uint8_t data_register_length = IPDBG_MAX_DR_LENGTH;
1021  bool has_virtual_ir = false;
1022  uint32_t virtual_ir_instruction = 0x00e;
1023  uint32_t virtual_ir_length = 5;
1024  uint32_t virtual_ir_value = 0x11;
1025  struct ipdbg_virtual_ir_info *virtual_ir = NULL;
1026  int user_num = 1;
1027  bool hub_configured = false;
1028 
1029  if (CMD_ARGC < IPDBG_MIN_NUM_OF_CREATE_OPTIONS || CMD_ARGC > IPDBG_MAX_NUM_OF_CREATE_OPTIONS)
1031 
1032  const char *hub_name = CMD_ARGV[0];
1033 
1034  for (unsigned int i = 1; i < CMD_ARGC; ++i) {
1035  if (strcmp(CMD_ARGV[i], "-tap") == 0) {
1036  if (i + 1 >= CMD_ARGC || CMD_ARGV[i + 1][0] == '-') {
1037  command_print(CMD, "no TAP name given");
1038  return ERROR_FAIL;
1039  }
1040  tap = jtag_tap_by_string(CMD_ARGV[i + 1]);
1041  if (!tap) {
1042  command_print(CMD, "Tap %s unknown", CMD_ARGV[i + 1]);
1043  return ERROR_FAIL;
1044  }
1045  ++i;
1046  } else if (strcmp(CMD_ARGV[i], "-ir") == 0) {
1047  COMMAND_PARSE_ADDITIONAL_NUMBER(u32, i, user_instruction, "ir_value to select hub");
1048  hub_configured = true;
1049  COMMAND_PARSE_OPTIONAL_NUMBER(u8, i, data_register_length);
1050  if (data_register_length < IPDBG_MIN_DR_LENGTH ||
1051  data_register_length > IPDBG_MAX_DR_LENGTH) {
1052  command_print(CMD, "length of \"user\"-data register must be at least %d and at most %d.",
1054  return ERROR_FAIL;
1055  }
1056  } else if (strcmp(CMD_ARGV[i], "-pld") == 0) {
1057  ++i;
1058  if (i >= CMD_ARGC || CMD_ARGV[i][0] == '-')
1061  if (!device || !device->driver) {
1062  command_print(CMD, "pld device '#%s' is out of bounds or unknown", CMD_ARGV[i]);
1063  return ERROR_FAIL;
1064  }
1065  COMMAND_PARSE_OPTIONAL_NUMBER(int, i, user_num);
1066  struct pld_ipdbg_hub pld_hub;
1067  struct pld_driver *driver = device->driver;
1068  if (!driver->get_ipdbg_hub) {
1069  command_print(CMD, "pld driver has no ipdbg support");
1070  return ERROR_FAIL;
1071  }
1072  if (driver->get_ipdbg_hub(user_num, device, &pld_hub) != ERROR_OK) {
1073  command_print(CMD, "unable to retrieve hub from pld driver");
1074  return ERROR_FAIL;
1075  }
1076  if (!pld_hub.tap) {
1077  command_print(CMD, "no tap received from pld driver");
1078  return ERROR_FAIL;
1079  }
1080  hub_configured = true;
1081  user_instruction = pld_hub.user_ir_code;
1082  tap = pld_hub.tap;
1083 
1084  } else if (strcmp(CMD_ARGV[i], "-vir") == 0) {
1085  COMMAND_PARSE_OPTIONAL_NUMBER(u32, i, virtual_ir_value);
1086  COMMAND_PARSE_OPTIONAL_NUMBER(u32, i, virtual_ir_length);
1087  COMMAND_PARSE_OPTIONAL_NUMBER(u32, i, virtual_ir_instruction);
1088  has_virtual_ir = true;
1089  } else {
1090  command_print(CMD, "Unknown argument: %s", CMD_ARGV[i]);
1091  return ERROR_FAIL;
1092  }
1093  }
1094  if (!tap) {
1095  command_print(CMD, "no valid tap selected");
1096  return ERROR_FAIL;
1097  }
1098 
1099  if (!hub_configured) {
1100  command_print(CMD, "hub not configured correctly");
1101  return ERROR_FAIL;
1102  }
1103 
1104  if (ipdbg_get_hub_by_name(hub_name)) {
1105  LOG_ERROR("IPDBG hub with name '%s' already exists", hub_name);
1106  return ERROR_FAIL;
1107  }
1108 
1109  if (has_virtual_ir) {
1110  virtual_ir = calloc(1, sizeof(struct ipdbg_virtual_ir_info));
1111  if (!virtual_ir) {
1112  LOG_ERROR("Out of memory");
1113  return ERROR_FAIL;
1114  }
1115  virtual_ir->instruction = virtual_ir_instruction;
1116  virtual_ir->length = virtual_ir_length;
1117  virtual_ir->value = virtual_ir_value;
1118  }
1119 
1120  if (ipdbg_find_hub(tap, user_instruction, virtual_ir)) {
1121  LOG_ERROR("IPDBG hub for given TAP and user-instruction already exists");
1122  free(virtual_ir);
1123  return ERROR_FAIL;
1124  }
1125 
1126  int retval = ipdbg_create_hub(tap, user_instruction, data_register_length, virtual_ir, hub_name, cmd);
1127  if (retval != ERROR_OK)
1128  free(virtual_ir);
1129 
1130  return retval;
1131 }
1132 
1133 static const struct command_registration ipdbg_config_command_handlers[] = {
1134  {
1135  .name = "create-hub",
1136  .mode = COMMAND_ANY,
1137  .handler = handle_ipdbg_create_hub_command,
1138  .help = "create a IPDBG Hub",
1139  .usage = "name.ipdbghub (-tap device.tap -ir ir_value [dr_length] |"
1140  " -pld name.pld [user]) [-vir [vir_value [length [instr_code]]]]",
1141  },
1143 };
1144 
1145 static const struct command_registration ipdbg_command_handlers[] = {
1146  {
1147  .name = "ipdbg",
1148  .mode = COMMAND_ANY,
1149  .help = "IPDBG Hub/Host commands.",
1150  .usage = "",
1152  },
1154 };
1155 
1157 {
1158  return register_commands(cmd_ctx, NULL, ipdbg_command_handlers);
1159 }
const char * name
Definition: armv4_5.c:76
static const struct device_t * device
Definition: at91rm9200.c:94
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.
Definition: binarybuffer.h:99
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.
Definition: binarybuffer.h:31
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:443
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:141
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
Definition: command.h:118
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:156
static int register_commands_with_data(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds, void *data)
Register one or more commands, as register_commands(), plus specify a pointer to command private data...
Definition: command.h:315
#define ERROR_COMMAND_SYNTAX_ERROR
Definition: command.h:402
#define CMD_DATA
Use this macro to access the invoked command handler's data pointer, rather than accessing the variab...
Definition: command.h:176
#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 ...
Definition: command.h:467
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:151
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:146
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
#define ERROR_COMMAND_ARGUMENT_INVALID
Definition: command.h:404
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,...
Definition: command.h:274
#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...
Definition: command.h:489
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
static struct esp_usb_jtag * priv
Definition: esp_usb_jtag.c:219
COMMAND_HANDLER(handle_ipdbg_start_command)
Definition: ipdbg.c:824
static const struct command_registration ipdbg_hub_subcommand_handlers[]
Definition: ipdbg.c:941
static int ipdbg_create_service(struct ipdbg_hub *hub, uint8_t tool, struct ipdbg_service **service, uint16_t port)
Definition: ipdbg.c:186
static void ipdbg_add_service(struct ipdbg_service *service)
Definition: ipdbg.c:175
static int ipdbg_remove_service(struct ipdbg_service *service)
Definition: ipdbg.c:201
static int ipdbg_polling_callback(void *priv)
Definition: ipdbg.c:560
#define IPDBG_BUFFER_SIZE
Definition: ipdbg.c:17
static int ipdbg_stop(struct ipdbg_hub *hub, uint8_t tool)
Definition: ipdbg.c:848
#define IPDBG_NUM_OF_QUEUE_OPTIONS
Definition: ipdbg.c:22
static bool ipdbg_fifo_is_empty(struct ipdbg_fifo *fifo)
Definition: ipdbg.c:93
static struct ipdbg_hub * ipdbg_first_hub
Definition: ipdbg.c:83
#define IPDBG_SCRATCH_MEMORY_SIZE
Definition: ipdbg.c:26
static int ipdbg_shift_vir(struct ipdbg_hub *hub)
Definition: ipdbg.c:361
static struct ipdbg_hub * ipdbg_find_hub(struct jtag_tap *tap, uint32_t user_instruction, struct ipdbg_virtual_ir_info *virtual_ir)
Definition: ipdbg.c:220
static struct ipdbg_service * ipdbg_find_service(struct ipdbg_hub *hub, uint8_t tool)
Definition: ipdbg.c:165
static void ipdbg_free_hub(struct ipdbg_hub *hub)
Definition: ipdbg.c:269
static const struct command_registration ipdbg_config_command_handlers[]
Definition: ipdbg.c:1133
static int ipdbg_shift_instr(struct ipdbg_hub *hub, uint32_t instr)
Definition: ipdbg.c:330
static int ipdbg_get_flow_control_info_from_hub(struct ipdbg_hub *hub)
Definition: ipdbg.c:607
static int ipdbg_move_buffer_to_connection(struct connection *conn, struct ipdbg_fifo *fifo)
Definition: ipdbg.c:132
#define IPDBG_TCP_PORT_STR_MAX_LENGTH
Definition: ipdbg.c:25
static int ipdbg_shift_data(struct ipdbg_hub *hub, uint32_t dn_data, uint32_t *up_data)
Definition: ipdbg.c:385
static void ipdbg_init_fifo(struct ipdbg_fifo *fifo)
Definition: ipdbg.c:87
#define IPDBG_NUM_OF_START_OPTIONS
Definition: ipdbg.c:20
static int ipdbg_on_connection_input(struct connection *connection)
Definition: ipdbg.c:707
int ipdbg_register_commands(struct command_context *cmd_ctx)
Definition: ipdbg.c:1156
static int ipdbg_remove_hub(struct ipdbg_hub *hub)
Definition: ipdbg.c:250
static int ipdbg_on_new_connection(struct connection *connection)
Definition: ipdbg.c:685
static void ipdbg_add_hub(struct ipdbg_hub *hub)
Definition: ipdbg.c:238
static int ipdbg_start(struct ipdbg_hub *hub, uint16_t port, uint8_t tool)
Definition: ipdbg.c:799
#define IPDBG_MIN_DR_LENGTH
Definition: ipdbg.c:23
static int ipdbg_jtag_transfer_byte(struct ipdbg_hub *hub, size_t tool, struct ipdbg_connection *connection)
Definition: ipdbg.c:488
#define IPDBG_MAX_DR_LENGTH
Definition: ipdbg.c:24
static const struct command_registration ipdbg_command_handlers[]
Definition: ipdbg.c:1145
static int ipdbg_start_polling(struct ipdbg_service *service, struct connection *connection)
Definition: ipdbg.c:634
static const struct service_driver ipdbg_service_driver
Definition: ipdbg.c:737
static int ipdbg_stop_service(struct ipdbg_service *service)
Definition: ipdbg.c:756
static int ipdbg_stop_polling(struct ipdbg_service *service)
Definition: ipdbg.c:671
static bool ipdbg_fifo_is_full(struct ipdbg_fifo *fifo)
Definition: ipdbg.c:98
static int ipdbg_on_connection_closed(struct connection *connection)
Definition: ipdbg.c:728
static int ipdbg_max_tools_from_data_register_length(uint8_t data_register_length)
Definition: ipdbg.c:154
static void ipdbg_zero_rd_idx(struct ipdbg_fifo *fifo)
Definition: ipdbg.c:103
static COMMAND_HELPER(ipdbg_config_queuing, struct ipdbg_hub *hub, unsigned int size)
Definition: ipdbg.c:901
static void ipdbg_append_to_fifo(struct ipdbg_fifo *fifo, char data)
Definition: ipdbg.c:114
static const struct command_registration ipdbg_hostserver_subcommand_handlers[]
Definition: ipdbg.c:884
int ipdbg_server_free(void)
Definition: ipdbg.c:776
static void ipdbg_init_scan_field(struct scan_field *fields, uint8_t *in_value, int num_bits, const uint8_t *out_value)
Definition: ipdbg.c:321
static int ipdbg_shift_empty_data(struct ipdbg_hub *hub)
Definition: ipdbg.c:445
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, const char *name, struct command_invocation *cmd)
Definition: ipdbg.c:984
#define IPDBG_NUM_OF_STOP_OPTIONS
Definition: ipdbg.c:21
static struct ipdbg_service * ipdbg_first_service
Definition: ipdbg.c:85
static char ipdbg_get_from_fifo(struct ipdbg_fifo *fifo)
Definition: ipdbg.c:123
static int ipdbg_distribute_data_from_hub(struct ipdbg_hub *hub, uint32_t up)
Definition: ipdbg.c:407
static void ipdbg_check_for_xoff(struct ipdbg_hub *hub, size_t tool, uint32_t rx_data)
Definition: ipdbg.c:434
static struct ipdbg_hub * ipdbg_allocate_hub(uint8_t data_register_length, struct ipdbg_virtual_ir_info *virtual_ir, const char *name)
Definition: ipdbg.c:283
static int ipdbg_register_hub_command(struct ipdbg_hub *hub, struct command_invocation *cmd)
Definition: ipdbg.c:959
static struct ipdbg_hub * ipdbg_get_hub_by_name(const char *name)
Definition: ipdbg.c:746
static int ipdbg_jtag_transfer_bytes(struct ipdbg_hub *hub, size_t tool, struct ipdbg_connection *connection)
Definition: ipdbg.c:506
#define IPDBG_MAX_NUM_OF_CREATE_OPTIONS
Definition: ipdbg.c:19
struct jtag_tap * jtag_tap_by_string(const char *s)
Definition: jtag/core.c:237
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
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.
Definition: jtag/core.c:374
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.
Definition: jtag/core.c:451
The JTAG interface can be implemented with a software or hardware fifo.
@ TAP_IDLE
Definition: jtag.h:53
#define ERROR_FAIL
Definition: log.h:170
#define LOG_ERROR(expr ...)
Definition: log.h:132
#define LOG_INFO(expr ...)
Definition: log.h:126
#define ERROR_OK
Definition: log.h:164
struct pld_device * get_pld_device_by_name_or_numstr(const char *str)
Definition: pld.c:56
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
int connection_write(struct connection *connection, const void *data, int len)
Definition: server.c:732
int connection_read(struct connection *connection, void *data, int len)
Definition: server.c:744
int remove_service(const char *name, const char *port)
Definition: server.c:355
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
Definition: server.c:198
#define ERROR_SERVER_REMOTE_CLOSED
Definition: server.h:119
#define BIT(nr)
Definition: stm32l4x.h:18
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
const char * name
Definition: command.h:235
void * priv
Definition: server.h:43
struct service * service
Definition: server.h:41
struct ipdbg_fifo up_fifo
Definition: ipdbg.c:37
struct ipdbg_fifo dn_fifo
Definition: ipdbg.c:36
bool closed
Definition: ipdbg.c:38
size_t count
Definition: ipdbg.c:30
size_t rd_idx
Definition: ipdbg.c:31
char buffer[IPDBG_BUFFER_SIZE]
Definition: ipdbg.c:32
uint8_t * vir_out_val
Definition: ipdbg.c:58
struct scan_field * fields
Definition: ipdbg.c:59
uint8_t * dr_out_vals
Definition: ipdbg.c:56
uint8_t * dr_in_vals
Definition: ipdbg.c:57
uint32_t active_services
Definition: ipdbg.c:66
struct ipdbg_hub * next
Definition: ipdbg.c:73
uint32_t last_dn_tool
Definition: ipdbg.c:70
uint32_t valid_mask
Definition: ipdbg.c:67
uint8_t dn_xoff
Definition: ipdbg.c:77
uint32_t max_tools
Definition: ipdbg.c:64
struct ipdbg_virtual_ir_info * virtual_ir
Definition: ipdbg.c:79
struct jtag_tap * tap
Definition: ipdbg.c:74
uint32_t tool_mask
Definition: ipdbg.c:69
size_t using_queue_size
Definition: ipdbg.c:72
struct ipdbg_hub_scratch_memory scratch_memory
Definition: ipdbg.c:80
struct connection ** connections
Definition: ipdbg.c:75
uint32_t xoff_mask
Definition: ipdbg.c:68
uint8_t flow_control_enabled
Definition: ipdbg.c:78
char * name
Definition: ipdbg.c:71
uint8_t data_register_length
Definition: ipdbg.c:76
uint32_t active_connections
Definition: ipdbg.c:65
uint32_t user_instruction
Definition: ipdbg.c:63
struct ipdbg_hub * hub
Definition: ipdbg.c:42
uint8_t tool
Definition: ipdbg.c:46
uint16_t port
Definition: ipdbg.c:44
struct ipdbg_service * next
Definition: ipdbg.c:43
uint32_t value
Definition: ipdbg.c:52
uint32_t length
Definition: ipdbg.c:51
uint32_t instruction
Definition: ipdbg.c:50
Definition: jtag.h:101
uint8_t * cur_instr
current instruction
Definition: jtag.h:132
int ir_length
size of instruction register
Definition: jtag.h:110
Definition: pld.h:48
Definition: pld.h:31
int(* get_ipdbg_hub)(int user_num, struct pld_device *pld_device, struct pld_ipdbg_hub *hub)
Definition: pld.h:36
unsigned int user_ir_code
Definition: pld.h:20
struct jtag_tap * tap
Definition: pld.h:19
This structure defines a single scan field in the scan.
Definition: jtag.h:87
int num_bits
The number of bits this field specifies.
Definition: jtag.h:89
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:93
uint8_t * check_value
The value used to check the data scanned out.
Definition: jtag.h:96
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:91
uint8_t * check_mask
The mask to go with check_value.
Definition: jtag.h:98
const char * name
the name of the server
Definition: server.h:49
Definition: server.h:67
struct service * next
Definition: server.h:82
void * priv
Definition: server.h:81
char * port
Definition: server.h:70
int target_unregister_timer_callback(int(*callback)(void *priv), void *priv)
Definition: target.c:1748
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...
Definition: target.c:1658
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
Definition: types.h:79
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1