telnet_port 4444
#TODO: Verify gdb setup works as intended.
#TODO: With the command "cache_config" we could configure the L2 cache and avoid the problem which occurs if you wait too long to connect via JTAG...
gdb_port 3333
#tcl_port 0 #No Tcl port needed...

#jtag_khz 1000 #Not needed?
adapter_khz 1000

if { [info exists CHIPNAME] } {
	set  _CHIPNAME $CHIPNAME
} else {
	set  _CHIPNAME bcmrpi2
}

if { [info exists DAP_TAPID] } {
	set _DAP_TAPID $DAP_TAPID
} else {
	set _DAP_TAPID 0x4ba00477
}

jtag newtap $_CHIPNAME dap -expected-id $_DAP_TAPID -irlen 4 -ircapture 0x01 -irmask 0x0f

set _TARGETNAME0 $_CHIPNAME.cpu0
set _TARGETNAME1 $_CHIPNAME.cpu1
set _TARGETNAME2 $_CHIPNAME.cpu2
set _TARGETNAME3 $_CHIPNAME.cpu3

target create $_TARGETNAME0 cortex_a -chain-position $_CHIPNAME.dap -coreid 0 -dbgbase 0x80010000
target create $_TARGETNAME1 cortex_a -chain-position $_CHIPNAME.dap -coreid 1 -dbgbase 0x80012000
target create $_TARGETNAME2 cortex_a -chain-position $_CHIPNAME.dap -coreid 2 -dbgbase 0x80014000
target create $_TARGETNAME3 cortex_a -chain-position $_CHIPNAME.dap -coreid 3 -dbgbase 0x80016000
target smp $_TARGETNAME0 $_TARGETNAME1 $_TARGETNAME2 $_TARGETNAME3

$_TARGETNAME0 configure -event gdb-attach {
	cortex_a dbginit
}
$_TARGETNAME1 configure -event gdb-attach {
	cortex_a dbginit
}
$_TARGETNAME2 configure -event gdb-attach {
	cortex_a dbginit
}
$_TARGETNAME3 configure -event gdb-attach {
	cortex_a dbginit
}
