34 #include <libjaylink/libjaylink.h>
36 static struct jaylink_context *
jayctx;
37 static struct jaylink_device_handle *
devh;
38 static struct jaylink_connection
conn;
39 static struct jaylink_connection
connlist[JAYLINK_MAX_CONNECTIONS];
41 static uint8_t
caps[JAYLINK_DEV_EXT_CAPS_SIZE];
48 static enum jaylink_target_interface
iface = JAYLINK_TIF_JTAG;
51 #define JLINK_MAX_SPEED 12000
52 #define JLINK_TAP_BUFFER_SIZE 2048
57 #define SWO_MAX_FREQ_DEV 0.03
108 const uint8_t *tms_out,
unsigned tms_offset,
109 uint8_t *in,
unsigned in_offset,
126 LOG_DEBUG_IO(
"runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
127 cmd->cmd.runtest->end_state);
144 cmd->cmd.pathmove->num_states,
145 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
152 LOG_DEBUG_IO(
"%s type:%d",
cmd->cmd.scan->ir_scan ?
"IRSCAN" :
"DRSCAN",
156 while (
cmd->cmd.scan->num_fields > 0
157 &&
cmd->cmd.scan->fields[
cmd->cmd.scan->num_fields - 1].num_bits == 0) {
158 cmd->cmd.scan->num_fields--;
159 LOG_DEBUG(
"discarding trailing empty field");
162 if (
cmd->cmd.scan->num_fields == 0) {
167 if (
cmd->cmd.scan->ir_scan) {
182 unsigned scan_size = 0;
184 for (
int i = 0; i <
cmd->cmd.scan->num_fields; i++, field++) {
190 cmd->cmd.scan->num_fields,
203 uint8_t last_bit = 0;
206 uint8_t tms_bits = 0x01;
239 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR", scan_size,
272 LOG_ERROR(
"BUG: Unknown JTAG command type encountered");
299 struct jaylink_speed tmp;
302 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
303 ret = jaylink_get_speeds(
devh, &tmp);
305 if (ret != JAYLINK_OK) {
306 LOG_ERROR(
"jaylink_get_speeds() failed: %s",
307 jaylink_strerror(ret));
312 max_speed = tmp.freq / tmp.div;
318 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING)) {
319 LOG_ERROR(
"Adaptive clocking is not supported by the device");
323 speed = JAYLINK_SPEED_ADAPTIVE_CLOCKING;
324 }
else if (speed > max_speed) {
325 LOG_INFO(
"Reduced speed from %d kHz to %d kHz (maximum)", speed,
330 ret = jaylink_set_speed(
devh, speed);
332 if (ret != JAYLINK_OK) {
333 LOG_ERROR(
"jaylink_set_speed() failed: %s",
334 jaylink_strerror(ret));
359 ret = jaylink_read_raw_config(
devh, (uint8_t *)cfg);
361 if (ret != JAYLINK_OK) {
362 LOG_ERROR(
"jaylink_read_raw_config() failed: %s",
363 jaylink_strerror(ret));
381 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SELECT_TIF)) {
382 if (
iface != JAYLINK_TIF_JTAG) {
383 LOG_ERROR(
"Device supports JTAG transport only");
390 ret = jaylink_get_available_interfaces(
devh, &interfaces);
392 if (ret != JAYLINK_OK) {
393 LOG_ERROR(
"jaylink_get_available_interfaces() failed: %s",
394 jaylink_strerror(ret));
398 if (!(interfaces & (1 <<
iface))) {
399 LOG_ERROR(
"Selected transport is not supported by the device");
406 LOG_ERROR(
"jaylink_select_interface() failed: %s",
407 jaylink_strerror(ret));
421 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER))
426 if (ret != JAYLINK_OK) {
427 LOG_ERROR(
"jaylink_register() failed: %s", jaylink_strerror(ret));
431 handle_found =
false;
433 for (i = 0; i <
count; i++) {
441 LOG_ERROR(
"Registration failed: maximum number of connections on the "
459 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
462 ret = jaylink_get_free_memory(
devh, &tmp);
464 if (ret != JAYLINK_OK) {
465 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
466 jaylink_strerror(ret));
471 LOG_ERROR(
"Not enough free device internal memory: %" PRIu32
" bytes", tmp);
479 LOG_DEBUG(
"Adjusted SWD transaction buffer size to %u bytes",
487 enum jaylink_log_level level,
const char *format, va_list args,
493 case JAYLINK_LOG_LEVEL_ERROR:
496 case JAYLINK_LOG_LEVEL_WARNING:
503 case JAYLINK_LOG_LEVEL_INFO:
504 case JAYLINK_LOG_LEVEL_DEBUG:
507 case JAYLINK_LOG_LEVEL_DEBUG_IO:
527 retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports);
529 if (retval == JAYLINK_ERR_NOT_SUPPORTED) {
531 }
else if (retval != JAYLINK_OK) {
532 LOG_WARNING(
"jaylink_device_get_usb_bus_ports() failed: %s",
533 jaylink_strerror(retval));
546 int ret = jaylink_discovery_scan(
jayctx, ifaces);
547 if (ret != JAYLINK_OK) {
548 LOG_ERROR(
"jaylink_discovery_scan() failed: %s", jaylink_strerror(ret));
554 struct jaylink_device **
devs;
555 ret = jaylink_get_devices(
jayctx, &
devs, &num_devices);
557 if (ret != JAYLINK_OK) {
558 LOG_ERROR(
"jaylink_get_devices() failed: %s", jaylink_strerror(ret));
566 LOG_ERROR(
"Multiple devices found, specify the desired device");
567 jaylink_free_devices(
devs,
true);
572 *found_device =
false;
574 for (
size_t i = 0;
devs[i]; i++) {
575 struct jaylink_device *dev =
devs[i];
579 ret = jaylink_device_get_serial_number(dev, &tmp);
581 if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
583 }
else if (ret != JAYLINK_OK) {
584 LOG_WARNING(
"jaylink_device_get_serial_number() failed: %s",
585 jaylink_strerror(ret));
594 enum jaylink_usb_address address;
595 ret = jaylink_device_get_usb_address(dev, &address);
597 if (ret == JAYLINK_ERR_NOT_SUPPORTED) {
599 }
else if (ret != JAYLINK_OK) {
600 LOG_WARNING(
"jaylink_device_get_usb_address() failed: %s",
601 jaylink_strerror(ret));
612 ret = jaylink_open(dev, &
devh);
614 if (ret == JAYLINK_OK) {
615 *found_device =
true;
619 LOG_ERROR(
"Failed to open device: %s", jaylink_strerror(ret));
622 jaylink_free_devices(
devs,
true);
630 char *firmware_version;
631 struct jaylink_hardware_version hwver;
632 struct jaylink_hardware_status hwstatus;
635 LOG_DEBUG(
"Using libjaylink %s (compiled with %s)",
636 jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING);
638 if (!jaylink_library_has_cap(JAYLINK_CAP_HIF_USB) &&
use_usb_address) {
639 LOG_ERROR(
"J-Link driver does not support USB devices");
643 ret = jaylink_init(&
jayctx);
645 if (ret != JAYLINK_OK) {
646 LOG_ERROR(
"jaylink_init() failed: %s", jaylink_strerror(ret));
652 if (ret != JAYLINK_OK) {
653 LOG_ERROR(
"jaylink_log_set_callback() failed: %s",
654 jaylink_strerror(ret));
662 if (ret == JAYLINK_ERR) {
667 if (ret != JAYLINK_OK) {
668 LOG_ERROR(
"jaylink_parse_serial_number() failed: %s", jaylink_strerror(ret));
698 ret = jaylink_get_firmware_version(
devh, &firmware_version, &
length);
700 if (ret != JAYLINK_OK) {
701 LOG_ERROR(
"jaylink_get_firmware_version() failed: %s",
702 jaylink_strerror(ret));
708 free(firmware_version);
710 LOG_WARNING(
"Device responds empty firmware version string");
713 memset(
caps, 0, JAYLINK_DEV_EXT_CAPS_SIZE);
716 if (ret != JAYLINK_OK) {
717 LOG_ERROR(
"jaylink_get_caps() failed: %s", jaylink_strerror(ret));
723 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_EXT_CAPS)) {
724 ret = jaylink_get_extended_caps(
devh,
caps);
726 if (ret != JAYLINK_OK) {
727 LOG_ERROR(
"jaylink_get_extended_caps() failed: %s",
728 jaylink_strerror(ret));
737 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_HW_VERSION)) {
738 ret = jaylink_get_hardware_version(
devh, &hwver);
740 if (ret != JAYLINK_OK) {
741 LOG_ERROR(
"Failed to retrieve hardware version: %s",
742 jaylink_strerror(ret));
748 LOG_INFO(
"Hardware version: %u.%02u", hwver.major, hwver.minor);
750 if (hwver.major >= 5)
754 if (
iface == JAYLINK_TIF_SWD) {
768 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
770 LOG_ERROR(
"Failed to read device configuration data");
779 ret = jaylink_get_hardware_status(
devh, &hwstatus);
781 if (ret != JAYLINK_OK) {
782 LOG_ERROR(
"jaylink_get_hardware_status() failed: %s",
783 jaylink_strerror(ret));
789 LOG_INFO(
"VTarget = %u.%03u V", hwstatus.target_voltage / 1000,
790 hwstatus.target_voltage % 1000);
794 strcpy(
conn.hid,
"0.0.0.0");
820 if (
iface == JAYLINK_TIF_JTAG) {
841 ret = jaylink_swo_stop(
devh);
843 if (ret != JAYLINK_OK)
844 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
847 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER)) {
850 if (ret != JAYLINK_OK)
851 LOG_ERROR(
"jaylink_unregister() failed: %s",
852 jaylink_strerror(ret));
878 uint8_t tms_scan_bits;
893 for (i = 0; i < num_states; i++) {
899 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
916 for (i = 0; i < num_cycles; i++)
942 LOG_DEBUG(
"TRST: %i, SRST: %i", trst, srst);
946 jaylink_set_reset(
devh);
949 jaylink_clear_reset(
devh);
952 jaylink_jtag_clear_trst(
devh);
955 jaylink_jtag_set_trst(
devh);
972 if (sscanf(
CMD_ARGV[0],
"%i", &tmp) != 1) {
977 if (tmp < JAYLINK_USB_ADDRESS_0 || tmp > JAYLINK_USB_ADDRESS_3) {
992 struct jaylink_hardware_status
status;
994 ret = jaylink_get_hardware_status(
devh, &
status);
996 if (ret != JAYLINK_OK) {
998 jaylink_strerror(ret));
1003 status.target_voltage / 1000,
status.target_voltage % 1000);
1009 if (
status.target_voltage < 1500)
1020 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) {
1026 ret = jaylink_get_free_memory(
devh, &tmp);
1028 if (ret != JAYLINK_OK) {
1030 jaylink_strerror(ret));
1046 case JAYLINK_JTAG_VERSION_2:
1049 case JAYLINK_JTAG_VERSION_3:
1058 if (sscanf(
CMD_ARGV[0],
"%i", &tmp) != 1) {
1089 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1097 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1104 ret = jaylink_set_target_power(
devh, enable);
1106 if (ret != JAYLINK_OK) {
1108 jaylink_strerror(ret));
1158 "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]",
1170 const char *current_target_power;
1178 current_target_power =
"off";
1180 current_target_power =
"on";
1184 current_target_power);
1195 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER))
1198 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1213 if (ret != JAYLINK_OK) {
1214 LOG_ERROR(
"jaylink_swo_read() failed: %s", jaylink_strerror(ret));
1228 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
1231 ret = jaylink_get_free_memory(
devh, &tmp);
1233 if (ret != JAYLINK_OK) {
1234 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
1235 jaylink_strerror(ret));
1239 if (tmp > 0x3fff || tmp <= 0x600)
1244 return tmp & 0xffffff00;
1248 uint32_t trace_freq, uint16_t *prescaler)
1250 unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1255 unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1256 if (presc * trace_freq < traceclkin_freq - max_deviation ||
1257 presc * trace_freq > traceclkin_freq + max_deviation)
1266 unsigned int traceclkin_freq,
unsigned int *trace_freq,
1267 uint16_t *prescaler)
1273 for (divider = speed.min_div; divider <= speed.max_div; divider++) {
1274 *trace_freq = speed.freq / divider;
1280 deviation = fabs(1.0 - ((
double)*trace_freq * presc / traceclkin_freq));
1292 uint32_t port_size,
unsigned int *trace_freq,
1293 unsigned int traceclkin_freq, uint16_t *prescaler)
1296 uint32_t buffer_size;
1297 struct jaylink_swo_speed speed;
1304 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SWO)) {
1308 LOG_ERROR(
"Trace capturing is not supported by the device");
1312 ret = jaylink_swo_stop(
devh);
1314 if (ret != JAYLINK_OK) {
1315 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
1331 LOG_ERROR(
"Selected pin protocol is not supported");
1338 LOG_ERROR(
"Not enough free device memory to start trace capturing");
1342 ret = jaylink_swo_get_speeds(
devh, JAYLINK_SWO_MODE_UART, &speed);
1344 if (ret != JAYLINK_OK) {
1345 LOG_ERROR(
"jaylink_swo_get_speeds() failed: %s",
1346 jaylink_strerror(ret));
1350 if (*trace_freq > 0) {
1351 divider = speed.freq / *trace_freq;
1352 min_freq = speed.freq / speed.max_div;
1353 max_freq = speed.freq / speed.min_div;
1355 if (*trace_freq > max_freq) {
1356 LOG_INFO(
"Given SWO frequency too high, using %" PRIu32
" Hz instead",
1358 *trace_freq = max_freq;
1359 }
else if (*trace_freq < min_freq) {
1360 LOG_INFO(
"Given SWO frequency too low, using %" PRIu32
" Hz instead",
1362 *trace_freq = min_freq;
1363 }
else if (*trace_freq != speed.freq / divider) {
1364 *trace_freq = speed.freq / divider;
1366 LOG_INFO(
"Given SWO frequency is not supported by the device, "
1367 "using %u Hz instead", *trace_freq);
1372 LOG_ERROR(
"SWO frequency is not suitable. Please choose a "
1373 "different frequency or use auto-detection");
1377 LOG_INFO(
"Trying to auto-detect SWO frequency");
1381 LOG_ERROR(
"Maximum permitted frequency deviation of %.02f %% "
1383 LOG_ERROR(
"Auto-detection of SWO frequency failed");
1387 LOG_INFO(
"Using SWO frequency of %u Hz", *trace_freq);
1390 ret = jaylink_swo_start(
devh, JAYLINK_SWO_MODE_UART, *trace_freq,
1393 if (ret != JAYLINK_OK) {
1394 LOG_ERROR(
"jaylink_start_swo() failed: %s", jaylink_strerror(ret));
1398 LOG_DEBUG(
"Using %" PRIu32
" bytes device memory for trace capturing",
1415 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1424 if (sscanf(
CMD_ARGV[0],
"%" SCNd8, &tmp) != 1) {
1429 if (tmp > JAYLINK_USB_ADDRESS_3) {
1446 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1452 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1463 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1485 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1491 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1502 if ((strlen(str) != 17) || (str[2] !=
':' || str[5] !=
':' ||
1503 str[8] !=
':' || str[11] !=
':' || str[14] !=
':')) {
1508 for (i = 5; i >= 0; i--) {
1509 addr[i] = strtoul(str, &e, 16);
1518 if (!(0x01 &
addr[0])) {
1535 const char *s_save = s;
1541 for (i = 0; i < 4; i++) {
1542 lip[i] = strtoul(s, &e, 10);
1544 if (*e !=
'.' && i != 3)
1551 memcpy(ip, lip,
sizeof(lip));
1556 static void cpy_ip(uint8_t *dst, uint8_t *src)
1560 for (i = 0, j = 3; i < 4; i++, j--)
1569 uint8_t subnet_bits = 24;
1571 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1577 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1610 ((1ULL << subnet_bits) - 1) : 0xffffffff);
1621 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG))
1634 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1640 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) {
1648 "the configuration");
1652 ret = jaylink_write_raw_config(
devh, (
const uint8_t *)&
tmp_config);
1654 if (ret != JAYLINK_OK) {
1655 LOG_ERROR(
"jaylink_write_raw_config() failed: %s",
1656 jaylink_strerror(ret));
1661 LOG_ERROR(
"Failed to read device configuration for verification");
1666 LOG_ERROR(
"Verification of device configuration failed. Please check "
1673 "cycling the J-Link device");
1680 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1703 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1704 LOG_ERROR(
"Device does not support EMUCOM");
1713 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1717 buf = malloc(tmp / 2);
1726 if (
dummy != (tmp / 2)) {
1727 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1733 ret = jaylink_emucom_write(
devh, channel, buf, &
length);
1737 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1738 LOG_ERROR(
"Channel not supported by the device");
1740 }
else if (ret != JAYLINK_OK) {
1741 LOG_ERROR(
"Failed to write to channel: %s", jaylink_strerror(ret));
1762 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1763 LOG_ERROR(
"Device does not support EMUCOM");
1770 buf = malloc(
length * 3 + 1);
1777 ret = jaylink_emucom_read(
devh, channel, buf, &
length);
1779 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1780 LOG_ERROR(
"Channel is not supported by the device");
1783 }
else if (ret == JAYLINK_ERR_DEV_NOT_AVAILABLE) {
1784 LOG_ERROR(
"Channel is not available for the requested amount of data. "
1785 "%" PRIu32
" bytes are available",
length);
1788 }
else if (ret != JAYLINK_OK) {
1789 LOG_ERROR(
"Failed to read from channel: %s", jaylink_strerror(ret));
1797 LOG_ERROR(
"Failed to convert data into hexadecimal string");
1811 .handler = &jlink_handle_config_usb_address_command,
1813 .help =
"set the USB address",
1817 .name =
"targetpower",
1818 .handler = &jlink_handle_config_target_power_command,
1820 .help =
"set the target power supply",
1825 .handler = &jlink_handle_config_mac_address_command,
1827 .help =
"set the MAC Address",
1828 .usage =
"[ff:ff:ff:ff:ff:ff]",
1832 .handler = &jlink_handle_config_ip_address_command,
1834 .help =
"set the IP address, where A.B.C.D is the IP address, "
1835 "E the bit of the subnet mask, F.G.H.I the subnet mask",
1836 .usage =
"[A.B.C.D[/E] [F.G.H.I]]",
1840 .handler = &jlink_handle_config_reset_command,
1842 .help =
"undo configuration changes",
1847 .handler = &jlink_handle_config_write_command,
1849 .help =
"write configuration to the device",
1858 .handler = &jlink_handle_emucom_write_command,
1860 .help =
"write to a channel",
1861 .usage =
"<channel> <data>",
1865 .handler = &jlink_handle_emucom_read_command,
1867 .help =
"read from a channel",
1868 .usage =
"<channel> <length>"
1876 .handler = &jlink_handle_jlink_jtag_command,
1878 .help =
"select the JTAG command version",
1882 .name =
"targetpower",
1883 .handler = &jlink_handle_target_power_command,
1885 .help =
"set the target power supply",
1890 .handler = &jlink_handle_free_memory_command,
1892 .help =
"show free device memory",
1897 .handler = &jlink_handle_hwstatus_command,
1899 .help =
"show the hardware status",
1904 .handler = &jlink_usb_command,
1906 .help =
"set the USB address of the device that should be used",
1911 .handler = &jlink_handle_config_command,
1913 .help =
"access the device configuration. If no argument is given "
1914 "this will show the device configuration",
1921 .help =
"access EMUCOM channel",
1932 .help =
"perform jlink management",
1941 iface = JAYLINK_TIF_SWD;
1980 #define MAX_PENDING_SCAN_RESULTS 256
1994 const uint8_t *tms_out,
unsigned tms_offset,
1995 uint8_t *in,
unsigned in_offset,
2001 if (!available_length ||
2011 unsigned scan_length =
length > available_length ?
2012 available_length :
length;
2028 out_offset += scan_length;
2029 tms_offset += scan_length;
2030 in_offset += scan_length;
2049 if (ret != JAYLINK_OK) {
2050 LOG_ERROR(
"jaylink_jtag_io() failed: %s", jaylink_strerror(ret));
2085 const uint32_t dir_out = 0xffffffff;
2098 const uint32_t dir_in = 0;
2146 LOG_ERROR(
"Sequence %d not supported", seq);
2175 if (ret != JAYLINK_OK) {
2176 LOG_ERROR(
"jaylink_swd_io() failed: %s", jaylink_strerror(ret));
2194 LOG_ERROR(
"SWD: Read data parity mismatch");
const char * adapter_get_required_serial(void)
Retrieves the serial number set with command 'adapter serial'.
bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
const char * adapter_usb_get_location(void)
@ TPIU_PIN_PROTOCOL_ASYNC_UART
asynchronous output with NRZ coding
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
static void bit_copy(uint8_t *dst, unsigned dst_offset, const uint8_t *src, unsigned src_offset, unsigned bit_count)
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 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.
#define ERROR_COMMAND_ARGUMENT_INVALID
enum scan_type jtag_scan_type(const struct scan_command *cmd)
#define TPIU_ACPR_MAX_SWOSCALER
bool tap_is_state_stable(tap_state_t astate)
Function tap_is_state_stable returns true if the astate is stable.
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.
void tap_set_end_state(tap_state_t new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
tap_state_t tap_get_end_state(void)
For more information,.
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 ...
static tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned tap_len, tap_state_t start_tap_state)
Prints verbose TAP state transitions for the given TMS/TDI buffers.
#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...
static void cpy_ip(uint8_t *dst, uint8_t *src)
static void jlink_queue_data_in(uint32_t len)
static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]
#define MAX_PENDING_SCAN_RESULTS
static int config_trace(bool enabled, enum tpiu_pin_protocol pin_protocol, uint32_t port_size, unsigned int *trace_freq, unsigned int traceclkin_freq, uint16_t *prescaler)
static int poll_trace(uint8_t *buf, size_t *size)
static void show_config_ip_address(struct command_invocation *cmd)
static int jlink_quit(void)
static uint8_t tdi_buffer[JLINK_TAP_BUFFER_SIZE]
static int jlink_khz(int khz, int *jtag_speed)
static unsigned tap_length
static bool use_serial_number
static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint32_t ap_delay_clk)
static void jlink_queue_data_out(const uint8_t *data, uint32_t len)
static void jlink_execute_scan(struct jtag_command *cmd)
static const struct command_registration jlink_config_subcommand_handlers[]
struct pending_scan_result __attribute__
static int jlink_init(void)
static void jlink_reset(int trst, int srst)
static bool use_usb_location
static int jlink_swd_switch_seq(enum swd_special_seq seq)
static bool detect_swo_freq_and_prescaler(struct jaylink_swo_speed speed, unsigned int traceclkin_freq, unsigned int *trace_freq, uint16_t *prescaler)
static int jaylink_log_handler(const struct jaylink_context *ctx, enum jaylink_log_level level, const char *format, va_list args, void *user_data)
static bool string_to_ip(const char *s, uint8_t *ip, int *pos)
static bool calculate_swo_prescaler(unsigned int traceclkin_freq, uint32_t trace_freq, uint16_t *prescaler)
static void show_config_usb_address(struct command_invocation *cmd)
static void fill_buffer(uint8_t *buf, uint32_t val, uint32_t len)
#define JLINK_TAP_BUFFER_SIZE
static int jlink_open_device(uint32_t ifaces, bool *found_device)
static void jlink_end_state(tap_state_t state)
static void jlink_clock_data(const uint8_t *out, unsigned out_offset, const uint8_t *tms_out, unsigned tms_offset, uint8_t *in, unsigned in_offset, unsigned length)
Queue data to go out and in, flushing the queue as many times as necessary.
static void jlink_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_clk)
static int jlink_speed_div(int speed, int *khz)
static int jlink_swd_run_queue(void)
static void jlink_state_move(void)
static enum jaylink_jtag_version jtag_command_version
static void jlink_execute_runtest(struct jtag_command *cmd)
static void jlink_execute_pathmove(struct jtag_command *cmd)
static int jlink_register(void)
COMMAND_HANDLER(jlink_usb_command)
static void jlink_path_move(int num_states, tap_state_t *path)
static struct jaylink_connection connlist[JAYLINK_MAX_CONNECTIONS]
static enum jaylink_usb_address usb_address
static struct pending_scan_result pending_scan_results_buffer[MAX_PENDING_SCAN_RESULTS]
static int jlink_reset_safe(int trst, int srst)
static const struct command_registration jlink_emucom_subcommand_handlers[]
static uint32_t serial_number
static bool jlink_usb_location_equal(struct jaylink_device *dev)
static struct jtag_interface jlink_interface
static bool read_device_config(struct device_config *cfg)
static int select_interface(void)
static const struct command_registration jlink_command_handlers[]
static int jlink_speed(int speed)
static int jlink_execute_command(struct jtag_command *cmd)
static bool use_usb_address
static struct jaylink_connection conn
static void jlink_runtest(int num_cycles)
static void jlink_tap_init(void)
static int jlink_swd_init(void)
static struct jaylink_device_handle * devh
static struct device_config config
static void show_config_mac_address(struct command_invocation *cmd)
static int jlink_execute_queue(struct jtag_command *cmd_queue)
static void show_config_target_power(struct command_invocation *cmd)
static struct jaylink_context * jayctx
static int jlink_flush(void)
static struct device_config tmp_config
static const char *const jlink_transports[]
static void jlink_execute_statemove(struct jtag_command *cmd)
static void show_config(struct command_invocation *cmd)
static uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE]
static enum jaylink_target_interface iface
static bool adjust_swd_buffer_size(void)
static enum tap_state jlink_last_state
static void jlink_execute_sleep(struct jtag_command *cmd)
static const struct command_registration jlink_subcommand_handlers[]
static unsigned int swd_buffer_size
struct adapter_driver jlink_adapter_driver
static uint32_t calculate_trace_buffer_size(void)
static uint8_t tms_buffer[JLINK_TAP_BUFFER_SIZE]
static const struct swd_driver jlink_swd
static void jlink_execute_stableclocks(struct jtag_command *cmd)
static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static void jlink_stableclocks(int num_cycles)
static int pending_scan_results_length
static bool trace_enabled
void jtag_sleep(uint32_t us)
#define ERROR_JTAG_DEVICE_ERROR
tap_state
Defines JTAG Test Access Port states.
#define ERROR_JTAG_QUEUE_FAILED
#define ERROR_JTAG_INIT_FAILED
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define ERROR_JTAG_NOT_IMPLEMENTED
static struct libusb_device ** devs
The usb device list.
void log_vprintf_lf(enum log_levels level, const char *file, unsigned line, const char *function, const char *format, va_list args)
#define LOG_DEBUG_IO(expr ...)
#define LOG_WARNING(expr ...)
#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.
Represents a driver for a debugging interface.
const char *const name
The name of the interface driver.
When run_command is called, a new instance will be created on the stack, filled with the proper value...
const char * usage
a string listing the options and arguments, required or optional
Represents a driver for a debugging interface.
int(* execute_queue)(struct jtag_command *cmd_queue)
Execute commands in the supplied queue.
unsigned int buffer_offset
Offset in the destination buffer.
unsigned first
First bit position in tdo_buffer to read.
uint8_t swd_cmd
SWD command.
void * buffer
Location to store the result.
uint8_t * buffer
Location to store the result.
unsigned length
Number of bits to read.
unsigned buffer_offset
Offset in the destination buffer.
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.
const uint8_t * out_value
A pointer to value to be scanned into the device.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned swd_seq_swd_to_jtag_len
static const unsigned swd_seq_jtag_to_swd_len
static const uint8_t swd_seq_dormant_to_jtag[]
Dormant-to-JTAG sequence.
static const uint8_t swd_seq_dormant_to_swd[]
Dormant-to-SWD sequence.
static const uint8_t swd_seq_jtag_to_dormant[]
JTAG-to-dormant sequence.
static const unsigned swd_seq_dormant_to_swd_len
static bool swd_cmd_returns_ack(uint8_t cmd)
Test if we can rely on ACK returned by SWD command.
static int swd_ack_to_error_code(uint8_t ack)
Convert SWD ACK value returned from DP to OpenOCD error code.
static uint8_t swd_cmd(bool is_read, bool is_ap, uint8_t regnum)
Construct a "cmd" byte, in lSB bit order, which swd_driver.read_reg() and swd_driver....
static const unsigned swd_seq_jtag_to_dormant_len
static const unsigned swd_seq_dormant_to_jtag_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
static const unsigned swd_seq_line_reset_len
static const unsigned swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_jtag_to_swd[]
JTAG-to-SWD sequence.
static const uint8_t swd_seq_swd_to_jtag[]
SWD-to-JTAG sequence.
static const uint8_t swd_seq_swd_to_dormant[]
SWD-to-dormant sequence.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static int parity_u32(uint32_t x)
Calculate the (even) parity of a 32-bit datum.
static unsigned int parity(unsigned int v)