# _MULTI_TARGETS:
#   0 - for debug single CPU. Start openocd locally.
#   1 - for debug multiple CPUs. Start openocd (need version >= 0.11.0 for e24) before and set "Remote Target" port.
set _MULTI_TARGETS	0
set _JLINK		0
set _CHIPNAME		JH8100

# "adapter_khz" is DEPRECATED in openocd v0.11.0, replace with "adapter speed" if not available
#adapter_khz   4000
adapter speed   2000
# listen on all interfaces for incoming TCP/IP connections, useful for multiple targets (_MULTI_TARGETS == 1)
bindto 0.0.0.0

if { $_JLINK } {
	#interface jlink
	adapter driver jlink
	# Select a specific device if more than one connected
	#jlink serial 4294967295
} else {
	#source [find interface/ftdi/olimex-arm-usb-tiny-h.cfg]
	#source olimex-arm-usb-tiny-h.cfg
	# Select a specific device if more than one connected
	interface ftdi
	ftdi_device_desc "Olimex OpenOCD JTAG ARM-USB-TINY-H"
	ftdi_vid_pid 0x15ba 0x002a

	ftdi_serial "OL570962"

	ftdi_layout_init 0x0808 0x0a1b
	ftdi_layout_signal nSRST -oe 0x0200
	ftdi_layout_signal nTRST -data 0x0100 -oe 0x0100
	ftdi_layout_signal LED -data 0x0800
}


transport select jtag

#set remote interrupt-on-connect off
## Follow chain order
jtag newtap RV64ABCDFHIMSU cpu -irlen 5 -expected-id 0x08100cfd -disable
jtag newtap RV32ACFIMUX cpu -irlen 5 -expected-id 0x08100cfd -disable

source [find jrc.cfg]

target create RV32ACFIMUX.hart0 riscv -chain-position RV32ACFIMUX.cpu -coreid 0 -gdb-port 3341
target create RV64ABCDFHIMSU.core0 riscv -chain-position RV64ABCDFHIMSU.cpu -coreid 2 -rtos hwthread -gdb-port 3340

init

RV32ACFIMUX.hart0 configure -event gdb-detach {
    jtag tapdisable RV32ACFIMUX.cpu
    jtag tapdisable RV64ABCDFHIMSU.cpu
    shutdown
}

RV64ABCDFHIMSU.core0 configure -event gdb-detach {
    jtag tapdisable RV64ABCDFHIMSU.cpu
    jtag tapdisable RV32ACFIMUX.cpu
    shutdown
}

halt
scan_chain

#echo "load U-Boot SPL .................."
#fast_load_image u-boot-spl.bin 0xb000000
#fast_load

#echo "load U-Boot itb images .................."
#fast_load_image u-boot.itb 0xa0000000
#fast_load

# echo "load Linux kernel image .................."
# fast_load_image Image_165.gz 0x47000000
# fast_load

# echo "load Linux dtb image .................."
# fast_load_image jh8100-fpga_165.dtb 0x46000000
# fast_load

# echo "load rootfs image .................."
# fast_load_image rootfs_165.cpio 0x59000000
# fast_load

echo "Finish loading images.................."

echo "Ready for Remote Connections"
