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 int tms_offset,
109 uint8_t *in,
unsigned int 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) {
167 if (
cmd->cmd.scan->ir_scan) {
182 unsigned int scan_size = 0;
184 for (
unsigned 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");
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));
581 jaylink_free_devices(
devs,
true);
586 *found_device =
false;
588 for (
size_t i = 0;
devs[i]; i++) {
589 struct jaylink_device *dev =
devs[i];
593 ret = jaylink_device_get_serial_number(dev, &tmp);
595 if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
597 }
else if (ret != JAYLINK_OK) {
598 LOG_WARNING(
"jaylink_device_get_serial_number() failed: %s",
599 jaylink_strerror(ret));
608 enum jaylink_usb_address address;
609 ret = jaylink_device_get_usb_address(dev, &address);
611 if (ret == JAYLINK_ERR_NOT_SUPPORTED) {
613 }
else if (ret != JAYLINK_OK) {
614 LOG_WARNING(
"jaylink_device_get_usb_address() failed: %s",
615 jaylink_strerror(ret));
626 ret = jaylink_open(dev, &
devh);
628 if (ret == JAYLINK_OK) {
629 *found_device =
true;
633 LOG_ERROR(
"Failed to open device: %s", jaylink_strerror(ret));
636 jaylink_free_devices(
devs,
true);
644 char *firmware_version;
645 struct jaylink_hardware_version hwver;
646 struct jaylink_hardware_status hwstatus;
649 LOG_DEBUG(
"Using libjaylink %s (compiled with %s)",
650 jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING);
652 if (!jaylink_library_has_cap(JAYLINK_CAP_HIF_USB) &&
use_usb_address) {
653 LOG_ERROR(
"J-Link driver does not support USB devices");
657 ret = jaylink_init(&
jayctx);
659 if (ret != JAYLINK_OK) {
660 LOG_ERROR(
"jaylink_init() failed: %s", jaylink_strerror(ret));
666 if (ret != JAYLINK_OK) {
667 LOG_ERROR(
"jaylink_log_set_callback() failed: %s",
668 jaylink_strerror(ret));
676 if (ret == JAYLINK_ERR) {
681 if (ret != JAYLINK_OK) {
682 LOG_ERROR(
"jaylink_parse_serial_number() failed: %s", jaylink_strerror(ret));
712 ret = jaylink_get_firmware_version(
devh, &firmware_version, &
length);
714 if (ret != JAYLINK_OK) {
715 LOG_ERROR(
"jaylink_get_firmware_version() failed: %s",
716 jaylink_strerror(ret));
722 free(firmware_version);
724 LOG_WARNING(
"Device responds empty firmware version string");
727 memset(
caps, 0, JAYLINK_DEV_EXT_CAPS_SIZE);
730 if (ret != JAYLINK_OK) {
731 LOG_ERROR(
"jaylink_get_caps() failed: %s", jaylink_strerror(ret));
737 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_EXT_CAPS)) {
738 ret = jaylink_get_extended_caps(
devh,
caps);
740 if (ret != JAYLINK_OK) {
741 LOG_ERROR(
"jaylink_get_extended_caps() failed: %s",
742 jaylink_strerror(ret));
751 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_HW_VERSION)) {
752 ret = jaylink_get_hardware_version(
devh, &hwver);
754 if (ret != JAYLINK_OK) {
755 LOG_ERROR(
"Failed to retrieve hardware version: %s",
756 jaylink_strerror(ret));
762 LOG_INFO(
"Hardware version: %u.%02u", hwver.major, hwver.minor);
764 if (hwver.major >= 5)
768 if (
iface == JAYLINK_TIF_SWD) {
782 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
784 LOG_ERROR(
"Failed to read device configuration data");
793 ret = jaylink_get_hardware_status(
devh, &hwstatus);
795 if (ret != JAYLINK_OK) {
796 LOG_ERROR(
"jaylink_get_hardware_status() failed: %s",
797 jaylink_strerror(ret));
803 LOG_INFO(
"VTarget = %u.%03u V", hwstatus.target_voltage / 1000,
804 hwstatus.target_voltage % 1000);
808 strcpy(
conn.hid,
"0.0.0.0");
834 if (
iface == JAYLINK_TIF_JTAG) {
855 ret = jaylink_swo_stop(
devh);
857 if (ret != JAYLINK_OK)
858 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
861 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_REGISTER)) {
864 if (ret != JAYLINK_OK)
865 LOG_ERROR(
"jaylink_unregister() failed: %s",
866 jaylink_strerror(ret));
892 uint8_t tms_scan_bits;
906 for (
unsigned int i = 0; i < num_states; i++) {
912 LOG_ERROR(
"BUG: %s -> %s isn't a valid TAP transition",
927 for (
unsigned int i = 0; i < num_cycles; i++)
953 LOG_DEBUG(
"TRST: %i, SRST: %i", trst, srst);
957 jaylink_set_reset(
devh);
960 jaylink_clear_reset(
devh);
963 jaylink_jtag_clear_trst(
devh);
966 jaylink_jtag_set_trst(
devh);
984 if (tmp > JAYLINK_USB_ADDRESS_3) {
998 struct jaylink_hardware_status
status;
1000 ret = jaylink_get_hardware_status(
devh, &
status);
1002 if (ret != JAYLINK_OK) {
1004 jaylink_strerror(ret));
1009 status.target_voltage / 1000,
status.target_voltage % 1000);
1015 if (
status.target_voltage < 1500)
1026 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) {
1032 ret = jaylink_get_free_memory(
devh, &tmp);
1034 if (ret != JAYLINK_OK) {
1036 jaylink_strerror(ret));
1048 unsigned int version;
1051 case JAYLINK_JTAG_VERSION_2:
1054 case JAYLINK_JTAG_VERSION_3:
1089 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1097 int ret = jaylink_get_hardware_info(
devh, JAYLINK_HW_INFO_TARGET_POWER,
1100 if (ret != JAYLINK_OK) {
1112 int ret = jaylink_set_target_power(
devh, enable);
1114 if (ret != JAYLINK_OK) {
1116 jaylink_strerror(ret));
1166 "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]",
1178 const char *current_target_power;
1186 current_target_power =
"off";
1188 current_target_power =
"on";
1192 current_target_power);
1203 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER))
1206 if (jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1221 if (ret != JAYLINK_OK) {
1222 LOG_ERROR(
"jaylink_swo_read() failed: %s", jaylink_strerror(ret));
1236 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY))
1239 ret = jaylink_get_free_memory(
devh, &tmp);
1241 if (ret != JAYLINK_OK) {
1242 LOG_ERROR(
"jaylink_get_free_memory() failed: %s",
1243 jaylink_strerror(ret));
1247 if (tmp > 0x3fff || tmp <= 0x600)
1252 return tmp & 0xffffff00;
1256 uint32_t trace_freq, uint16_t *prescaler)
1258 unsigned int presc = (traceclkin_freq + trace_freq / 2) / trace_freq;
1263 unsigned int max_deviation = (traceclkin_freq * 3) / 100;
1264 if (presc * trace_freq < traceclkin_freq - max_deviation ||
1265 presc * trace_freq > traceclkin_freq + max_deviation)
1274 unsigned int traceclkin_freq,
unsigned int *trace_freq,
1275 uint16_t *prescaler)
1281 for (divider = speed.min_div; divider <= speed.max_div; divider++) {
1282 *trace_freq = speed.freq / divider;
1288 deviation = fabs(1.0 - ((
double)*trace_freq * presc / traceclkin_freq));
1300 uint32_t port_size,
unsigned int *trace_freq,
1301 unsigned int traceclkin_freq, uint16_t *prescaler)
1304 uint32_t buffer_size;
1305 struct jaylink_swo_speed speed;
1312 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SWO)) {
1316 LOG_ERROR(
"Trace capturing is not supported by the device");
1320 ret = jaylink_swo_stop(
devh);
1322 if (ret != JAYLINK_OK) {
1323 LOG_ERROR(
"jaylink_swo_stop() failed: %s", jaylink_strerror(ret));
1339 LOG_ERROR(
"Selected pin protocol is not supported");
1346 LOG_ERROR(
"Not enough free device memory to start trace capturing");
1350 ret = jaylink_swo_get_speeds(
devh, JAYLINK_SWO_MODE_UART, &speed);
1352 if (ret != JAYLINK_OK) {
1353 LOG_ERROR(
"jaylink_swo_get_speeds() failed: %s",
1354 jaylink_strerror(ret));
1358 if (*trace_freq > 0) {
1359 divider = speed.freq / *trace_freq;
1360 min_freq = speed.freq / speed.max_div;
1361 max_freq = speed.freq / speed.min_div;
1363 if (*trace_freq > max_freq) {
1364 LOG_INFO(
"Given SWO frequency too high, using %" PRIu32
" Hz instead",
1366 *trace_freq = max_freq;
1367 }
else if (*trace_freq < min_freq) {
1368 LOG_INFO(
"Given SWO frequency too low, using %" PRIu32
" Hz instead",
1370 *trace_freq = min_freq;
1371 }
else if (*trace_freq != speed.freq / divider) {
1372 *trace_freq = speed.freq / divider;
1374 LOG_INFO(
"Given SWO frequency is not supported by the device, "
1375 "using %u Hz instead", *trace_freq);
1380 LOG_ERROR(
"SWO frequency is not suitable. Please choose a "
1381 "different frequency or use auto-detection");
1385 LOG_INFO(
"Trying to auto-detect SWO frequency");
1389 LOG_ERROR(
"Maximum permitted frequency deviation of %.02f %% "
1391 LOG_ERROR(
"Auto-detection of SWO frequency failed");
1395 LOG_INFO(
"Using SWO frequency of %u Hz", *trace_freq);
1398 ret = jaylink_swo_start(
devh, JAYLINK_SWO_MODE_UART, *trace_freq,
1401 if (ret != JAYLINK_OK) {
1402 LOG_ERROR(
"jaylink_start_swo() failed: %s", jaylink_strerror(ret));
1406 LOG_DEBUG(
"Using %" PRIu32
" bytes device memory for trace capturing",
1421 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1433 if (tmp > JAYLINK_USB_ADDRESS_3) {
1450 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1456 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) {
1467 }
else if (!strcmp(
CMD_ARGV[0],
"off")) {
1489 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1495 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1506 if ((strlen(str) != 17) || (str[2] !=
':' || str[5] !=
':' ||
1507 str[8] !=
':' || str[11] !=
':' || str[14] !=
':')) {
1512 for (i = 5; i >= 0; i--) {
1513 addr[i] = strtoul(str, &e, 16);
1522 if (!(0x01 &
addr[0])) {
1539 const char *s_save = s;
1545 for (i = 0; i < 4; i++) {
1546 lip[i] = strtoul(s, &e, 10);
1548 if (*e !=
'.' && i != 3)
1555 memcpy(ip, lip,
sizeof(lip));
1560 static void cpy_ip(uint8_t *dst, uint8_t *src)
1564 for (i = 0, j = 3; i < 4; i++, j--)
1573 uint8_t subnet_bits = 24;
1575 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1581 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_ETHERNET)) {
1614 ((1ULL << subnet_bits) - 1) : 0xffffffff);
1625 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG))
1638 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1644 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) {
1652 "the configuration");
1656 ret = jaylink_write_raw_config(
devh, (
const uint8_t *)&
tmp_config);
1658 if (ret != JAYLINK_OK) {
1659 LOG_ERROR(
"jaylink_write_raw_config() failed: %s",
1660 jaylink_strerror(ret));
1665 LOG_ERROR(
"Failed to read device configuration for verification");
1670 LOG_ERROR(
"Verification of device configuration failed. Please check "
1677 "cycling the J-Link device");
1684 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_READ_CONFIG)) {
1707 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1708 LOG_ERROR(
"Device does not support EMUCOM");
1717 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1721 buf = malloc(tmp / 2);
1730 if (
dummy != (tmp / 2)) {
1731 LOG_ERROR(
"Data must be encoded as hexadecimal pairs");
1737 ret = jaylink_emucom_write(
devh, channel, buf, &
length);
1741 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1742 LOG_ERROR(
"Channel not supported by the device");
1744 }
else if (ret != JAYLINK_OK) {
1745 LOG_ERROR(
"Failed to write to channel: %s", jaylink_strerror(ret));
1766 if (!jaylink_has_cap(
caps, JAYLINK_DEV_CAP_EMUCOM)) {
1767 LOG_ERROR(
"Device does not support EMUCOM");
1774 buf = malloc(
length * 3 + 1);
1781 ret = jaylink_emucom_read(
devh, channel, buf, &
length);
1783 if (ret == JAYLINK_ERR_DEV_NOT_SUPPORTED) {
1784 LOG_ERROR(
"Channel is not supported by the device");
1787 }
else if (ret == JAYLINK_ERR_DEV_NOT_AVAILABLE) {
1788 LOG_ERROR(
"Channel is not available for the requested amount of data. "
1789 "%" PRIu32
" bytes are available",
length);
1792 }
else if (ret != JAYLINK_OK) {
1793 LOG_ERROR(
"Failed to read from channel: %s", jaylink_strerror(ret));
1801 LOG_ERROR(
"Failed to convert data into hexadecimal string");
1815 .handler = &jlink_handle_config_usb_address_command,
1817 .help =
"set the USB address",
1821 .name =
"targetpower",
1822 .handler = &jlink_handle_config_target_power_command,
1824 .help =
"set the target power supply",
1829 .handler = &jlink_handle_config_mac_address_command,
1831 .help =
"set the MAC Address",
1832 .usage =
"[ff:ff:ff:ff:ff:ff]",
1836 .handler = &jlink_handle_config_ip_address_command,
1838 .help =
"set the IP address, where A.B.C.D is the IP address, "
1839 "E the bit of the subnet mask, F.G.H.I the subnet mask",
1840 .usage =
"[A.B.C.D[/E] [F.G.H.I]]",
1844 .handler = &jlink_handle_config_reset_command,
1846 .help =
"undo configuration changes",
1851 .handler = &jlink_handle_config_write_command,
1853 .help =
"write configuration to the device",
1862 .handler = &jlink_handle_emucom_write_command,
1864 .help =
"write to a channel",
1865 .usage =
"<channel> <data>",
1869 .handler = &jlink_handle_emucom_read_command,
1871 .help =
"read from a channel",
1872 .usage =
"<channel> <length>"
1880 .handler = &jlink_handle_jlink_jtag_command,
1882 .help =
"select the JTAG command version",
1886 .name =
"targetpower",
1887 .handler = &jlink_handle_target_power_command,
1889 .help =
"set the target power supply",
1890 .usage =
"[0|1|on|off]"
1894 .handler = &jlink_handle_free_memory_command,
1896 .help =
"show free device memory",
1901 .handler = &jlink_handle_hwstatus_command,
1903 .help =
"show the hardware status",
1908 .handler = &jlink_usb_command,
1910 .help =
"set the USB address of the device that should be used",
1915 .handler = &jlink_handle_config_command,
1917 .help =
"access the device configuration. If no argument is given "
1918 "this will show the device configuration",
1925 .help =
"access EMUCOM channel",
1936 .help =
"perform jlink management",
1945 iface = JAYLINK_TIF_SWD;
1984 #define MAX_PENDING_SCAN_RESULTS 256
1998 const uint8_t *tms_out,
unsigned int tms_offset,
1999 uint8_t *in,
unsigned int in_offset,
2005 if (!available_length ||
2015 unsigned int scan_length =
length > available_length ?
2016 available_length :
length;
2032 out_offset += scan_length;
2033 tms_offset += scan_length;
2034 in_offset += scan_length;
2053 if (ret != JAYLINK_OK) {
2054 LOG_ERROR(
"jaylink_jtag_io() failed: %s", jaylink_strerror(ret));
2089 const uint32_t dir_out = 0xffffffff;
2102 const uint32_t dir_in = 0;
2150 LOG_ERROR(
"Sequence %d not supported", seq);
2179 if (ret != JAYLINK_OK) {
2180 LOG_ERROR(
"jaylink_swd_io() failed: %s", jaylink_strerror(ret));
2198 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
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 ...
#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 tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned int tap_len, tap_state_t 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_path_move(unsigned int num_states, tap_state_t *path)
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_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 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_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 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 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 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
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 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.
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.
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)