2e828de869ec426c162007367c58ce3b66939bcf
[fw/openocd] / tcl / target / ampere_emag.cfg
1 #
2 # OpenOCD Target Configuration for eMAG ARMv8 Processor
3 #
4 # Copyright (c) 2019-2021, Ampere Computing LLC
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program;
18 #
19 #
20
21 #
22 # Configure defaults for target
23 # Can be overriden in board configuration file
24 #
25
26 if { [info exists CHIPNAME] } {
27         set _CHIPNAME $CHIPNAME
28 } else {
29         set _CHIPNAME emag
30 }
31
32 if { [info exists NUMCORES] } {
33         set _NUMCORES $NUMCORES
34 } else {
35         set _NUMCORES 32
36 }
37
38 if { [info exists ENDIAN] } {
39         set _ENDIAN $ENDIAN
40 } else {
41         set _ENDIAN little
42 }
43
44 if { [info exists CPUTAPID ] } {
45         set _CPUTAPID $CPUTAPID
46 } else {
47         set _CPUTAPID 0x4BA00477
48 }
49
50 #
51 # Configure JTAG TAP
52 #
53
54 jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0x3 -expected-id $_CPUTAPID
55 set _TAPNAME $_CHIPNAME.cpu
56
57 set _DAPNAME ${_TAPNAME}_dap
58 set _APNUM 1
59 dap create $_DAPNAME -chain-position $_TAPNAME
60 $_DAPNAME apsel $_APNUM
61
62 # Create the DAP AP0 MEM-AP AHB-AP target
63 target create AHB mem_ap -endian $_ENDIAN -dap $_DAPNAME -ap-num 0
64
65 # Create the DAP AP1 MEM-AP APB-AP target
66 target create APB mem_ap -endian $_ENDIAN -dap $_DAPNAME -ap-num 1
67
68 #
69 # Configure target CPUs
70 #
71
72 # Build string used to enable smp mode
73 set _SMP_STR "target smp"
74
75 for {set _i 0} {$_i < $_NUMCORES} {incr _i} {
76         # Format a string to reference which CPU target to use
77         set _TARGETNAME [format "${_TAPNAME}_%02d" $_i]
78
79         # Create and configure Cross Trigger Interface (CTI) - required for halt and resume
80         set _CTINAME $_TARGETNAME.cti
81         cti create $_CTINAME -dap $_DAPNAME -ap-num $_APNUM -baseaddr [expr {0xFC020000 + ($_i << 20)}]
82
83         # Create the target
84         target create $_TARGETNAME aarch64 -endian $_ENDIAN -dap $_DAPNAME -ap-num $_APNUM -cti $_CTINAME -coreid $_i
85         set _SMP_STR "$_SMP_STR $_TARGETNAME"
86
87         # Clear CTI output/input enables that are not configured by OpenOCD for aarch64
88         $_TARGETNAME configure -event examine-start [subst {
89                 $_CTINAME write INEN0 0x00000000
90                 $_CTINAME write INEN1 0x00000000
91                 $_CTINAME write INEN2 0x00000000
92                 $_CTINAME write INEN3 0x00000000
93                 $_CTINAME write INEN4 0x00000000
94                 $_CTINAME write INEN5 0x00000000
95                 $_CTINAME write INEN6 0x00000000
96                 $_CTINAME write INEN7 0x00000000
97                 $_CTINAME write INEN8 0x00000000
98
99                 $_CTINAME write OUTEN2 0x00000000
100                 $_CTINAME write OUTEN3 0x00000000
101                 $_CTINAME write OUTEN4 0x00000000
102                 $_CTINAME write OUTEN5 0x00000000
103                 $_CTINAME write OUTEN6 0x00000000
104                 $_CTINAME write OUTEN7 0x00000000
105                 $_CTINAME write OUTEN8 0x00000000
106         }]
107
108         # Enable OpenOCD HWTHREAD RTOS feature for GDB thread (CPU) selection support
109         # This feature presents CPU cores ("hardware threads") in an SMP system as threads to GDB
110         $_TARGETNAME configure -rtos hwthread
111 }
112 eval $_SMP_STR