From 80ddafc2f883f7e8a6452507e4c7afbfbd93883c Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Mon, 19 Oct 2020 13:13:43 +0200 Subject: [PATCH] Jtag/High Level : Transfer dp->dp_jd_index with every HL command. - Add REMOTE_HL_VERSION, now at 1. Fall back to hosted/low-level when wrong version is found and give hint to user. --- src/platforms/hosted/bmp_remote.c | 26 ++++++++------------------ src/remote.c | 17 ++++++----------- src/remote.h | 22 ++++++++++------------ 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/src/platforms/hosted/bmp_remote.c b/src/platforms/hosted/bmp_remote.c index e42ac54b..12387151 100644 --- a/src/platforms/hosted/bmp_remote.c +++ b/src/platforms/hosted/bmp_remote.c @@ -153,7 +153,7 @@ static uint32_t remote_adiv5_dp_read(ADIv5_DP_t *dp, uint16_t addr) (void)dp; uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_DP_READ_STR, - addr); + dp->dp_jd_index, addr); platform_buffer_write(construct, s); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { @@ -171,7 +171,7 @@ static uint32_t remote_adiv5_low_access( (void)dp; uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, - REMOTE_LOW_ACCESS_STR, RnW, addr, value); + REMOTE_LOW_ACCESS_STR, dp->dp_jd_index, RnW, addr, value); platform_buffer_write(construct, s); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { @@ -186,7 +186,7 @@ static uint32_t remote_adiv5_ap_read(ADIv5_AP_t *ap, uint16_t addr) { uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_READ_STR, - ap->apsel, addr); + ap->dp->dp_jd_index, ap->apsel, addr); platform_buffer_write(construct, s); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { @@ -201,7 +201,7 @@ static void remote_adiv5_ap_write(ADIv5_AP_t *ap, uint16_t addr, uint32_t value) { uint8_t construct[REMOTE_MAX_MSG_SIZE]; int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,REMOTE_AP_WRITE_STR, - ap->apsel, addr, value); + ap->dp->dp_jd_index, ap->apsel, addr, value); platform_buffer_write(construct, s); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { @@ -267,7 +267,7 @@ static void remote_ap_mem_read( if (count > batchsize) count = batchsize; s = snprintf(construct, REMOTE_MAX_MSG_SIZE, - REMOTE_AP_MEM_READ_STR, ap->apsel, ap->csw, src, count); + REMOTE_AP_MEM_READ_STR, ap->dp->dp_jd_index, ap->apsel, ap->csw, src, count); platform_buffer_write((uint8_t*)construct, s); s = platform_buffer_read((uint8_t*)construct, REMOTE_MAX_MSG_SIZE); if ((s > 0) && (construct[0] == REMOTE_RESP_OK)) { @@ -307,7 +307,7 @@ static void remote_ap_mem_write_sized( count = batchsize; int s = snprintf(construct, REMOTE_MAX_MSG_SIZE, REMOTE_AP_MEM_WRITE_SIZED_STR, - ap->apsel, ap->csw, align, dest, count); + ap->dp->dp_jd_index, ap->apsel, ap->csw, align, dest, count); char *p = construct + s; hexify(p, src, count); p += 2 * count; @@ -340,22 +340,12 @@ void remote_adiv5_dp_defaults(ADIv5_DP_t *dp) REMOTE_HL_CHECK_STR); platform_buffer_write(construct, s); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); - if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { + if ((!s) || (construct[0] == REMOTE_RESP_ERR) || + ((construct[1] - '0') < REMOTE_HL_VERSION)) { DEBUG_WARN( "Please update BMP firmware for substantial speed increase!\n"); return; } - if (dp->dp_jd_index < JTAG_MAX_DEVS) { - s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_HL_JTAG_DEV_STR, - dp->dp_jd_index); - platform_buffer_write(construct, s); - s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); - if ((!s) || (construct[0] != REMOTE_RESP_OK)) { - DEBUG_WARN( - "Please update BMP firmware to allow high level jtag commands!\n"); - return; - } - } dp->low_access = remote_adiv5_low_access; dp->dp_read = remote_adiv5_dp_read; dp->ap_write = remote_adiv5_ap_write; diff --git a/src/remote.c b/src/remote.c index 3e0a70e1..445d18ec 100644 --- a/src/remote.c +++ b/src/remote.c @@ -322,21 +322,16 @@ void remotePacketProcessHL(uint8_t i, char *packet) /* Re-use packet buffer. Align to DWORD! */ void *src = (void *)(((uint32_t)packet + 7) & ~7); char index = packet[1]; + if (index == REMOTE_HL_CHECK) { + _respond(REMOTE_RESP_OK, REMOTE_HL_VERSION); + return; + } + packet += 2; + remote_dp.dp_jd_index = remotehston(2, packet); packet += 2; remote_ap.apsel = remotehston(2, packet); remote_ap.dp = &remote_dp; switch (index) { - case REMOTE_HL_CHECK: /* HC = Check availability of HL commands*/ - _respond(REMOTE_RESP_OK, 0); - break; - case REMOTE_HL_JTAG_DEV: /* HJ for jtag device to use */ - if (i < 4) { - _respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN); - } else { - remote_dp.dp_jd_index = remotehston(2, packet); - _respond(REMOTE_RESP_OK, 0); - } - break; case REMOTE_DP_READ: /* Hd = Read from DP register */ packet += 2; uint16_t addr16 = remotehston(4, packet); diff --git a/src/remote.h b/src/remote.h index 3cfd1b0a..94eee009 100644 --- a/src/remote.h +++ b/src/remote.h @@ -24,6 +24,8 @@ #include #include "general.h" +#define REMOTE_HL_VERSION 1 + /* * Commands to remote end, and responses * ===================================== @@ -86,7 +88,6 @@ /* High level protocol elements */ #define REMOTE_HL_CHECK 'C' -#define REMOTE_HL_JTAG_DEV 'J' #define REMOTE_HL_PACKET 'H' #define REMOTE_DP_READ 'd' #define REMOTE_LOW_ACCESS 'L' @@ -156,24 +157,21 @@ REMOTE_EOM, 0} #define REMOTE_HL_CHECK_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_HL_CHECK, REMOTE_EOM, 0 } -#define REMOTE_HL_JTAG_DEV_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, \ - REMOTE_HL_JTAG_DEV, '%', '0', '2', 'x', REMOTE_EOM, 0 } -#define REMOTE_MEM_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_MEM_READ, \ - HEX_U32(address), HEX_U32(count), REMOTE_EOM, 0 } #define REMOTE_DP_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_DP_READ, \ - 'f', 'f', '%', '0', '4', 'x', REMOTE_EOM, 0 } + '%','0', '2', 'x', 'f', 'f', '%', '0', '4', 'x', REMOTE_EOM, 0 } #define REMOTE_LOW_ACCESS_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_LOW_ACCESS, \ - '%','0', '2', 'x', '%', '0', '4', 'x', HEX_U32(csw), REMOTE_EOM, 0 } + '%','0', '2', 'x', '%','0', '2', 'x', '%', '0', '4', 'x', HEX_U32(csw), REMOTE_EOM, 0 } #define REMOTE_AP_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_AP_READ, \ - '%','0','2','x', '%', '0', '4', 'x', REMOTE_EOM, 0 } + '%','0', '2', 'x', '%','0','2','x', '%', '0', '4', 'x', REMOTE_EOM, 0 } #define REMOTE_AP_WRITE_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_AP_WRITE, \ - '%','0','2','x', '%', '0', '4', 'x', HEX_U32(csw), REMOTE_EOM, 0 } + '%','0', '2', 'x', '%','0','2','x', '%', '0', '4', 'x', HEX_U32(csw), REMOTE_EOM, 0 } #define REMOTE_AP_MEM_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_AP_MEM_READ, \ - '%','0','2','x',HEX_U32(csw), HEX_U32(address), HEX_U32(count), REMOTE_EOM, 0 } + '%','0', '2', 'x', '%','0','2','x',HEX_U32(csw), HEX_U32(address), HEX_U32(count), \ + REMOTE_EOM, 0 } #define REMOTE_AP_MEM_WRITE_SIZED_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_AP_MEM_WRITE_SIZED, \ - '%', '0', '2', 'x', HEX_U32(csw), '%', '0', '2', 'x', HEX_U32(address), HEX_U32(count), 0} + '%','0', '2', 'x', '%', '0', '2', 'x', HEX_U32(csw), '%', '0', '2', 'x', HEX_U32(address), HEX_U32(count), 0} #define REMOTE_MEM_WRITE_SIZED_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_AP_MEM_WRITE_SIZED, \ - '%','0','2','x', HEX_U32(address), HEX_U32(count), 0} + '%','0', '2', 'x', '%','0','2','x', HEX_U32(address), HEX_U32(count), 0} uint64_t remotehston(uint32_t limit, char *s); void remotePacketProcess(uint8_t i, char *packet);