hosted/jtag: Transfer jtag_devs to firmware.

This commit is contained in:
Uwe Bonnes 2020-10-09 17:42:11 +02:00
parent 3d92b82678
commit 8b929c12c9
9 changed files with 93 additions and 8 deletions

View File

@ -45,6 +45,5 @@ bool platform_srst_get_val(void);
bool platform_target_get_power(void); bool platform_target_get_power(void);
void platform_target_set_power(bool power); void platform_target_set_power(bool power);
void platform_request_boot(void); void platform_request_boot(void);
#endif #endif

View File

@ -336,8 +336,7 @@ static void remote_ap_mem_write_sized(
void remote_adiv5_dp_defaults(ADIv5_DP_t *dp) void remote_adiv5_dp_defaults(ADIv5_DP_t *dp)
{ {
uint8_t construct[REMOTE_MAX_MSG_SIZE]; uint8_t construct[REMOTE_MAX_MSG_SIZE];
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s", int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, REMOTE_HL_CHECK_STR);
REMOTE_HL_CHECK_STR);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { if ((!s) || (construct[0] == REMOTE_RESP_ERR)) {
@ -346,9 +345,16 @@ void remote_adiv5_dp_defaults(ADIv5_DP_t *dp)
return; return;
} }
if (dp->dp_jd_index < JTAG_MAX_DEVS) { if (dp->dp_jd_index < JTAG_MAX_DEVS) {
DEBUG_WARN("Falling back to ll as high level JTAG is not yet possible!\n"); 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; return;
} }
}
dp->low_access = remote_adiv5_low_access; dp->low_access = remote_adiv5_low_access;
dp->dp_read = remote_adiv5_dp_read; dp->dp_read = remote_adiv5_dp_read;
dp->ap_write = remote_adiv5_ap_write; dp->ap_write = remote_adiv5_ap_write;
@ -356,3 +362,20 @@ void remote_adiv5_dp_defaults(ADIv5_DP_t *dp)
dp->mem_read = remote_ap_mem_read; dp->mem_read = remote_ap_mem_read;
dp->mem_write_sized = remote_ap_mem_write_sized; dp->mem_write_sized = remote_ap_mem_write_sized;
} }
void remote_add_jtag_dev(int i, const jtag_dev_t *jtag_dev)
{
uint8_t construct[REMOTE_MAX_MSG_SIZE];
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,
REMOTE_JTAG_ADD_DEV_STR,
i,
jtag_dev->dr_prescan,
jtag_dev->dr_postscan,
jtag_dev->ir_len,
jtag_dev->ir_prescan,
jtag_dev->ir_postscan,
jtag_dev->current_ir);
platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
/* No check for error here. Done in remote_adiv5_dp_defaults!*/
}

View File

@ -39,5 +39,6 @@ void remote_srst_set_val(bool assert);
bool remote_srst_get_val(void); bool remote_srst_get_val(void);
const char *platform_target_voltage(void); const char *platform_target_voltage(void);
void remote_adiv5_dp_defaults(ADIv5_DP_t *dp); void remote_adiv5_dp_defaults(ADIv5_DP_t *dp);
void remote_add_jtag_dev(int i, const jtag_dev_t *jtag_dev);
#define __BMP_REMOTE_H_ #define __BMP_REMOTE_H_
#endif #endif

View File

@ -392,6 +392,12 @@ int platform_swdptap_init(void)
return -1; return -1;
} }
void platform_add_jtag_dev(int i, const jtag_dev_t *jtag_dev)
{
if (info.bmp_type == BMP_TYPE_BMP)
remote_add_jtag_dev(i, jtag_dev);
}
int platform_jtag_scan(const uint8_t *lrlens) int platform_jtag_scan(const uint8_t *lrlens)
{ {
switch (info.bmp_type) { switch (info.bmp_type) {

View File

@ -189,7 +189,7 @@ void remotePacketProcessJTAG(uint8_t i, char *packet)
uint64_t DO; uint64_t DO;
uint8_t ticks; uint8_t ticks;
uint64_t DI; uint64_t DI;
jtag_dev_t jtag_dev;
switch (packet[1]) { switch (packet[1]) {
case REMOTE_INIT: /* JS = initialise ============================= */ case REMOTE_INIT: /* JS = initialise ============================= */
remote_dp.dp_read = fw_adiv5_jtagdp_read; remote_dp.dp_read = fw_adiv5_jtagdp_read;
@ -241,6 +241,23 @@ void remotePacketProcessJTAG(uint8_t i, char *packet)
} }
break; break;
case REMOTE_ADD_JTAG_DEV: /* JJ = fill firmware jtag_devs */
if (i < 22) {
_respond(REMOTE_RESP_ERR,REMOTE_ERROR_WRONGLEN);
} else {
memset(&jtag_dev, 0, sizeof(jtag_dev));
uint8_t index = remotehston(2, &packet[ 2]);
jtag_dev.dr_prescan = remotehston(2, &packet[ 4]);
jtag_dev.dr_postscan = remotehston(2, &packet[ 6]);
jtag_dev.ir_len = remotehston(2, &packet[ 8]);
jtag_dev.ir_prescan = remotehston(2, &packet[10]);
jtag_dev.ir_postscan = remotehston(2, &packet[12]);
jtag_dev.current_ir = remotehston(8, &packet[14]);
jtag_add_device(index, &jtag_dev);
_respond(REMOTE_RESP_OK, 0);
}
break;
default: default:
_respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED); _respond(REMOTE_RESP_ERR,REMOTE_ERROR_UNRECOGNISED);
break; break;
@ -312,6 +329,14 @@ void remotePacketProcessHL(uint8_t i, char *packet)
case REMOTE_HL_CHECK: /* HC = Check availability of HL commands*/ case REMOTE_HL_CHECK: /* HC = Check availability of HL commands*/
_respond(REMOTE_RESP_OK, 0); _respond(REMOTE_RESP_OK, 0);
break; 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[2]);
_respond(REMOTE_RESP_OK, 0);
}
break;
case REMOTE_DP_READ: /* Hd = Read from DP register */ case REMOTE_DP_READ: /* Hd = Read from DP register */
packet += 2; packet += 2;
uint16_t addr16 = remotehston(4, packet); uint16_t addr16 = remotehston(4, packet);

View File

@ -76,6 +76,7 @@
#define REMOTE_VOLTAGE 'V' #define REMOTE_VOLTAGE 'V'
#define REMOTE_SRST_SET 'Z' #define REMOTE_SRST_SET 'Z'
#define REMOTE_SRST_GET 'z' #define REMOTE_SRST_GET 'z'
#define REMOTE_ADD_JTAG_DEV 'J'
/* Protocol response options */ /* Protocol response options */
#define REMOTE_RESP_OK 'K' #define REMOTE_RESP_OK 'K'
@ -85,6 +86,7 @@
/* High level protocol elements */ /* High level protocol elements */
#define REMOTE_HL_CHECK 'C' #define REMOTE_HL_CHECK 'C'
#define REMOTE_HL_JTAG_DEV 'J'
#define REMOTE_HL_PACKET 'H' #define REMOTE_HL_PACKET 'H'
#define REMOTE_DP_READ 'd' #define REMOTE_DP_READ 'd'
#define REMOTE_LOW_ACCESS 'L' #define REMOTE_LOW_ACCESS 'L'
@ -137,13 +139,25 @@
#define REMOTE_JTAG_NEXT (char []){ REMOTE_SOM, REMOTE_JTAG_PACKET, REMOTE_NEXT, \ #define REMOTE_JTAG_NEXT (char []){ REMOTE_SOM, REMOTE_JTAG_PACKET, REMOTE_NEXT, \
'%','c','%','c',REMOTE_EOM, 0 } '%','c','%','c',REMOTE_EOM, 0 }
/* HL protocol elements */ /* HL protocol elements */
#define HEX '%', '0', '2', 'x' #define HEX '%', '0', '2', 'x'
#define HEX_U32(x) '%', '0', '8', 'x' #define HEX_U32(x) '%', '0', '8', 'x'
#define CHR(x) '%', 'c' #define CHR(x) '%', 'c'
#define REMOTE_JTAG_ADD_DEV_STR (char []){ REMOTE_SOM, REMOTE_JTAG_PACKET,\
REMOTE_ADD_JTAG_DEV, \
'%','0','2','x', /* index */ \
'%','0','2','x', /* dr_prescan */ \
'%','0','2','x', /* dr_postscan */ \
'%','0','2','x', /* ir_len */ \
'%','0','2','x', /* ir_prescan */ \
'%','0','2','x', /* ir_postscan */ \
HEX_U32(current_ir), /* current_ir */ \
REMOTE_EOM, 0}
#define REMOTE_HL_CHECK_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_HL_CHECK, 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, \ #define REMOTE_MEM_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_MEM_READ, \
HEX_U32(address), HEX_U32(count), REMOTE_EOM, 0 } HEX_U32(address), HEX_U32(count), REMOTE_EOM, 0 }
#define REMOTE_DP_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_DP_READ, \ #define REMOTE_DP_READ_STR (char []){ REMOTE_SOM, REMOTE_HL_PACKET, REMOTE_DP_READ, \

View File

@ -260,8 +260,10 @@ void adiv5_dp_write(ADIv5_DP_t *dp, uint16_t addr, uint32_t value);
void adiv5_dp_init(ADIv5_DP_t *dp); void adiv5_dp_init(ADIv5_DP_t *dp);
void platform_adiv5_dp_defaults(ADIv5_DP_t *dp); void platform_adiv5_dp_defaults(ADIv5_DP_t *dp);
ADIv5_AP_t *adiv5_new_ap(ADIv5_DP_t *dp, uint8_t apsel); ADIv5_AP_t *adiv5_new_ap(ADIv5_DP_t *dp, uint8_t apsel);
void remote_jtag_dev(const jtag_dev_t *jtag_dev);
void adiv5_ap_ref(ADIv5_AP_t *ap); void adiv5_ap_ref(ADIv5_AP_t *ap);
void adiv5_ap_unref(ADIv5_AP_t *ap); void adiv5_ap_unref(ADIv5_AP_t *ap);
void platform_add_jtag_dev(const int dev_index, const jtag_dev_t *jtag_dev);
void adiv5_jtag_dp_handler(uint8_t jd_index, uint32_t j_idcode); void adiv5_jtag_dp_handler(uint8_t jd_index, uint32_t j_idcode);
int platform_jtag_dp_init(ADIv5_DP_t *dp); int platform_jtag_dp_init(ADIv5_DP_t *dp);

View File

@ -36,6 +36,16 @@ int jtag_dev_count;
/* bucket of ones for don't care TDI */ /* bucket of ones for don't care TDI */
static const uint8_t ones[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"; static const uint8_t ones[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
#if PC_HOSTED == 0
void jtag_add_device(const int dev_index, const jtag_dev_t *jtag_dev)
{
if (dev_index == 0)
memset(&jtag_devs, 0, sizeof(jtag_devs));
memcpy(&jtag_devs[dev_index], jtag_dev, sizeof(jtag_dev_t));
jtag_dev_count = dev_index + 1;
}
#endif
/* Scan JTAG chain for devices, store IR length and IDCODE (if present). /* Scan JTAG chain for devices, store IR length and IDCODE (if present).
* Reset TAP state machine. * Reset TAP state machine.
* Select Shift-IR state. * Select Shift-IR state.
@ -177,6 +187,11 @@ int jtag_scan(const uint8_t *irlens)
DEBUG_INFO("Return to Run-Test/Idle\n"); DEBUG_INFO("Return to Run-Test/Idle\n");
jtag_proc.jtagtap_next(1, 1); jtag_proc.jtagtap_next(1, 1);
jtagtap_return_idle(); jtagtap_return_idle();
#if PC_HOSTED == 1
/*Transfer needed device information to firmware jtag_devs*/
for(i = 0; i < jtag_dev_count; i++)
platform_add_jtag_dev(i, &jtag_devs[i]);
#endif
/* Check for known devices and handle accordingly */ /* Check for known devices and handle accordingly */
for(i = 0; i < jtag_dev_count; i++) for(i = 0; i < jtag_dev_count; i++)

View File

@ -45,6 +45,6 @@ extern int jtag_dev_count;
void jtag_dev_write_ir(jtag_proc_t *jp, uint8_t jd_index, uint32_t ir); void jtag_dev_write_ir(jtag_proc_t *jp, uint8_t jd_index, uint32_t ir);
void jtag_dev_shift_dr(jtag_proc_t *jp, uint8_t jd_index, uint8_t *dout, const uint8_t *din, int ticks); void jtag_dev_shift_dr(jtag_proc_t *jp, uint8_t jd_index, uint8_t *dout, const uint8_t *din, int ticks);
void jtag_add_device(const int dev_index, const jtag_dev_t *jtag_dev);
#endif #endif