arm_adi_v5: prevent possibly endless recursion in dap_dp_init()
authorTomas Vanek <vanekt@fbl.cz>
Mon, 29 Jun 2020 11:34:07 +0000 (13:34 +0200)
committerTomas Vanek <vanekt@fbl.cz>
Wed, 2 Dec 2020 23:15:08 +0000 (23:15 +0000)
commit646c3c99020f8fdf7ee0adf821582238aac4a80c
tree58647f4f4ef0b211e69203a980d47aa4d08d4f00
parenta8edbd0200560bfd412c5c563908d860ed2c96a6
arm_adi_v5: prevent possibly endless recursion in dap_dp_init()

If dap_dp_read_atomic() in 30 trials loop fails, dap->do_reconnect is set.
Following dap_dp_read_atomic() calls dap_queue_dp_read() which in case
of SWD transport calls swd_queue_dp_read(). It starts
with swd_check_reconnect() and it calls swd_connect() because
dap->do_reconnect is set. swd_connect() does some initialization,
reads DPIDR and calls dap_dp_init() again!

Moreover if dap_dp_init() is called from cortex_m_reset_(de)assert()
one level of recursion is necessary to reconnect the target.

Introduce dap_dp_init_or_reconnect() for use in cortex_m reset
and similar.
Remove loop of 30 atomic reads of DP_STAT to prevent unwanted recursion.

Change-Id: I54052fdefe50bf5f7c7b59fe751fe2063d5710c9
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5729
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/target/arm_adi_v5.c
src/target/arm_adi_v5.h
src/target/cortex_m.c