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: ARM JTAG regressions #1389

Merged
merged 56 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f65f240
remote: Cleaned up and rewrote remote_send_buf()
dragonmux Feb 14, 2023
a0bc82f
remote: Cleaned up remote_respond_buf()
dragonmux Feb 14, 2023
9a42802
remote: Systematically worked through and fixed remote_packet_process…
dragonmux Feb 14, 2023
bcd923c
common/jtagtap: Removed the jtag_next_tms_tdi() helper to explore ret…
dragonmux Feb 14, 2023
cf5d280
adiv5: Cleanup and const correctness in adiv5_dp_init()
dragonmux Feb 14, 2023
c7907ba
common/jtagtap: Further work opening the timings on jtagtap_tdi_tdo_s…
dragonmux Feb 14, 2023
0718c5f
adiv5: Fixed CMSIS-DAP JTAG adaptors like OBRTrace going off the rail…
dragonmux Feb 15, 2023
852fcd1
hosted/dap: Cleaned up the implementation of dap_jtag_configure and d…
dragonmux Feb 15, 2023
f4ee6b2
common/jtagtap: jtagtap_tdi_tdo_seq_no_delay must write to data_out o…
dragonmux Feb 15, 2023
407b93b
common/jtagtap: Re-timed jtagtap_tdi_seq_no_delay() slightly to impro…
dragonmux Feb 15, 2023
3ec44c8
remote: Begun defining a new version of the remote protocol so the AD…
dragonmux Feb 15, 2023
35a61fe
remote: Cleaned up the header ready for the introduction of the ADIv5…
dragonmux Feb 16, 2023
1689a5c
remote: Implemented a new version of REMOTE_DP_READ
dragonmux Feb 16, 2023
497adf9
hex_utils: Replace the hexdigits array with a function
dragonmux Feb 16, 2023
9ccae8d
hex_utils: Made the hex_digit and unhex_digit functions available to …
dragonmux Feb 16, 2023
9a7d928
remote: Cleaned up and rewrote remote_respond()
dragonmux Feb 16, 2023
2785383
remote: Corrected the naming of remote_hex_string_to_num from remoteh…
dragonmux Feb 16, 2023
40327fa
remote: Cleaned up and rewrote remote_respond_string()
dragonmux Feb 16, 2023
ac79d70
remote: Implemented a new version of REMOTE_ADIv5_RAW_ACCESS (was REM…
dragonmux Feb 16, 2023
b2e7990
remote: Impelemented new versions of REMOTE_AP_READ and REMOTE_AP_WRITE
dragonmux Feb 16, 2023
e1611f2
remote: Fixed the ADIv5 protocol definitions for memory access
dragonmux Feb 16, 2023
eb18700
main: Ensured alignment of the packet buffer and allowed the remote p…
dragonmux Feb 16, 2023
64fef3d
remote: Implemented a new version of REMOTE_MEM_READ
dragonmux Feb 16, 2023
47f1560
remote: Documented more of how remote_packet_process_adiv5() works
dragonmux Feb 16, 2023
418eb73
remote: Implemented a new version of REMOTE_MEM_WRITE
dragonmux Feb 16, 2023
57dfec3
remote: Do at least any validation on the packet length going into re…
dragonmux Feb 16, 2023
ea090f5
remote: Moved the JTAG device fill command into the high-level comman…
dragonmux Feb 16, 2023
b35d44d
remote: Refactored out some of the formatting strings to ease readabi…
dragonmux Feb 16, 2023
7b4432e
remote: Fixed up the parameters to remote_packet_process_high_level()
dragonmux Feb 16, 2023
da9836f
remote: Folded the protocol version check command into the high level…
dragonmux Feb 16, 2023
d4e0ae9
remote: Cleaned up the implementation of REMOTE_ADD_JTAG_DEV
dragonmux Feb 16, 2023
a5cb710
hosted/bmp_remote: Fixed the input types to the platform_buffer_*() f…
dragonmux Feb 16, 2023
156eae1
hosted/bmp_remote: Corrected for the renaming in the remote protocol …
dragonmux Feb 16, 2023
35e94fe
hosted/bmp_remote: Fixed the clang-tidy lints in remote_add_jtag_dev()
dragonmux Feb 16, 2023
9c414da
hosted/bmp_remote: Cleaned up and fixed various clang-tidy lints
dragonmux Feb 16, 2023
172aa64
general: Fixed several clang-tidy lints about BMDA's DEBUG_ functions
dragonmux Feb 16, 2023
549b4f2
hosted/remote_jtagtap: Removed all the platform_buffer_* function cas…
dragonmux Feb 16, 2023
f7067b0
hosted/remote_swdptap: Removed all the platform_buffer_* function cas…
dragonmux Feb 16, 2023
6125803
hosted/bmp_remote: Simplified remote_init() as the REMOTE_START_STR d…
dragonmux Feb 16, 2023
22f9cf8
adiv5: Fixed the nomenclature of the device index member of the DP st…
dragonmux Feb 16, 2023
ef08820
hosted/bmp_remote: Implemented new error handling machinary for ADIv5…
dragonmux Feb 16, 2023
aa9d288
hosted/bmp_remote: Reimplemented the DP read handler using the new ma…
dragonmux Feb 16, 2023
8cb2fdf
hosted/bmp_remote: Reimplemented the raw access handler using the new…
dragonmux Feb 16, 2023
8cb4809
hosted/bmp_remote: Reimplemented the AP read handler using the new ma…
dragonmux Feb 16, 2023
34edcd1
hosted/bmp_remote: Reimplemented the AP write handler using the new m…
dragonmux Feb 16, 2023
8380070
hosted/bmp_remote: Reimplemented the ADIv5 memory read handler using …
dragonmux Feb 16, 2023
233b0e4
hosted/bmp_remote: Reimplemented the ADIv5 memory write handler using…
dragonmux Feb 16, 2023
184fd62
hosted/bmp_remote: Overhaulled the high-level remote protocol version…
dragonmux Feb 16, 2023
935238c
remote: Implemented exception handling around the ADIv5 high-levle re…
dragonmux Feb 16, 2023
9a58408
hosted/bmp_remote: Implemented handling for exceptions propegated thr…
dragonmux Feb 16, 2023
6d8dbe3
adiv5_jtagdp: Fixed the behaviour of adiv5_jtagdp_error() under BMDA …
dragonmux Feb 20, 2023
932849b
hosted/cmsis_dap: Fixed the implementation of dap_jtag_dp_error() to …
dragonmux Feb 20, 2023
9211f78
hosted/dap_command: Fixed several clang-tidy lints in the decls
dragonmux Feb 20, 2023
8ec851f
hosted/cmsis_dap: Removed the custom JTAG error recovery function in …
dragonmux Feb 20, 2023
51267d8
cortexm: Fix target resumption on detach for some targets
dragonmux Feb 24, 2023
7d04143
hoted/cmsis_dap: Changed the phase when dap_jtag_configure() is calle…
dragonmux Feb 26, 2023
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
17 changes: 13 additions & 4 deletions src/hex_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Copyright (C) 2011 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2023 1BitSquared <info@1bitsquared.com>
* Modified by Rachel Mant <git@dragonmux.network>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -23,23 +25,30 @@
#include "general.h"
#include "hex_utils.h"

static const char hexdigits[] = "0123456789abcdef";
char hex_digit(const uint8_t value)
{
char digit = (char)value;
if (value > 9U)
digit += 'A' - '0' - 10U;
digit += '0';
return digit;
}

char *hexify(char *const hex, const void *const buf, const size_t size)
{
char *dst = hex;
const uint8_t *const src = buf;

for (size_t idx = 0; idx < size; ++idx) {
*dst++ = hexdigits[src[idx] >> 4U];
*dst++ = hexdigits[src[idx] & 0xfU];
*dst++ = hex_digit(src[idx] >> 4U);
*dst++ = hex_digit(src[idx] & 0xfU);
}
*dst = 0;

return hex;
}

static uint8_t unhex_digit(const char hex)
uint8_t unhex_digit(const char hex)
{
uint8_t tmp = hex - '0';
if (tmp > 9U)
Expand Down
3 changes: 3 additions & 0 deletions src/include/gdb_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
#define INCLUDE_GDB_MAIN_H

#include "target.h"

extern bool gdb_target_running;
extern target_s *cur_target;

void gdb_poll_target(void);
void gdb_main(char *pbuf, size_t pbuf_size, size_t size);
char *gdb_packet_buffer();

#endif /* INCLUDE_GDB_MAIN_H */
65 changes: 29 additions & 36 deletions src/include/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,80 +103,73 @@ extern int cl_debuglevel;

static inline void DEBUG_WARN(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_INFO(const char *format, ...)
{
if (~cl_debuglevel & BMP_DEBUG_INFO)
return;
va_list ap;
va_start(ap, format);
va_list args;
va_start(args, format);
if (cl_debuglevel & BMP_DEBUG_STDOUT)
vfprintf(stdout, format, ap);
vfprintf(stdout, format, args);
else
vfprintf(stderr, format, ap);
va_end(ap);
return;
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_GDB(const char *format, ...)
{
if (~cl_debuglevel & BMP_DEBUG_GDB)
return;
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_GDB_WIRE(const char *format, ...)
{
if ((cl_debuglevel & (BMP_DEBUG_GDB | BMP_DEBUG_WIRE)) != (BMP_DEBUG_GDB | BMP_DEBUG_WIRE))
return;
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_TARGET(const char *format, ...)
{
if (~cl_debuglevel & BMP_DEBUG_TARGET)
return;
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_PROBE(const char *format, ...)
{
if (~cl_debuglevel & BMP_DEBUG_PROBE)
return;
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}

static inline void DEBUG_WIRE(const char *format, ...)
{
if (~cl_debuglevel & BMP_DEBUG_WIRE)
return;
va_list ap;
va_start(ap, format);
vfprintf(stderr, format, ap);
va_end(ap);
return;
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions src/include/hex_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Copyright (C) 2011 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2023 1BitSquared <info@1bitsquared.com>
* Modified by Rachel Mant <git@dragonmux.network>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,9 +23,13 @@
#ifndef INCLUDE_HEX_UTILS_H
#define INCLUDE_HEX_UTILS_H

#include <stdint.h>
#include <stddef.h>

char *hexify(char *hex, const void *buf, size_t size);
char *unhexify(void *buf, const char *hex, size_t size);

char hex_digit(uint8_t value);
uint8_t unhex_digit(char hex);

#endif /* INCLUDE_HEX_UTILS_H */
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@
#endif

#define BUF_SIZE 1024U
static char pbuf[BUF_SIZE + 1U];
/* This has to be aligned so the remote protocol can re-use it without causing Problems */
static char pbuf[BUF_SIZE + 1U] __attribute__((aligned(8)));

char *gdb_packet_buffer()
{
return pbuf;
}

static void bmp_poll_loop(void)
{
Expand Down
57 changes: 40 additions & 17 deletions src/platforms/common/jtagtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Copyright (C) 2011 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz>
* Copyright (C) 2022-2023 1BitSquared <info@1bitsquared.com>
* Modified by Rachel Mant <git@dragonmux.network>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -168,15 +170,6 @@ static void jtagtap_tdi_tdo_seq_swd_delay(
data_out[byte] = value;
}

static inline void jtag_next_tms_tdi(const bool tms, const bool tdi)
{
/* Initiate the falling edge on the bus */
gpio_clear(TCK_PORT, TCK_PIN);
/* It is now safe to change TMS and TDI */
gpio_set_val(TMS_PORT, TMS_PIN, tms);
gpio_set_val(TDI_PORT, TDI_PIN, tdi);
}

static void jtagtap_tdi_tdo_seq_no_delay(
const uint8_t *const data_in, uint8_t *const data_out, const bool final_tms, const size_t clock_cycles)
{
Expand All @@ -185,16 +178,28 @@ static void jtagtap_tdi_tdo_seq_no_delay(
/* Calculate the next bit and byte to consume data from */
const uint8_t bit = cycle & 7U;
const size_t byte = cycle >> 3U;
const bool tms = cycle + 1U >= clock_cycles && final_tms;
const bool tdi = data_in[byte] & (1U << bit);
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
gpio_clear(TCK_PORT, TCK_PIN);
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
/* Configure the bus for the next cycle */
jtag_next_tms_tdi(cycle + 1U >= clock_cycles && final_tms, data_in[byte] & (1U << bit));
gpio_set_val(TDI_PORT, TDI_PIN, tdi);
gpio_set_val(TMS_PORT, TMS_PIN, tms);
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
/* Increment the cycle counter */
++cycle;
__asm__("nop");
__asm__("nop");
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
__asm__ volatile("nop" ::: "memory");
/* Start the clock cycle */
gpio_set(TCK_PORT, TCK_PIN);
/* If TDO is high, store a 1 in the appropriate position in the value being accumulated */
if (gpio_get(TDO_PORT, TDO_PIN))
if (gpio_get(TDO_PORT, TDO_PIN)) /* XXX: Try to remove the need for the if here */
value |= 1U << bit;
/* If we've got the next whole byte, store the accumulated value and reset state */
if (bit == 7U) {
Expand All @@ -203,6 +208,11 @@ static void jtagtap_tdi_tdo_seq_no_delay(
}
/* Finish the clock cycle */
}
/* If clock_cycles is not divisable by 8, we have some extra data to write back here. */
if (clock_cycles & 7U) {
const size_t byte = (clock_cycles - 1U) >> 3U;
data_out[byte] = value;
}
gpio_clear(TCK_PORT, TCK_PIN);
}

Expand Down Expand Up @@ -238,14 +248,27 @@ static void jtagtap_tdi_seq_swd_delay(const uint8_t *const data_in, const bool f

static void jtagtap_tdi_seq_no_delay(const uint8_t *const data_in, const bool final_tms, size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
gpio_clear(TCK_PORT, TCK_PIN);
for (size_t cycle = 0; cycle < clock_cycles;) {
const size_t bit = cycle & 7U;
const size_t byte = cycle >> 3U;
const bool tms = cycle + 1U >= clock_cycles && final_tms;
const bool tdi = data_in[byte] & (1U << bit);
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
gpio_clear(TCK_PORT, TCK_PIN);
/* On the last tick, assert final_tms to TMS_PIN */
gpio_set_val(TMS_PORT, TMS_PIN, cycle + 1U >= clock_cycles && final_tms);
gpio_set_val(TMS_PORT, TMS_PIN, tms);
/* Set up the TDI pin and start the clock cycle */
gpio_set_val(TDI_PORT, TDI_PIN, data_in[byte] & (1U << bit));
gpio_set_val(TDI_PORT, TDI_PIN, tdi);
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("" ::: "memory");
/* Increment the cycle counter */
++cycle;
__asm__("nop");
__asm__("nop");
/* Block the compiler from re-ordering the calculations to preserve timings */
__asm__ volatile("nop" ::: "memory");
/* Start the clock cycle */
gpio_set(TCK_PORT, TCK_PIN);
/* Finish the clock cycle */
}
Expand Down Expand Up @@ -279,7 +302,7 @@ static void jtagtap_cycle_no_delay(const size_t clock_cycles)
{
for (size_t cycle = 0; cycle < clock_cycles; ++cycle) {
gpio_set(TCK_PORT, TCK_PIN);
gpio_set(TCK_PORT, TCK_PIN);
__asm__ volatile("nop" ::: "memory");
gpio_clear(TCK_PORT, TCK_PIN);
}
}
Expand Down
Loading