Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Remote protocol target communications initialisation #1629

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -135,7 +144,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();
Expand Down Expand Up @@ -185,7 +196,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();
Expand Down
2 changes: 2 additions & 0 deletions src/target/adiv5.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ 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);
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);
Expand Down
4 changes: 1 addition & 3 deletions src/target/adiv5_jtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down