From 9af2a48e0e270b1a7d94e67e5acd3a5259b2647e Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 25 Sep 2023 16:30:23 +0100 Subject: [PATCH 1/3] remote: Fixed the SWD remote protocol implementation miss-initialising its static faked DP --- src/remote.c | 2 ++ src/target/adiv5.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/remote.c b/src/remote.c index ba85bb0a3f4..5a69544066e 100644 --- a/src/remote.c +++ b/src/remote.c @@ -135,7 +135,9 @@ static void remote_packet_process_swd(const char *const packet, const size_t pac switch (packet[1]) { case REMOTE_INIT: /* SS = initialise =============================== */ if (packet_len == 2) { + remote_dp.dp_low_write = firmware_dp_low_write; remote_dp.dp_read = firmware_swdp_read; + remote_dp.error = firmware_swdp_error; remote_dp.low_access = firmware_swdp_low_access; remote_dp.abort = firmware_swdp_abort; swdptap_init(); diff --git a/src/target/adiv5.h b/src/target/adiv5.h index 098c7719b78..cb6b86f1284 100644 --- a/src/target/adiv5.h +++ b/src/target/adiv5.h @@ -387,6 +387,7 @@ uint32_t fw_adiv5_jtagdp_low_access(adiv5_debug_port_s *dp, uint8_t RnW, uint16_ uint32_t firmware_swdp_read(adiv5_debug_port_s *dp, uint16_t addr); uint32_t fw_adiv5_jtagdp_read(adiv5_debug_port_s *dp, uint16_t addr); +bool firmware_dp_low_write(uint16_t addr, uint32_t data); uint32_t firmware_swdp_error(adiv5_debug_port_s *dp, bool protocol_recovery); void firmware_swdp_abort(adiv5_debug_port_s *dp, uint32_t abort); From b0c078e2f22f8026f7001598910c2ae036ac350a Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 25 Sep 2023 16:51:53 +0100 Subject: [PATCH 2/3] remote: Fixed the JTAG remote protocol implementation miss-initialising its static faked DP --- src/remote.c | 2 ++ src/target/adiv5.h | 1 + src/target/adiv5_jtag.c | 4 +--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/remote.c b/src/remote.c index 5a69544066e..bdff27b720f 100644 --- a/src/remote.c +++ b/src/remote.c @@ -187,7 +187,9 @@ static void remote_packet_process_jtag(const char *const packet, const size_t pa { switch (packet[1]) { case REMOTE_INIT: /* JS = initialise ============================= */ + remote_dp.dp_low_write = NULL; remote_dp.dp_read = fw_adiv5_jtagdp_read; + remote_dp.error = adiv5_jtagdp_error; remote_dp.low_access = fw_adiv5_jtagdp_low_access; remote_dp.abort = adiv5_jtagdp_abort; jtagtap_init(); diff --git a/src/target/adiv5.h b/src/target/adiv5.h index cb6b86f1284..ed9ddb1025f 100644 --- a/src/target/adiv5.h +++ b/src/target/adiv5.h @@ -389,6 +389,7 @@ uint32_t fw_adiv5_jtagdp_read(adiv5_debug_port_s *dp, uint16_t addr); bool firmware_dp_low_write(uint16_t addr, uint32_t data); uint32_t firmware_swdp_error(adiv5_debug_port_s *dp, bool protocol_recovery); +uint32_t adiv5_jtagdp_error(adiv5_debug_port_s *dp, bool protocol_recovery); void firmware_swdp_abort(adiv5_debug_port_s *dp, uint32_t abort); void adiv5_jtagdp_abort(adiv5_debug_port_s *dp, uint32_t abort); diff --git a/src/target/adiv5_jtag.c b/src/target/adiv5_jtag.c index 98fb89aa89c..3caea165e58 100644 --- a/src/target/adiv5_jtag.c +++ b/src/target/adiv5_jtag.c @@ -37,8 +37,6 @@ #define IR_DPACC 0xaU #define IR_APACC 0xbU -static uint32_t adiv5_jtagdp_error(adiv5_debug_port_s *dp, bool protocol_recovery); - void adiv5_jtag_dp_handler(const uint8_t dev_index) { adiv5_debug_port_s *dp = calloc(1, sizeof(*dp)); @@ -89,7 +87,7 @@ uint32_t fw_adiv5_jtagdp_read(adiv5_debug_port_s *dp, uint16_t addr) return fw_adiv5_jtagdp_low_access(dp, ADIV5_LOW_READ, ADIV5_DP_RDBUFF, 0); } -static uint32_t adiv5_jtagdp_error(adiv5_debug_port_s *dp, const bool protocol_recovery) +uint32_t adiv5_jtagdp_error(adiv5_debug_port_s *dp, const bool protocol_recovery) { (void)protocol_recovery; const uint32_t status = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) & ADIV5_DP_CTRLSTAT_ERRMASK; From 3b83c3bedb7752676a53f1fab87a7b3199c4df2d Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 25 Sep 2023 17:04:16 +0100 Subject: [PATCH 3/3] remote: Added some documentation on the remote_dp structure and its purpose --- src/remote.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/remote.c b/src/remote.c index bdff27b720f..de56efbc48d 100644 --- a/src/remote.c +++ b/src/remote.c @@ -123,6 +123,15 @@ static void remote_respond_string(const char response_code, const char *const st gdb_if_putchar(REMOTE_EOM, 1); } +/* + * This faked ADIv5 DP structure holds the currently used low-level implementation functions (SWD vs JTAG) + * and basic DP state for remote protocol requests made. This is shared between remote_packet_process_swd() + * and remote_packet_process_jtag() for use by remote_packet_process_adiv5() so its faked AP can do the right + * thing. + * + * REMOTE_INIT for SWD and JTAG rewrite the dp_low_write, dp_read, error, low_access and abort function + * pointers to reconfigure this structure appropriately. + */ static adiv5_debug_port_s remote_dp = { .ap_read = firmware_ap_read, .ap_write = firmware_ap_write,