From 13dc81c4b9c12bfebef6048bcd2cec5288613c9f Mon Sep 17 00:00:00 2001
From: Joakim Bech <joakim.bech@linaro.org>
Date: Mon, 4 Feb 2019 15:13:17 +0100
Subject: [PATCH] rpi3: update OpenOCD configuration for RPi3

Fixes: https://github.com/OP-TEE/build/issues/257

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Tested-by: Joakim Bech <joakim.bech@linaro.org> (RPi3+NFS+JTAG)
Acked-by: Jerome Forissier <jerome.forissier@linaro.org>
---
 rpi3/debugger/pi3.cfg | 61 +++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 26 deletions(-)

diff --git a/rpi3/debugger/pi3.cfg b/rpi3/debugger/pi3.cfg
index 4463be8..a075d1a 100644
--- a/rpi3/debugger/pi3.cfg
+++ b/rpi3/debugger/pi3.cfg
@@ -1,38 +1,47 @@
-#  RPi3b
-
-tcl_port 5555
-telnet_port 4444
-gdb_port 3333
-
+# Credits to Petr Tesarik from SUSE who provided this updated configuration,
+# source: https://www.suse.com/c/debugging-raspberry-pi-3-with-jtag/
 transport select jtag
 
+# we need to enable srst even though we don't connect it
+reset_config trst_and_srst
+
 adapter_khz 1000
+jtag_ntrst_delay 500
 
-jtag_ntrst_delay 100
-reset_config trst_only separate 
+if { [info exists CHIPNAME] } {
+  set _CHIPNAME $CHIPNAME
+} else {
+  set _CHIPNAME rpi3
+}
 
-set _CHIPNAME rpi3b
+#
+# Main DAP
+#
+if { [info exists DAP_TAPID] } {
+   set _DAP_TAPID $DAP_TAPID
+} else {
+   set _DAP_TAPID 0x4ba00477
+}
 
-set _TARGETNAME_0 $_CHIPNAME.cpu0
-set _TARGETNAME_1 $_CHIPNAME.cpu1
-set _TARGETNAME_2 $_CHIPNAME.cpu2
-set _TARGETNAME_3 $_CHIPNAME.cpu3
+jtag newtap $_CHIPNAME tap -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_DAP_TAPID -enable
+dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.tap
 
-jtag newtap $_CHIPNAME dap -irlen 4 -expected-id 0x4ba00477
+set _TARGETNAME $_CHIPNAME.a53
+set _CTINAME $_CHIPNAME.cti
 
-target create $_TARGETNAME_0 aarch64 -chain-position $_CHIPNAME.dap -dbgbase 0x80010000 -ctibase 0x80018000
-#target create $_TARGETNAME_1 aarch64 -chain-position $_CHIPNAME.dap -dbgbase 0x80012000 -ctibase 0x80019000
-#target create $_TARGETNAME_2 aarch64 -chain-position $_CHIPNAME.dap -dbgbase 0x80014000 -ctibase 0x8001a000
-#target create $_TARGETNAME_3 aarch64 -chain-position $_CHIPNAME.dap -dbgbase 0x80016000 -ctibase 0x8001b000
+set DBGBASE {0x80010000 0x80012000 0x80014000 0x80016000}
+set CTIBASE {0x80018000 0x80019000 0x8001a000 0x8001b000}
+set _cores 4
 
-#target smp $_CHIPNAME.cpu3 $_CHIPNAME.cpu2 $_CHIPNAME.cpu1 $_CHIPNAME.cpu0
+for { set _core 0 } { $_core < $_cores } { incr _core } {
 
-proc rpi3b_gdb_attach {target} {
-  echo "gdb attach halt ..."
-  targets 0
-  halt
-}
+    cti create $_CTINAME.$_core -dap $_CHIPNAME.dap -ap-num 0 \
+        -ctibase [lindex $CTIBASE $_core]
+
+    target create $_TARGETNAME.$_core aarch64 \
+        -dap $_CHIPNAME.dap -coreid $_core \
+        -dbgbase [lindex $DBGBASE $_core] -cti $_CTINAME.$_core
 
-$_TARGETNAME_0 configure -event gdb-attach {
-  halt
+    $_TARGETNAME.$_core configure -event reset-assert-post "aarch64 dbginit"
+    $_TARGETNAME.$_core configure -event gdb-attach { halt }
 }
-- 
GitLab