source [find target/Cortex-A53/cortexa53.tcl ]

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

if { [info exists ENDIAN] } {
   set  _ENDIAN $ENDIAN
} else {
  # this defaults to a bigendian
   set  _ENDIAN little
}

if { [info exists CPUTAPID ] } {
   set _CPUTAPID $CPUTAPID
} else {
  # force an error till we get a good number
   set _CPUTAPID 0x4ba00477
}

adapter_nsrst_delay 500
adapter_khz 500
	
# hiSilicon only has one ARM cortex A9 tap. If you get the wrong IDCODE (0x12a,....) 
# your box is open and wired for boundary-scan JTAG. You should rewire it.

# the '477' at the end is indicative for ARM debug TAPs.

jtag newtap $CHIPNAME dap -irlen 4 -ircapture 0x1 -irmask 0x0f -expected-id 0x5ba00477
# This is the tap you see when boundary scan is enabled..


set TARGETNAME $CHIPNAME.dap
# may need to add -endian big|little here ...
target create $TARGETNAME aarch32 -endian little -chain-position $TARGETNAME -dbgbase 0x80010000

# setup working area somewhere in internal RAM
$TARGETNAME configure -work-area-phys 0x80000000 -work-area-size 0x2000

$TARGETNAME configure -event reset-assert-post {
 echo "init debug.."
 aarch32 dbginit
}
$TARGETNAME configure -event reset-assert {
echo "reset init..."
}