#
# Hisilicon SD5115 (T?)
#
# Author : CserSoft
# Version : 1.2.2
#
transport select jtag
if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME sd5115
}
if { [info exists CPUTAPID] } {
set _CPU_TAPID $CPUTAPID
} else {
set _CPU_TAPID 0x4ba00477
}
if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
# this defaults to a bigendian
set _ENDIAN little
}
if { [info exists ETB_TAPID] } {
set _ETB_TAPID $ETB_TAPID
} else {
set _ETB_TAPID 0x410CF231
}
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPU_TAPID
# jtag newtap $_CHIPNAME etb -irlen 4 -expected-id $_ETB_TAPID
set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME cortex_a -endian $_ENDIAN -chain-position $_TARGETNAME
# etm_dummy config $_TARGETNAME
# etb config $_TARGETNAME $_CHIPNAME.etb
proc sd5115_dbginit { target } {
cortex_a dbginit
}
proc getmem32 { addr } {
mem2array atmp 32 $addr 1
return [lindex $atmp 1]
}
proc setmem32 { addr value } {
mww phys $addr $value 1
}
proc andmem32 { addr value } {
set vmem [getmem32 $addr]
return [expr $vmem & $value]
}
proc andmem32w { addr value } {
set vmem [expr [getmem32 $addr] & $value]
mww phys $addr $vmem 1
return $vmem
}
proc ormem32 { addr value } {
set vmem [getmem32 $addr]
return [expr $vmem | $value]
}
proc ormem32w { addr value } {
set vmem [expr [getmem32 $addr] | $value]
mww phys $addr $vmem 1
return $vmem
}
proc sd5115_startcode_offset_0x6EC { } {
andmem32w 0x10180000 0xFFFFFFFE
}
proc sd5115_startcode_offset_0x700 { } {
mww phys 0x1018000C 0xFFFFFFFF 1
}
proc sd5115_startcode_offset_0x710 { } {
ormem32w 0x10180054 0xFF
ormem32w 0x10180000 0x1
}
proc sd5115_startcode_offset_0xFAD4 { } {
setmem32 0x10100144 [expr [andmem32 0x10100144 0xFFF803FF] | 0x400]
}
proc sd5115_startcode_offset_0xFAF4 { } {
set vcpuid [getmem32 0x10100800]
if { $vcpuid == 0x51151100 } {
ormem32w 0x13000000 0x80000
ormem32w 0x10106008 0xC0
ormem32w 0x10106008 0x300
} elseif { $vcpuid == 0x51152100 } {
ormem32w 0x13000000 0x60000
ormem32w 0x10108008 0xF0
} else {
ormem32w 0x130001C8 0x100
ormem32w 0x10106008 0xC00
andmem32w 0x13000000 0xFFFFFFFB
andmem32w 0x130001C8 0xFFFFFFDF
ormem32w 0x10106008 0x3000
andmem32w 0x13000000 0xFFFDFFFF
andmem32w 0x130001C8 0xFFFFFFBF
}
}
proc sd5115_startcode_offset_0xFBD8 { } {
set vcpuid [getmem32 0x10100800]
if { $vcpuid != 0x51151100 } {
if { $vcpuid == 0x51152100 } {
setmem32 0x10400500 0x1FFF800
andmem32w 0x10100134 0xFFFFFFFC
andmem32w 0x10107008 0xDDFFFFFF
ormem32w 0x10107004 0x22000000
ormem32w 0x10107000 0x22000000
andmem32w 0x10108008 0xFFF7FFFF
ormem32w 0x10108004 0x80000
ormem32w 0x10108000 0x80000
andmem32w 0x10100144 0x3FFFFFFF
} else {
setmem32 0x10400500 0x1FFF800
andmem32w 0x10100134 0xFFFFFFFC
ormem32w 0x10107004 0x18000
andmem32w 0x10107000 0xFFFE7FFF
ormem32w 0x10107000 0x18000
andmem32w 0x1300016C 0xFFFFFFFC
}
}
}
proc sd5115_startcode_offset_0xFCD4 { } {
set vcpuid [getmem32 0x10100800]
if { $vcpuid == 0x51151100 } {
andmem32w 0x1010012C 0xFFBFFFFF
andmem32w 0x10100138 0xFFFFFFBF
ormem32w 0x10100080 0x9
andmem32w 0x1010013C 0xFFFFEFFF
setmem32 0x1010005C 0x81020248
while { [andmem32 0x10100038 0x10000] != 0x10000 } {sleep 1}
ormem32w 0x1010007C 0x9
ormem32w 0x10100148 0x2
ormem32w 0x1010012C 0x400000
ormem32w 0x10100138 0x40
} elseif { $vcpuid == 0x51152100 } {
if { [andmem32 0x10100190 1] == 1 } {
andmem32w 0x1010012C 0xFFBFFFFF
andmem32w 0x10100138 0xFFFFFFBF
ormem32w 0x10100080 0x9
andmem32w 0x10100144 0xFEFFFFFF
andmem32w 0x10100140 0xFFFFCFFF
ormem32w 0x10100140 0x40000000
setmem32 0x10100074 0x81028249
while { [andmem32 0x10100038 0x40000] != 0x40000 } {sleep 1}
ormem32w 0x1010007C 0x9
ormem32w 0x10100148 0x2
ormem32w 0x1010012C 0x400000
ormem32w 0x10100138 0x40
} else {
while { [andmem32 0x10100038 0x20000] != 0x20000 } {sleep 1}
}
} else {
andmem32w 0x1010012C 0xFFBFFFFF
andmem32w 0x10100138 0xFFFFFFBF
ormem32w 0x10100080 0x9
setmem32 0x1010011C 0x81028648
while { [andmem32 0x10100038 0x20000] != 0x20000 } {sleep 1}
ormem32w 0x1010007C 0x9
ormem32w 0x10100148 0x2
ormem32w 0x1010012C 0x400000
ormem32w 0x10100138 0x40
}
}
proc sd5115_startcode_offset_0xFED4 { } {
set vcpuid [getmem32 0x10100800]
if { $vcpuid == 0x51151100 } {
setmem32 0x10102010 1
setmem32 0x1010201C 0x8DF40630
setmem32 0x10102020 0x10184
setmem32 0x1010202C 0x132
setmem32 0x10102040 0x80000000
setmem32 0x10102050 0x62330A08
setmem32 0x10102054 0x7F525616
setmem32 0x1010205C 0x4BE58352
setmem32 0x101020F4 1
setmem32 0x10102058 0x6230A000
setmem32 0x10102004 0
while { [andmem32 0x10102000 4] != 0 } { sleep 1 }
setmem32 0x10102404 0x80000000
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102418 0xDC000
setmem32 0x10102584 0x5D
setmem32 0x1010240C 0x3008401
setmem32 0x10102444 0x48B
setmem32 0x10102448 0x51106644
setmem32 0x1010244C 0x1A81629A
setmem32 0x10102450 0x100220C8
setmem32 0x10102454 0x1520
setmem32 0x10102458 6
setmem32 0x1010245C 0
setmem32 0x10102460 0
setmem32 0x101025C0 0x44000887
setmem32 0x10102440 0xF008003E
setmem32 0x10102468 0x1001541
setmem32 0x10102404 0xFFF3
while { [andmem32 0x10102410 0x80000FFF] != 0x80000FFF } { sleep 1 }
setmem32 0x10102058 0x6230A05F
setmem32 0x10102020 0x410185
setmem32 0x1010201C 0x8DF40630
setmem32 0x10102200 0x305133
setmem32 0x10102204 0x3062CC
} elseif { $vcpuid == 0x51152100 } {
if { [andmem32 0x10100190 1] == 1 } {
setmem32 0x10102010 1
setmem32 0x1010201C 0x80000600
setmem32 0x10102020 0x584
setmem32 0x1010202C 0x142
setmem32 0x10102040 0x80000000
setmem32 0x10102050 0x63440E0A
setmem32 0x10102054 0xFF526720
setmem32 0x10102058 0x6240A000
setmem32 0x1010205C 0xFFDFF5F2
setmem32 0x101020F4 0x21
setmem32 0x101020AC 0x3000501
setmem32 0x10102004 0
while { [andmem32 0x10102000 4] != 0 } { sleep 1 }
setmem32 0x10102404 0x80000000
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102418 0x5C000
setmem32 0x1010248C 0xF01E78
setmem32 0x1010241C 0x1F40FA10
setmem32 0x10102420 0x61A808CA
setmem32 0x10102428 0xC83D090
setmem32 0x1010242C 0x1F4186A0
setmem32 0x10102444 0x48B
setmem32 0x10102448 0x6D538844
setmem32 0x1010244C 0x22820282
setmem32 0x10102450 0x1002EA00
setmem32 0x10102454 0x1930
setmem32 0x10102458 0x42
setmem32 0x1010245C 8
setmem32 0x10102460 0
setmem32 0x10102464 0x210000
setmem32 0x10102468 0x210035C3
setmem32 0x10102584 0x2D
setmem32 0x101025C0 0x44000E81
setmem32 0x10102600 0x44000E81
setmem32 0x10102440 0xF000603E
setmem32 0x10102404 0xFFF3
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102058 0x6240A079
setmem32 0x10102200 0x304132
setmem32 0x10102204 0x306132
setmem32 0x10102208 0x304066
setmem32 0x10102210 0x306132
} else {
setmem32 0x10102010 1
setmem32 0x1010201C 0x80000601
setmem32 0x10102020 0x580
setmem32 0x1010202C 0x142
setmem32 0x10102040 0x80000000
setmem32 0x10102050 0xC466150F
setmem32 0x10102054 0xFF545540
setmem32 0x10102058 0x84610000
setmem32 0x1010205C 0xFFDFF4F4
setmem32 0x101020F4 0x21
setmem32 0x101020AC 0x3000501
setmem32 0x10102004 0
while { [andmem32 0x10102000 4] != 0 } { sleep 1 }
setmem32 0x10102404 0x80000000
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102418 0x5C000
setmem32 0x1010248C 0xF01860
setmem32 0x1010241C 0x1900C810
setmem32 0x10102420 0x4E200708
setmem32 0x10102428 0xA030D40
setmem32 0x1010242C 0x19013880
setmem32 0x10102444 0x48B
setmem32 0x10102448 0x550F6644
setmem32 0x1010244C 0x22820202
setmem32 0x10102450 0x1002EA00
setmem32 0x10102454 0x1510
setmem32 0x10102458 0x42
setmem32 0x1010245C 0
setmem32 0x10102460 0
setmem32 0x10102464 0x210000
setmem32 0x10102468 0x210035C3
setmem32 0x10102584 0x2D
setmem32 0x101025C0 0x44000E81
setmem32 0x10102600 0x44000E81
setmem32 0x10102440 0xF008603E
setmem32 0x10102404 0xFFF3
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102058 0x846100C3
setmem32 0x10102200 0x304132
setmem32 0x10102204 0x306132
setmem32 0x10102208 0x304066
setmem32 0x10102210 0x306132
}
} else {
setmem32 0x10102010 1
setmem32 0x1010201C 0xE92E0601
setmem32 0x10102020 0x1F180
setmem32 0x1010202C 0x132
setmem32 0x10102040 0x80000000
setmem32 0x10102050 0xC466130E
setmem32 0x10102054 0xFF535625
setmem32 0x1010205C 0x7E58484
setmem32 0x101020F4 1
setmem32 0x10102058 0x74511000
setmem32 0x101020AC 0x3000501
setmem32 0x10102004 0
while { [andmem32 0x10102000 4] != 0 } { sleep 1 }
setmem32 0x10102404 0x80000000
while { [andmem32 0x10102410 1] != 1 } { sleep 1 }
setmem32 0x10102418 0xDC000
setmem32 0x1010240C 0x3008401
setmem32 0x10102444 0x48B
setmem32 0x10102448 0x4D0E6644
setmem32 0x1010244C 0x1A812A30
setmem32 0x10102450 0x1001A0C8
setmem32 0x10102454 0x1320
setmem32 0x10102458 0x42
setmem32 0x1010245C 0
setmem32 0x10102460 0
setmem32 0x10102468 0x11001547
setmem32 0x101025C0 0x44000887
setmem32 0x10102600 0x44000E81
setmem32 0x10102440 0xF008003E
setmem32 0x10102584 0x1D
setmem32 0x10102404 0xFFF3
while { [andmem32 0x10102410 0x80000FFF] != 0x80000FFF } { sleep 1 }
setmem32 0x10102058 0x7450F09E
setmem32 0x10102020 0x40EF01
setmem32 0x101020F8 0
setmem32 0x10102200 0x305133
setmem32 0x10102204 0x306266
setmem32 0x10102208 0x306066
setmem32 0x1010220C 0
setmem32 0x1010201C 0xB9D60601
}
}
proc sd5115_hwinit { } {
halt
#enter Supervisor mode
reg cpsr 0x1D3
arm mcr 15 0 8 7 0 0
arm mcr 15 0 7 5 0 0
arm mcr 15 2 0 0 0 0
set v5 [expr ([arm mrc 15 1 0 0 0] >> 13) & 0x1ff]
set v6 0
while {$v6 < 4} {
set v7 0
while {$v7 <= $v5} {
set vtmp [expr ($v6 << 30) | 32 * $v7]
set v7 [incr $v7]
arm mcr 15 0 7 6 2 $vtmp
}
set v6 [incr $v6]
}
if { [expr [arm mrc 15 0 0 0 5] & 0xf] != 0} {
echo "Error 1 !"
return
}
arm mcr 15 0 1 0 0 [expr [arm mrc 15 0 0 0 1] & 0xFFFFDFF8 | 0x802]
if { [expr [arm mrc 15 0 0 0 5] & 0xf] != 0} {
sd5115_startcode_offset_0x6EC
sd5115_startcode_offset_0x700
sd5115_startcode_offset_0x710
}
arm mcr 15 0 1 0 0 [expr [arm mrc 15 0 1 0 0] | 0x1000]
setmem32 0x10A30004 0x00000355
ormem32w 0x10A20100 0x2
sd5115_startcode_offset_0xFAD4
setmem32 0x1010007C 0xFFFFFFFF
setmem32 0x1010008C 0xFFFFFFFF
setmem32 0x1010012C 0xFFFFFFFF
setmem32 0x10100130 0xFE7FFFFF
ormem32w 0x10100138 0x7F
ormem32w 0x10100140 0x80000000
set vcpuid [getmem32 0x10100800]
if { $vcpuid == 0x51152100 } {
if { [expr [getmem32 0x10100190] & 1] == 1 } {
mww phys 0x1010005C 0x8103844D 1
}
mww phys 0x1010005C 0x8103444D 1
}
while { [andmem32 0x10100038 0x10000] != 0x10000 } {sleep 1}
while { [andmem32 0x10100038 0x40000] != 0x40000 } {sleep 1}
setmem32 0x1010013C [expr [andmem32 0x1010013C 0xFFFFFFE3] | 0x10]
sd5115_startcode_offset_0xFCD4
andmem32w 0x1010013C 0xFFFFF3FF
andmem32w 0x10100138 0xFFDFFFFF
andmem32w 0x10100138 0xFFF7FFFF
setmem32 0x10100054 0xFFFFFFE0
setmem32 0x10100050 0x7FF00
ormem32w 0x10100000 0x4
while { [andmem32 0x10100000 0x4] != 0x4 } {sleep 1}
sd5115_startcode_offset_0xFAF4
sd5115_startcode_offset_0xFBD8
sd5115_startcode_offset_0xFED4
echo "Hardware initialization is complete!"
}
$_TARGETNAME configure -event reset-assert-post "sd5115_dbginit $_TARGETNAME"
# init
# dap apsel 1