From: OpenOCD-Gerrit <ope...@us...> - 2022-08-27 16:15:22
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 65de7c95f41e78746dc41e6173bbee4106a758f9 (commit) via 1a9d9916193ee7884d942b6119163557edc8dad2 (commit) from 66d6f9a1e7c977faed71cf7fef977124a5edee7e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 65de7c95f41e78746dc41e6173bbee4106a758f9 Author: Tomas Vanek <va...@fb...> Date: Tue Aug 2 09:16:21 2022 +0200 jtag/drivers/kitprog: workaround serious firmware problem Since commit 88f429ead019fd6df96ec15f0d897385f3cef0d0 5321: target/cortex_m: faster reading of all CPU registers debugging with a kitprog adapter freezes at debug entry. How to replicate: openocd -f interface/kitprog.cfg -f target/psoc4.cfg Connect to telnet server. Make sure the target is running: resume Halt the target: halt Without this patch OpenOCD freezes in kitprog_hid_command() in library call hid_write(). Reduce the number of SWD transactions sent in one USB bulk write as a workaround, simply use shorter buffer. For details see the comment in src/jtag/drivers/kitprog.c Change-Id: I0116894d5ebf1655f6011f0d35acdbbc178cd48c Signed-off-by: Tomas Vanek <va...@fb...> Reviewed-on: https://review.openocd.org/c/openocd/+/7107 Tested-by: jenkins Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/src/jtag/drivers/kitprog.c b/src/jtag/drivers/kitprog.c index 7122d5757..f800b7b92 100644 --- a/src/jtag/drivers/kitprog.c +++ b/src/jtag/drivers/kitprog.c @@ -79,8 +79,24 @@ #define HID_COMMAND_CONFIGURE 0x8f #define HID_COMMAND_BOOTLOADER 0xa0 -/* 512 bytes seems to work reliably */ -#define SWD_MAX_BUFFER_LENGTH 512 +/* 512 bytes seemed to work reliably. + * It works with both full queue of mostly reads or mostly writes. + * + * Unfortunately the commit 88f429ead019fd6df96ec15f0d897385f3cef0d0 + * 5321: target/cortex_m: faster reading of all CPU registers + * revealed a serious Kitprog firmware problem: + * If the queue contains more than 63 transactions in the repeated pattern + * one write, two reads, the firmware fails badly. + * Sending 64 transactions makes the adapter to loose the connection with the + * device. Sending 65 or more transactions causes the adapter to stop + * receiving USB HID commands, next kitprog_hid_command() stops in hid_write(). + * + * The problem was detected with KitProg v2.12 and v2.16. + * We can guess the problem is something like a buffer or stack overflow. + * + * Use shorter buffer as a workaround. 300 bytes (= 60 transactions) works. + */ +#define SWD_MAX_BUFFER_LENGTH 300 struct kitprog { hid_device *hid_handle; commit 1a9d9916193ee7884d942b6119163557edc8dad2 Author: Tomas Vanek <va...@fb...> Date: Mon Aug 1 23:16:47 2022 +0200 jtag/drivers/kitprog: use HID read timeout Use hid_read_timeout() instead of hid_read(). Improve error messages. Change-Id: Ia75b4fcd610442ab926bc454341f928d59843fcf Signed-off-by: Tomas Vanek <va...@fb...> Reviewed-on: https://review.openocd.org/c/openocd/+/7106 Tested-by: jenkins Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/src/jtag/drivers/kitprog.c b/src/jtag/drivers/kitprog.c index 0956d3aa6..7122d5757 100644 --- a/src/jtag/drivers/kitprog.c +++ b/src/jtag/drivers/kitprog.c @@ -321,9 +321,13 @@ static int kitprog_hid_command(uint8_t *command, size_t command_length, return ERROR_FAIL; } - ret = hid_read(kitprog_handle->hid_handle, data, data_length); - if (ret < 0) { - LOG_DEBUG("HID read returned %i", ret); + ret = hid_read_timeout(kitprog_handle->hid_handle, + data, data_length, LIBUSB_TIMEOUT_MS); + if (ret == 0) { + LOG_ERROR("HID read timed out"); + return ERROR_TIMEOUT_REACHED; + } else if (ret < 0) { + LOG_ERROR("HID read error %ls", hid_error(kitprog_handle->hid_handle)); return ERROR_FAIL; } ----------------------------------------------------------------------- Summary of changes: src/jtag/drivers/kitprog.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) hooks/post-receive -- Main OpenOCD repository |