35 #include <libjaylink/libjaylink.h>
37 static struct jaylink_context *
jayctx;
38 static struct jaylink_device_handle *
devh;
39 static struct jaylink_connection
conn;
40 static struct jaylink_connection
connlist[JAYLINK_MAX_CONNECTIONS];
42 static uint8_t
caps[JAYLINK_DEV_EXT_CAPS_SIZE];
47 static enum jaylink_target_interface
iface = JAYLINK_TIF_JTAG;
50 #define JLINK_MAX_SPEED 12000
51 #define JLINK_TAP_BUFFER_SIZE 2048
56 #define SWO_MAX_FREQ_DEV 0.03
107 const uint8_t *tms_out,
unsigned int tms_offset,
108 uint8_t *in,
unsigned int in_offset,
125 LOG_DEBUG_IO(
"runtest %i cycles, end in %i",
cmd->cmd.runtest->num_cycles,
126 cmd->cmd.runtest->end_state);
143 cmd->cmd.pathmove->num_states,
144 cmd->cmd.pathmove->path[
cmd->cmd.pathmove->num_states - 1]);
151 LOG_DEBUG_IO(
"%s type:%d",
cmd->cmd.scan->ir_scan ?
"IRSCAN" :
"DRSCAN",
155 while (
cmd->cmd.scan->num_fields > 0
156 &&
cmd->cmd.scan->fields[
cmd->cmd.scan->num_fields - 1].num_bits == 0) {
157 cmd->cmd.scan->num_fields--;
158 LOG_DEBUG(
"discarding trailing empty field");
161 if (!
cmd->cmd.scan->num_fields) {
166 if (
cmd->cmd.scan->ir_scan) {
181 unsigned int scan_size = 0;
183 for (
unsigned int i = 0; i <
cmd->cmd.scan->num_fields; i++, field++) {
189 cmd->cmd.scan->num_fields,
202 uint8_t last_bit = 0;
205 uint8_t tms_bits = 0x01;
238 (
cmd->cmd.scan->ir_scan) ?
"IR" :
"DR", scan_size,
271 LOG_ERROR(
"BUG: Unknown JTAG command type encountered");
298 struct jaylink_speed tmp;
301 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
302 ret = jaylink_get_speeds(
devh, &tmp);
304 if (ret != JAYLINK_OK) {
305 LOG_ERROR(
"jaylink_get_speeds() failed: %s",
306 jaylink_strerror(ret));
311 max_speed = tmp.freq / tmp.div;
317 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING)) {
318 LOG_ERROR(
"Adaptive clocking is not supported by the device");
322 speed = JAYLINK_SPEED_ADAPTIVE_CLOCKING;
323 }
else if (speed > max_speed) {
324 LOG_INFO(
"Reduced speed from %d kHz to %d kHz (maximum)", speed,
329 ret = jaylink_set_speed(
devh, speed);
331 if (ret != JAYLINK_OK) {
332 LOG_ERROR(
"jaylink_set_speed() failed: %s",
333 jaylink_strerror(ret));
358 ret = jaylink_read_raw_config(
devh, (uint8_t *)cfg);
360 if (ret != JAYLINK_OK) {
361 LOG_ERROR(
"jaylink_read_raw_config() failed: %s",
362 jaylink_strerror(ret));
380 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SELECT_TIF)) {
381 if (
iface != JAYLINK_TIF_JTAG) {
382 LOG_ERROR(
"Device supports JTAG transport only");
389 ret = jaylink_get_available_interfaces(
devh, &interfaces);
391 if (ret != JAYLINK_OK) {
392 LOG_ERROR(
"jaylink_get_available_interfaces() failed: %s",
393 jaylink_strerror(ret));
397 if (!(interfaces & (1 <<
iface))) {
398 LOG_ERROR(
"Selected transport is not supported by the device");
405 LOG_ERROR(
"jaylink_select_interface() failed: %s",
406 jaylink_strerror(ret));
420 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER))
425 if (ret != JAYLINK_OK) {
426 LOG_ERROR(
"jaylink_register() failed: %s", jaylink_strerror(ret));
430 handle_found =
false;
432 for (i = 0; i <
count; i++) {
440 LOG_ERROR(
"Registration failed: maximum number of connections on the "
458 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
461 ret = jaylink_get_free_memory(
devh, &tmp);
463 if (ret != JAYLINK_OK) {
464 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
465 jaylink_strerror(ret));
470 LOG_ERROR(
"Not enough free device internal memory: %" PRIu32
" bytes", tmp);
478 LOG_DEBUG(
"Adjusted SWD transaction buffer size to %u bytes",
486 enum jaylink_log_level level,
const char *format, va_list args,
492 case JAYLINK_LOG_LEVEL_ERROR:
495 case JAYLINK_LOG_LEVEL_WARNING:
502 case JAYLINK_LOG_LEVEL_INFO:
503 case JAYLINK_LOG_LEVEL_DEBUG:
506 case JAYLINK_LOG_LEVEL_DEBUG_IO:
526 retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports);
528 if (retval == JAYLINK_ERR_NOT_SUPPORTED) {
530 }
else if (retval != JAYLINK_OK) {
531 LOG_WARNING(
"jaylink_device_get_usb_bus_ports() failed: %s",
532 jaylink_strerror(retval));
545 int ret = jaylink_discovery_scan(
jayctx, ifaces);
546 if (ret != JAYLINK_OK) {
547 LOG_ERROR(
"jaylink_discovery_scan() failed: %s", jaylink_strerror(ret));
553 struct jaylink_device **
devs;
554 ret = jaylink_get_devices(
jayctx, &
devs, &num_devices);
556 if (ret != JAYLINK_OK) {
557 LOG_ERROR(
"jaylink_get_devices() failed: %s", jaylink_strerror(ret));
566 LOG_ERROR(
"Multiple devices found, specify the desired device");
568 for (
size_t i = 0;
devs[i]; i++) {
570 ret = jaylink_device_get_serial_number(
devs[i], &
serial);
571 if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
573 }
else if (ret != JAYLINK_OK) {
574 LOG_WARNING(
"jaylink_device_get_serial_number() failed: %s",
575 jaylink_strerror(ret));
578 char name[JAYLINK_NICKNAME_MAX_LENGTH];
579 int name_ret = jaylink_device_get_nickname(
devs[i],
name);
580 if (name_ret == JAYLINK_OK)
586 jaylink_free_devices(
devs,
true);
591 *found_device =
false;
593 uint32_t serial_number;
594 ret = jaylink_parse_serial_number(adapter_serial, &serial_number);
595 if (ret != JAYLINK_OK)
598 for (
size_t i = 0;
devs[i]; i++) {
599 struct jaylink_device *dev =
devs[i];
601 if (adapter_serial) {
607 char nickname[JAYLINK_NICKNAME_MAX_LENGTH];
608 ret = jaylink_device_get_nickname(dev, nickname);
609 if (ret != JAYLINK_OK || strcmp(nickname, adapter_serial) != 0) {
614 ret = jaylink_device_get_serial_number(dev, &tmp);
615 if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
617 }
else if (ret != JAYLINK_OK) {
618 LOG_WARNING(
"jaylink_device_get_serial_number() failed: %s",
619 jaylink_strerror(ret));
623 if (serial_number != tmp)
629 enum jaylink_usb_address
address;
630 ret = jaylink_device_get_usb_address(dev, &
address);
632 if (ret == JAYLINK_ERR_NOT_SUPPORTED) {
634 }
else if (ret != JAYLINK_OK) {
635 LOG_WARNING(
"jaylink_device_get_usb_address() failed: %s",
636 jaylink_strerror(ret));
647 ret = jaylink_open(dev, &
devh);
649 if (ret == JAYLINK_OK) {
650 *found_device =
true;
654 LOG_ERROR(
"Failed to open device: %s", jaylink_strerror(ret));
657 jaylink_free_devices(
devs,
true);
665 char *firmware_version;
666 struct jaylink_hardware_version hwver;
667 struct jaylink_hardware_status hwstatus;
670 LOG_DEBUG(
"Using libjaylink %s (compiled with %s)",
671 jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING);
673 if (!jaylink_library_has_cap(JAYLINK_CAP_HIF_USB) &&
use_usb_address) {
674 LOG_ERROR(
"J-Link driver does not support USB devices");
678 ret = jaylink_init(&
jayctx);
680 if (ret != JAYLINK_OK) {
681 LOG_ERROR(
"jaylink_init() failed: %s", jaylink_strerror(ret));
687 if (ret != JAYLINK_OK) {
688 LOG_ERROR(
"jaylink_log_set_callback() failed: %s",
689 jaylink_strerror(ret));
719 ret = jaylink_get_firmware_version(
devh, &firmware_version, &
length);
721 if (ret != JAYLINK_OK) {
722 LOG_ERROR(
"jaylink_get_firmware_version() failed: %s",
723 jaylink_strerror(ret));
729 free(firmware_version);
731 LOG_WARNING(
"Device responds empty firmware version string");
734 memset(
caps, 0, JAYLINK_DEV_EXT_CAPS_SIZE);
737 if (ret != JAYLINK_OK) {
738 LOG_ERROR(
"jaylink_get_caps() failed: %s", jaylink_strerror(ret));
744 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_EXT_CAPS)) {
745 ret = jaylink_get_extended_caps(
devh,
caps);
747 if (ret != JAYLINK_OK) {
748 LOG_ERROR(
"jaylink_get_extended_caps() failed: %s",
749 jaylink_strerror(ret));
758 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_HW_VERSION)) {
759 ret = jaylink_get_hardware_version(
devh, &hwver);
761 if (ret != JAYLINK_OK) {
762 LOG_ERROR(
"Failed to retrieve hardware version: %s",
763 jaylink_strerror(ret));
769 LOG_INFO(
"Hardware version: %u.%02u", hwver.major, hwver.minor);
771 if (hwver.major >= 5)
775 if (
iface == JAYLINK_TIF_SWD) {
789 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
791 LOG_ERROR(
"Failed to read device configuration data");
800 ret = jaylink_get_hardware_status(
devh, &hwstatus);
802 if (ret != JAYLINK_OK) {
803 LOG_ERROR(
"jaylink_get_hardware_status() failed: %s",
804 jaylink_strerror(ret));
810 LOG_INFO(
"VTarget = %u.%03u V", hwstatus.target_voltage / 1000,
811 hwstatus.target_voltage % 1000);
815 strcpy(
conn.hid,
"0.0.0.0");
841 if (
iface == JAYLINK_TIF_JTAG) {
862 ret = jaylink_swo_stop(
devh);
864 if (ret != JAYLINK_OK)
865 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
868 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER)) {
871 if (ret != JAYLINK_OK)
872 LOG_ERROR(
"jaylink_unregister() failed: %s",
873 jaylink_strerror(ret));
899 uint8_t tms_scan_bits;
913 for (
unsigned int i = 0; i < num_states; i++) {
919 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
934 for (
unsigned int i = 0; i < num_cycles; i++)
960 LOG_DEBUG(
"TRST: %i, SRST: %i", trst, srst);
964 jaylink_set_reset(
devh);
967 jaylink_clear_reset(
devh);
970 jaylink_jtag_clear_trst(
devh);
973 jaylink_jtag_set_trst(
devh);
991 if (tmp > JAYLINK_USB_ADDRESS_3) {
1005 struct jaylink_hardware_status
status;
1007 ret = jaylink_get_hardware_status(
devh, &
status);
1009 if (ret != JAYLINK_OK) {
1011 jaylink_strerror(ret));
1016 status.target_voltage / 1000,
status.target_voltage % 1000);
1022 if (
status.target_voltage < 1500)
1033 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) {
1039 ret = jaylink_get_free_memory(
devh, &tmp);
1041 if (ret != JAYLINK_OK) {
1043 jaylink_strerror(ret));
1055 unsigned int version;
1058 case JAYLINK_JTAG_VERSION_2:
1061 case JAYLINK_JTAG_VERSION_3:
1096 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1104 int ret = jaylink_get_hardware_info(
devh, JAYLINK_HW_INFO_TARGET_POWER,
1107 if (ret != JAYLINK_OK) {
1119 int ret = jaylink_set_target_power(
devh, enable);
1121 if (ret != JAYLINK_OK) {
1123 jaylink_strerror(ret));
1173 "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]",
1185 const char *current_target_power;
1193 current_target_power =
"off";
1195 current_target_power =
"on";
1199 current_target_power);
1210 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER))
1213 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1228 if (ret != JAYLINK_OK) {
1229 LOG_ERROR(
"jaylink_swo_read() failed: %s", jaylink_strerror(ret));
1243 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
1246 ret = jaylink_get_free_memory(
devh, &tmp);
1248 if (ret != JAYLINK_OK) {
1249 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
1250 jaylink_strerror(ret));
1254 if (tmp > 0x3fff || tmp <= 0x600)
1259 return tmp & 0xffffff00;
1263 uint32_t trace_freq, uint16_t *prescaler)
1265 unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1270 unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1271 if (presc * trace_freq < traceclkin_freq - max_deviation ||
1272 presc * trace_freq > traceclkin_freq + max_deviation)
1281 unsigned int traceclkin_freq,
unsigned int *trace_freq,
1282 uint16_t *prescaler)
1288 for (divider = speed.min_div; divider <= speed.max_div; divider++) {
1289 *trace_freq = speed.freq / divider;
1295 deviation = fabs(1.0 - ((
double)*trace_freq * presc / traceclkin_freq));
1307 uint32_t port_size,
unsigned int *trace_freq,
1308 unsigned int traceclkin_freq, uint16_t *prescaler)
1312 struct jaylink_swo_speed speed;
1319 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SWO)) {
1323 LOG_ERROR(
"Trace capturing is not supported by the device");
1327 ret = jaylink_swo_stop(
devh);
1329 if (ret != JAYLINK_OK) {
1330 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
1346 LOG_ERROR(
"Selected pin protocol is not supported");
1353 LOG_ERROR(
"Not enough free device memory to start trace capturing");
1357 ret = jaylink_swo_get_speeds(
devh, JAYLINK_SWO_MODE_UART, &speed);
1359 if (ret != JAYLINK_OK) {
1360 LOG_ERROR(
"jaylink_swo_get_speeds() failed: %s",
1361 jaylink_strerror(ret));
1365 if (*trace_freq > 0) {
1366 divider = speed.freq / *trace_freq;
1367 min_freq = speed.freq / speed.max_div;
1368 max_freq = speed.freq / speed.min_div;
1370 if (*trace_freq > max_freq) {
1371 LOG_INFO(
"Given SWO frequency too high, using %" PRIu32
" Hz instead",
1373 *trace_freq = max_freq;
1374 }
else if (*trace_freq < min_freq) {
1375 LOG_INFO(
"Given SWO frequency too low, using %" PRIu32
" Hz instead",
1377 *trace_freq = min_freq;
1378 }
else if (*trace_freq != speed.freq / divider) {
1379 *trace_freq = speed.freq / divider;
1381 LOG_INFO(
"Given SWO frequency is not supported by the device, "
1382 "using %u Hz instead", *trace_freq);
1387 LOG_ERROR(
"SWO frequency is not suitable. Please choose a "
1388 "different frequency or use auto-detection");
1392 LOG_INFO(
"Trying to auto-detect SWO frequency");
1396 LOG_ERROR(
"Maximum permitted frequency deviation of %.02f %% "
1398 LOG_ERROR(
"Auto-detection of SWO frequency failed");
1402 LOG_INFO(
"Using SWO frequency of %u Hz", *trace_freq);
1405 ret = jaylink_swo_start(
devh, JAYLINK_SWO_MODE_UART, *trace_freq,
1408 if (ret != JAYLINK_OK) {
1409 LOG_ERROR(
"jaylink_start_swo() failed: %s", jaylink_strerror(ret));
1413 LOG_DEBUG(
"Using %" PRIu32
" bytes device memory for trace capturing",
1428 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1440 if (tmp > JAYLINK_USB_ADDRESS_3) {
1457 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1463 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1474 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1496 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1502 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1513 if ((strlen(str) != 17) || (str[2] !=
':' || str[5] !=
':' ||
1514 str[8] !=
':' || str[11] !=
':' || str[14] !=
':')) {
1519 for (i = 5; i >= 0; i--) {
1520 addr[i] = strtoul(str, &e, 16);
1529 if (!(0x01 &
addr[0])) {
1546 const char *s_save = s;
1552 for (i = 0; i < 4; i++) {
1553 lip[i] = strtoul(s, &e, 10);
1555 if (*e !=
'.' && i != 3)
1562 memcpy(ip, lip,
sizeof(lip));
1567 static void cpy_ip(uint8_t *dst, uint8_t *src)
1571 for (i = 0, j = 3; i < 4; i++, j--)
1580 uint8_t subnet_bits = 24;
1582 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1588 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1621 ((1ULL << subnet_bits) - 1) : 0xffffffff);
1632 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG))
1645 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1651 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) {
1659 "the configuration");
1663 ret = jaylink_write_raw_config(
devh, (
const uint8_t *)&
tmp_config);
1665 if (ret != JAYLINK_OK) {
1666 LOG_ERROR(
"jaylink_write_raw_config() failed: %s",
1667 jaylink_strerror(ret));
1672 LOG_ERROR(
"Failed to read device configuration for verification");
1677 LOG_ERROR(
"Verification of device configuration failed. Please check "
1684 "cycling the J-Link device");
1691 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1714 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1715 LOG_ERROR(
"Device does not support EMUCOM");
1724 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1728 buf = malloc(tmp / 2);
1737 if (
dummy != (tmp / 2)) {
1738 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1744 ret = jaylink_emucom_write(
devh, channel, buf, &
length);
1748 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1749 LOG_ERROR(
"Channel not supported by the device");
1751 }
else if (ret != JAYLINK_OK) {
1752 LOG_ERROR(
"Failed to write to channel: %s", jaylink_strerror(ret));
1773 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1774 LOG_ERROR(
"Device does not support EMUCOM");
1781 buf = malloc(
length * 3 + 1);
1788 ret = jaylink_emucom_read(
devh, channel, buf, &
length);
1790 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1791 LOG_ERROR(
"Channel is not supported by the device");
1794 }
else if (ret == JAYLINK_ERR_DEV_NOT_AVAILABLE) {
1795 LOG_ERROR(
"Channel is not available for the requested amount of data. "
1796 "%" PRIu32
" bytes are available",
length);
1799 }
else if (ret != JAYLINK_OK) {
1800 LOG_ERROR(
"Failed to read from channel: %s", jaylink_strerror(ret));
1808 LOG_ERROR(
"Failed to convert data into hexadecimal string");
1822 .handler = &jlink_handle_config_usb_address_command,
1824 .help =
"set the USB address",
1828 .name =
"targetpower",
1829 .handler = &jlink_handle_config_target_power_command,
1831 .help =
"set the target power supply",
1836 .handler = &jlink_handle_config_mac_address_command,
1838 .help =
"set the MAC Address",
1839 .usage =
"[ff:ff:ff:ff:ff:ff]",
1843 .handler = &jlink_handle_config_ip_address_command,
1845 .help =
"set the IP address, where A.B.C.D is the IP address, "
1846 "E the bit of the subnet mask, F.G.H.I the subnet mask",
1847 .usage =
"[A.B.C.D[/E] [F.G.H.I]]",
1851 .handler = &jlink_handle_config_reset_command,
1853 .help =
"undo configuration changes",
1858 .handler = &jlink_handle_config_write_command,
1860 .help =
"write configuration to the device",
1869 .handler = &jlink_handle_emucom_write_command,
1871 .help =
"write to a channel",
1872 .usage =
"<channel> <data>",
1876 .handler = &jlink_handle_emucom_read_command,
1878 .help =
"read from a channel",
1879 .usage =
"<channel> <length>"
1887 .handler = &jlink_handle_jlink_jtag_command,
1889 .help =
"select the JTAG command version",
1893 .name =
"targetpower",
1894 .handler = &jlink_handle_target_power_command,
1896 .help =
"set the target power supply",
1897 .usage =
"[0|1|on|off]"
1901 .handler = &jlink_handle_free_memory_command,
1903 .help =
"show free device memory",
1908 .handler = &jlink_handle_hwstatus_command,
1910 .help =
"show the hardware status",
1915 .handler = &jlink_usb_command,
1917 .help =
"set the USB address of the device that should be used",
1922 .handler = &jlink_handle_config_command,
1924 .help =
"access the device configuration. If no argument is given "
1925 "this will show the device configuration",
1932 .help =
"access EMUCOM channel",
1943 .help =
"perform jlink management",
1952 iface = JAYLINK_TIF_SWD;
1991 #define MAX_PENDING_SCAN_RESULTS 256
2005 const uint8_t *tms_out,
unsigned int tms_offset,
2006 uint8_t *in,
unsigned int in_offset,
2012 if (!available_length ||
2022 unsigned int scan_length =
length > available_length ?
2023 available_length :
length;
2039 out_offset += scan_length;
2040 tms_offset += scan_length;
2041 in_offset += scan_length;
2060 if (ret != JAYLINK_OK) {
2061 LOG_ERROR(
"jaylink_jtag_io() failed: %s", jaylink_strerror(ret));
2096 const uint32_t dir_out = 0xffffffff;
2109 const uint32_t dir_in = 0;
2157 LOG_ERROR(
"Sequence %d not supported", seq);
2186 if (ret != JAYLINK_OK) {
2187 LOG_ERROR(
"jaylink_swd_io() failed: %s", jaylink_strerror(ret));
2205 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
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
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.
static void bit_copy(uint8_t *dst, unsigned int dst_offset, const uint8_t *src, unsigned int src_offset, unsigned int bit_count)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int 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 int first, unsigned int 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 COMMAND_PARSE_ON_OFF(in, out)
parses an on/off command argument
#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
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t buffer_size
Size of dw_spi_program::buffer.
uint32_t address
Starting address. Sector aligned.
enum tap_state tap_get_end_state(void)
For more information,.
enum tap_state tap_state_transition(enum tap_state 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(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
int tap_get_tms_path_len(enum tap_state from, enum tap_state to)
Function int tap_get_tms_path_len returns the total number of bits that represents a TMS path transit...
void tap_set_end_state(enum tap_state new_end_state)
This function sets the state of an "end state follower" which tracks the state that any cable driver ...
enum tap_state tap_get_state(void)
This function gets the state of the "state follower" which tracks the state of the TAPs connected to ...
bool tap_is_state_stable(enum tap_state astate)
Function tap_is_state_stable returns true if the astate is stable.
int tap_get_tms_path(enum tap_state from, enum tap_state to)
This function provides a "bit sequence" indicating what has to be done with TMS during a sequence of ...
#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 enum tap_state jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned int tap_len, enum tap_state start_tap_state)
Prints verbose TAP state transitions for the given TMS/TDI buffers.
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 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_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 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 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 void jlink_end_state(enum tap_state state)
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_clock_data(const uint8_t *out, unsigned int out_offset, const uint8_t *tms_out, unsigned int tms_offset, uint8_t *in, unsigned int in_offset, unsigned int length)
Queue data to go out and in, flushing the queue as many times as necessary.
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 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 unsigned int tap_length
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 void jlink_path_move(unsigned int num_states, enum tap_state *path)
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_runtest(unsigned int num_cycles)
static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_clk)
static int pending_scan_results_length
static bool trace_enabled
static void jlink_stableclocks(unsigned int num_cycles)
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
#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 int 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.
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.
uint8_t swd_cmd
SWD command.
int first
First bit position in tdo_buffer to read.
void * buffer
Location to store the result.
int length
Number of bits to read.
uint8_t * buffer
Location to store the result.
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.
int(* init)(void)
Initialize the debug link so it can perform SWD operations.
static const unsigned int swd_seq_dormant_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 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 int swd_seq_jtag_to_swd_len
static const unsigned int swd_seq_line_reset_len
static const unsigned int swd_seq_dormant_to_jtag_len
static const unsigned int swd_seq_swd_to_dormant_len
static const uint8_t swd_seq_line_reset[]
SWD Line reset.
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 unsigned int swd_seq_swd_to_jtag_len
static const unsigned int swd_seq_jtag_to_dormant_len
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)