tcl/target/ti_k3: Rename R5 targets to be more descriptive
[fw/openocd] / tcl / target / ti_k3.cfg
1 # SPDX-License-Identifier: GPL-2.0-or-later
2 # Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/
3 #
4 # Texas Instruments K3 devices:
5 # * AM654x: https://www.ti.com/lit/pdf/spruid7
6 #  Has 4 ARMV8 Cores and 2 R5 Cores and an M3
7 # * J721E: https://www.ti.com/lit/pdf/spruil1
8 #  Has 2 ARMV8 Cores and 6 R5 Cores and an M3
9 # * J7200: https://www.ti.com/lit/pdf/spruiu1
10 #  Has 2 ARMV8 Cores and 4 R5 Cores and an M3
11 # * AM642: https://www.ti.com/lit/pdf/spruim2
12 #  Has 2 ARMV8 Cores and 4 R5 Cores, M4F and an M3
13 #
14
15 if { [info exists SOC] } {
16         set _soc $SOC
17 } else {
18         set _soc am654
19 }
20
21 # set V8_SMP_DEBUG to non 0 value in board if you'd like to use SMP debug
22 if { [info exists V8_SMP_DEBUG] } {
23         set _v8_smp_debug $V8_SMP_DEBUG
24 } else {
25         set _v8_smp_debug 0
26 }
27
28 # Common Definitions
29
30 # System Controller is the very first processor - all current SoCs have it.
31 set CM3_CTIBASE         {0x3C016000}
32
33 # sysctrl power-ap unlock offsets
34 set _sysctrl_ap_unlock_offsets {0xf0 0x44}
35
36 # All the ARMV8s are the next processors.
37 #                  CL0,CORE0  CL0,CORE1  CL1,CORE0  CL1,CORE1
38 set ARMV8_DBGBASE {0x90410000 0x90510000 0x90810000 0x90910000}
39 set ARMV8_CTIBASE {0x90420000 0x90520000 0x90820000 0x90920000}
40
41 # And we add up the R5s
42 #               (0)MCU 0   (1)MCU 1   (2)MAIN_0_0 (3)MAIN_0_1 (4)MAIN_1_0 (5)MAIN_1_1
43 set R5_DBGBASE {0x9d010000 0x9d012000 0x9d410000 0x9d412000 0x9d510000 0x9d512000}
44 set R5_CTIBASE {0x9d018000 0x9d019000 0x9d418000 0x9d419000 0x9d518000 0x9d519000}
45 set R5_NAMES {mcu_r5.0 mcu_r5.1 main0_r5.0 main0_r5.1 main1_r5.0 main1_r5.1}
46
47 # Finally an General Purpose(GP) MCU
48 set CM4_CTIBASE         {0x20001000}
49
50 # General Purpose MCU (M4) may be present on some very few SoCs
51 set _gp_mcu_cores 0
52 # General Purpose MCU power-ap unlock offsets
53 set _gp_mcu_ap_unlock_offsets {0xf0 0x60}
54
55 # Set configuration overrides for each SOC
56 switch $_soc {
57         am654 {
58                 set _CHIPNAME am654
59                 set _K3_DAP_TAPID 0x0bb5a02f
60
61                 # AM654 has 2 clusters of 2 A53 cores each.
62                 set _armv8_cpu_name a53
63                 set _armv8_cores 4
64
65                 # AM654 has 1 cluster of 2 R5s cores.
66                 set _r5_cores 2
67                 set _mcu_r5_cores 2
68                 set _main0_r5_cores 0
69                 set _main1_r5_cores 0
70                 set R5_NAMES {mcu_r5.0 mcu_r5.1}
71
72                 # Sysctrl power-ap unlock offsets
73                 set _sysctrl_ap_unlock_offsets {0xf0 0x50}
74         }
75         am642 {
76                 set _CHIPNAME am642
77                 set _K3_DAP_TAPID 0x0bb3802f
78
79                 # AM642 has 1 clusters of 2 A53 cores each.
80                 set _armv8_cpu_name a53
81                 set _armv8_cores 2
82                 set ARMV8_DBGBASE {0x90010000 0x90110000}
83                 set ARMV8_CTIBASE {0x90020000 0x90120000}
84
85                 # AM642 has 2 cluster of 2 R5s cores.
86                 set _r5_cores 4
87                 set _mcu_r5_cores 0
88                 set _main0_r5_cores 2
89                 set _main1_r5_cores 2
90                 set R5_NAMES {main0_r5.0 main0_r5.1 main1_r5.0 main1_r5.1}
91                 set R5_DBGBASE {0x9d410000 0x9d412000 0x9d510000 0x9d512000}
92                 set R5_CTIBASE {0x9d418000 0x9d419000 0x9d518000 0x9d519000}
93
94                 # M4 processor
95                 set _gp_mcu_cores 1
96         }
97         j721e {
98                 set _CHIPNAME j721e
99                 set _K3_DAP_TAPID 0x0bb6402f
100                 # J721E has 1 cluster of 2 A72 cores.
101                 set _armv8_cpu_name a72
102                 set _armv8_cores 2
103
104                 # J721E has 3 clusters of 2 R5 cores each.
105                 set _r5_cores 6
106                 set _mcu_r5_cores 2
107                 set _main0_r5_cores 2
108                 set _main1_r5_cores 2
109         }
110         j7200 {
111                 set _CHIPNAME j7200
112                 set _K3_DAP_TAPID 0x0bb6d02f
113
114                 # J7200 has 1 cluster of 2 A72 cores.
115                 set _armv8_cpu_name a72
116                 set _armv8_cores 2
117
118                 # J7200 has 2 clusters of 2 R5 cores each.
119                 set _r5_cores 4
120                 set _mcu_r5_cores 2
121                 set _main0_r5_cores 2
122                 set _main1_r5_cores 0
123                 set R5_DBGBASE {0x9d010000 0x9d012000 0x9d110000 0x9d112000}
124                 set R5_CTIBASE {0x9d018000 0x9d019000 0x9d118000 0x9d119000}
125
126                 # M3 CTI base
127                 set CM3_CTIBASE {0x20001000}
128         }
129         default {
130                 echo "'$_soc' is invalid!"
131         }
132 }
133
134 jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_K3_DAP_TAPID -ignore-version
135 dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
136
137 set _TARGETNAME $_CHIPNAME.cpu
138
139 set _CTINAME $_CHIPNAME.cti
140
141 # sysctrl is always present
142 cti create $_CTINAME.sysctrl -dap $_CHIPNAME.dap -ap-num 7 -baseaddr [lindex $CM3_CTIBASE 0]
143 target create $_TARGETNAME.sysctrl cortex_m -dap $_CHIPNAME.dap -ap-num 7 -defer-examine
144 $_TARGETNAME.sysctrl configure -event reset-assert { }
145
146 proc sysctrl_up {} {
147         # To access sysctrl, we need to enable the JTAG access for the same.
148         # Ensure Power-AP unlocked
149         $::_CHIPNAME.dap apreg 3 [lindex $::_sysctrl_ap_unlock_offsets 0] 0x00190000
150         $::_CHIPNAME.dap apreg 3 [lindex $::_sysctrl_ap_unlock_offsets 1] 0x00102098
151
152         $::_TARGETNAME.sysctrl arp_examine
153 }
154
155 $_TARGETNAME.sysctrl configure -event gdb-attach {
156         sysctrl_up
157         # gdb-attach default rule
158         halt 1000
159 }
160
161 set _v8_smp_targets ""
162
163 for { set _core 0 } { $_core < $_armv8_cores } { incr _core } {
164
165         cti create $_CTINAME.$_armv8_cpu_name.$_core -dap $_CHIPNAME.dap -ap-num 1 \
166                 -baseaddr [lindex $ARMV8_CTIBASE $_core]
167
168         target create $_TARGETNAME.$_armv8_cpu_name.$_core aarch64 -dap $_CHIPNAME.dap \
169                 -dbgbase [lindex $ARMV8_DBGBASE $_core] -cti $_CTINAME.$_armv8_cpu_name.$_core -defer-examine
170
171         set _v8_smp_targets "$_v8_smp_targets $_TARGETNAME.$_armv8_cpu_name.$_core"
172 }
173
174 # Setup ARMV8 proc commands based on CPU to prevent people confusing SoCs
175 set _armv8_up_cmd "$_armv8_cpu_name"_up
176 # Available if V8_SMP_DEBUG is set to non-zero value
177 set _armv8_smp_cmd "$_armv8_cpu_name"_smp
178
179 if { $_v8_smp_debug == 0 } {
180         proc $_armv8_up_cmd { args } {
181                 foreach { _core } [set args] {
182                         $::_TARGETNAME.$::_armv8_cpu_name.$_core arp_examine
183                         $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 dbginit
184                 }
185         }
186 } else {
187         proc $_armv8_smp_cmd { args } {
188                 for { set _core 0 } { $_core < $::_armv8_cores } { incr _core } {
189                         $::_TARGETNAME.$::_armv8_cpu_name.$_core arp_examine
190                         $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 dbginit
191                         $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 smp on
192                 }
193                 # Set Default target are core 0
194                 targets $::_TARGETNAME.$::_armv8_cpu_name.0
195         }
196
197         # Declare SMP
198         target smp $:::_v8_smp_targets
199 }
200
201 for { set _core 0 } { $_core < $_r5_cores } { incr _core } {
202         set _r5_name [lindex $R5_NAMES $_core]
203         cti create $_CTINAME.$_r5_name -dap $_CHIPNAME.dap -ap-num 1 \
204                 -baseaddr [lindex $R5_CTIBASE $_core]
205
206         # inactive core examination will fail - wait till startup of additional core
207         target create $_TARGETNAME.$_r5_name cortex_r4 -dap $_CHIPNAME.dap \
208                 -dbgbase [lindex $R5_DBGBASE $_core] -ap-num 1 -defer-examine
209 }
210
211 if { $_mcu_r5_cores != 0 } {
212         proc mcu_r5_up { args } {
213                 foreach { _core } [set args] {
214                         $::_TARGETNAME.mcu_r5.$_core arp_examine
215                         $::_TARGETNAME.mcu_r5.$_core cortex_r4 dbginit
216                 }
217         }
218 }
219
220 if { $_main0_r5_cores != 0 } {
221         proc main0_r5_up { args } {
222                 foreach { _core } [set args] {
223                         $::_TARGETNAME.main0_r5.$_core arp_examine
224                         $::_TARGETNAME.main0_r5.$_core cortex_r4 dbginit
225                 }
226         }
227 }
228
229 if { $_main1_r5_cores != 0 } {
230         proc main1_r5_up { args } {
231                 foreach { _core } [set args] {
232                         $::_TARGETNAME.main1_r5.$_core arp_examine
233                         $::_TARGETNAME.main1_r5.$_core cortex_r4 dbginit
234                 }
235         }
236 }
237
238 if { $_gp_mcu_cores != 0 } {
239         cti create $_CTINAME.gp_mcu -dap $_CHIPNAME.dap -ap-num 8 -baseaddr [lindex $CM4_CTIBASE 0]
240         target create $_TARGETNAME.gp_mcu cortex_m -dap $_CHIPNAME.dap -ap-num 8 -defer-examine
241         $_TARGETNAME.gp_mcu configure -event reset-assert { }
242
243         proc gp_mcu_up {} {
244                 # To access GP MCU, we need to enable the JTAG access for the same.
245                 # Ensure Power-AP unlocked
246                 $::_CHIPNAME.dap apreg 3 [lindex $::_gp_mcu_ap_unlock_offsets 0] 0x00190000
247                 $::_CHIPNAME.dap apreg 3 [lindex $::_gp_mcu_ap_unlock_offsets 1] 0x00102098
248
249                 $::_TARGETNAME.gp_mcu arp_examine
250         }
251
252         $_TARGETNAME.gp_mcu configure -event gdb-attach {
253                 gp_mcu_up
254                 # gdb-attach default rule
255                 halt 1000
256         }
257 }