300 lines
12 KiB
Plaintext
300 lines
12 KiB
Plaintext
source [find interface/jlink.cfg]
|
|
|
|
adapter driver jlink
|
|
transport select swd
|
|
|
|
if { [info exists CHIPNAME] } {
|
|
set _CHIPNAME $CHIPNAME
|
|
} else {
|
|
set _CHIPNAME rtl8710
|
|
}
|
|
|
|
if { [info exists ENDIAN] } {
|
|
set _ENDIAN $ENDIAN
|
|
} else {
|
|
set _ENDIAN little
|
|
}
|
|
|
|
if { [info exists WORKAREASIZE] } {
|
|
set _WORKAREASIZE $WORKAREASIZE
|
|
} else {
|
|
set _WORKAREASIZE 0x800
|
|
}
|
|
|
|
if { [info exists CPUTAPID] } {
|
|
set _CPUTAPID $CPUTAPID
|
|
} else {
|
|
set _CPUTAPID 0x2ba01477
|
|
}
|
|
|
|
swd newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
|
|
|
|
set _TARGETNAME $_CHIPNAME.cpu
|
|
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
|
|
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
|
|
|
|
# todo: get work area from makefile
|
|
$_TARGETNAME configure -work-area-phys 0x10001500 -work-area-size $_WORKAREASIZE -work-area-backup 0
|
|
|
|
adapter speed 3000
|
|
adapter srst delay 100
|
|
cortex_m reset_config vectreset
|
|
|
|
$_TARGETNAME configure -event reset-init {amebaz_init}
|
|
set rtl8710_flasher_firmware_ptr 0x10001500
|
|
set rtl8710_flasher_buffer 0x10008000
|
|
set rtl8710_flasher_buffer_size 204800
|
|
set rtl8710_flasher_sector_size 4096
|
|
|
|
set rtl8710_flasher_code [list 0x4880e92d 0x5d80f5ad 0xb673b085 0x0810f10d 0xf8482300 0xf04f3c04 0x4e6d4380 0x3210f8d3 0x0f10f013 0x486bd001 0x4c6b47b0 0x22004d6b 0x7180f44f 0x47a02010 0x20004b69 0x22014798 0x7180f44f 0x47a02010 0x21002201 0x4c664b65 0x4798200a 0x46284b65 0x4b654798 0x47982002 0x0049f895 0x2103aa03 0xf81847a0 0xf8183c02 0xf8182c03 0x485f1c04 0x682947b0 0x47b0485e 0x796a68ab 0x485d7929 0x7feb47b0 0x7f297f6a 0x485b9300 0x47b07fab 0x21004b5a 0x4798201c 0x47b04859 0x20004b59 0x46a14798 0x23004c58 0x68236023 0x6863b193 0xf2002b05 0xa2018086 0xf023f852 0x100015e1 0x100015f3 0x10001601 0x10001627 0x1000162b 0x10001659 0xe7e8bf00 0x0049f895 0x2104aa03 0xf85847c8 0x60e33c04 0x2100e7dd 0x4b474608 0x48474798 0xe7d647b0 0x4b446921 0x47982002 0x6922e7d1 0x6200f102 0xf10358d1 0xf5025280 0x33044200 0x69626211 0xd8f2429a 0x2300e7c3 0x6961e7f9 0x6922483b 0xf8df4f3b 0x47b0b0f0 0x0a00f04f 0x45536963 0x4839d801 0x6920e7da 0x0207eb0a 0x21044450 0xf10a47d8 0xe7f10a04 0x69236923 0x44136962 0x0b1b3b01 0x69622700 0xd9a042ba 0xf1026922 0x59d26200 0x2000f8c8 0x1bd26962 0xbf982a04 0x69226960 0xbf94443a 0x20041bc0 0x3f12ebb3 0x46c6d38d 0x0c00f04f 0xd1014584 0xe7e23704 0x010ceb07 0x0a01eb04 0x2b01f81e 0xb020f89a 0xd007455a 0x3020f89a 0x47b0481c 0x60a32301 0xe77460e7 0x0c01f10c 0x2301e7e6 0xe76e60a3 0x000004dd 0x10001730 0x00009b65 0x10000dec 0x00007d15 0x000042fd 0x00007465 0x00007b81 0x00007ca1 0x10001760 0x10001783 0x1000179b 0x100017ce 0x0000784d 0x10001806 0x00005811 0x10008000 0x00007755 0x10001828 0x1000184d 0x10008020 0x00007661 0x10001884 0x100018ac 0x414c465b 0x52454853 0x6c46205d 0x20687361 0x69726570 0x72656870 0x61206c61 0x6165726c 0x65207964 0x6c62616e 0x2e2e6465 0x000a3f2e 0x414c465b 0x205d4853 0x69766544 0x49206563 0x25203a44 0x20583230 0x58323025 0x32302520 0x5b000a58 0x53414c46 0x56205d48 0x6f646e65 0x30203a72 0x38302578 0x5b000a58 0x53414c46 0x43205d48 0x69666e6f 0x4d203a67 0x3d65646f 0x202c6425 0x636f6c43 0x64253d6b 0x6552202c 0x6d436461 0x78303d64 0x58323025 0x465b000a 0x4853414c 0x6954205d 0x676e696d 0x6153203a 0x656c706d 0x616c6544 0x64253d79 0x7544202c 0x43796d6d 0x656c6379 0x255b3d73 0x64252c64 0x5d64252c 0x465b000a 0x4853414c 0x6c42205d 0x206b636f 0x746f7270 0x69746365 0x63206e6f 0x7261656c 0x000a6465 0x414c465b 0x52454853 0x7546205d 0x63206c6c 0x20706968 0x73617265 0x6f632065 0x656c706d 0x0a646574 0x4c465b00 0x45485341 0x53205d52 0x74726174 0x20676e69 0x74697277 0x666f2065 0x20642520 0x65747962 0x74612073 0x66666f20 0x20746573 0x30257830 0x000a5838 0x414c465b 0x52454853 0x7257205d 0x20657469 0x706d6f63 0x6574656c 0x75732064 0x73656363 0x6c756673 0x000a796c 0x5245565b 0x5d594649 0x73696d20 0x6374616d 0x74612068 0x66666f20 0x20746573 0x203a7825 0x73616c66 0x30253d68 0x62207832 0x253d6675 0x0a783230 0x00000000 ]
|
|
|
|
set rtl8710_flasher_command_read_id 0
|
|
set rtl8710_flasher_command_mass_erase 1
|
|
set rtl8710_flasher_command_sector_erase 2
|
|
set rtl8710_flasher_command_read 3
|
|
set rtl8710_flasher_command_write 4
|
|
set rtl8710_flasher_command_verify 5
|
|
|
|
set rtl8710_flasher_mac_address_offset 0xA088
|
|
|
|
set rtl8710_flasher_ready 0
|
|
set rtl8710_flasher_capacity 0
|
|
set rtl8710_flasher_auto_erase 0
|
|
set rtl8710_flasher_auto_verify 0
|
|
set rtl8710_flasher_auto_erase_sector 0
|
|
|
|
proc rtl8710_flasher_init {} {
|
|
global rtl8710_flasher_ready rtl8710_flasher_firmware_ptr
|
|
global rtl8710_flasher_buffer rtl8710_flasher_capacity
|
|
global rtl8710_flasher_code
|
|
|
|
if {!$rtl8710_flasher_ready} {
|
|
set buf_ctrl [expr {$rtl8710_flasher_buffer + 0x00}]
|
|
set buf_status [expr {$rtl8710_flasher_buffer + 0x08}]
|
|
set buf_id [expr {$rtl8710_flasher_buffer + 0x0C}]
|
|
|
|
halt
|
|
# init buffer control regs
|
|
mww $buf_status 0
|
|
mww $buf_ctrl 1
|
|
|
|
# load and start flasher
|
|
write_memory $rtl8710_flasher_firmware_ptr 32 $rtl8710_flasher_code
|
|
reg faultmask 1
|
|
reg sp 0x1003ef00
|
|
reg pc $rtl8710_flasher_firmware_ptr
|
|
resume
|
|
rtl8710_flasher_wait
|
|
|
|
set id [rtl8710_flasher_mrw $buf_id]
|
|
set rtl8710_flasher_capacity [expr {1 << (($id >> 16) & 0xFF)}]
|
|
set rtl8710_flasher_ready 1
|
|
}
|
|
}
|
|
|
|
proc rtl8710_flasher_mrw {reg} {
|
|
read_memory $reg 32 1
|
|
}
|
|
|
|
proc rtl8710_flasher_wait {} {
|
|
global rtl8710_flasher_buffer
|
|
set addr [expr {$rtl8710_flasher_buffer + 0x00}]
|
|
while {[rtl8710_flasher_mrw $addr]} {}
|
|
}
|
|
|
|
proc rtl8710_flasher_load_block {local_filename offset length} {
|
|
global rtl8710_flasher_buffer
|
|
set buffer_addr [expr {$rtl8710_flasher_buffer + 0x20}]
|
|
load_image $local_filename [expr {$buffer_addr - $offset}] bin $buffer_addr $length
|
|
}
|
|
|
|
proc rtl8710_flasher_block {command offset len} {
|
|
global rtl8710_flasher_buffer
|
|
global rtl8710_flasher_command_read rtl8710_flasher_command_write rtl8710_flasher_command_verify
|
|
|
|
# select command type
|
|
switch $command {
|
|
"read" {set cmd_type $rtl8710_flasher_command_read}
|
|
"write" {set cmd_type $rtl8710_flasher_command_write}
|
|
"verify" {set cmd_type $rtl8710_flasher_command_verify}
|
|
default {error "Unknown command type: $command"}
|
|
}
|
|
|
|
mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd_type
|
|
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000
|
|
mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset
|
|
mww [expr {$rtl8710_flasher_buffer + 0x14}] $len
|
|
mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001
|
|
rtl8710_flasher_wait
|
|
|
|
set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x08}]]
|
|
if {[expr {$status > 0}]} {
|
|
if {$command eq "verify"} {
|
|
set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]]
|
|
set status [expr {$status + $offset}]
|
|
}
|
|
error "$command error, offset $status"
|
|
}
|
|
}
|
|
|
|
proc rtl8710_flasher_read_block {offset len} {
|
|
rtl8710_flasher_block "read" $offset $len
|
|
}
|
|
|
|
proc rtl8710_flasher_write_block {offset len} {
|
|
rtl8710_flasher_block "write" $offset $len
|
|
}
|
|
|
|
proc rtl8710_flasher_verify_block {offset len} {
|
|
rtl8710_flasher_block "verify" $offset $len
|
|
}
|
|
|
|
proc rtl8710_flash_read_id {} {
|
|
global rtl8710_flasher_buffer rtl8710_flasher_capacity
|
|
global rtl8710_flasher_command_read_id
|
|
|
|
rtl8710_flasher_init
|
|
|
|
# send read ID command
|
|
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id
|
|
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0
|
|
mww [expr {$rtl8710_flasher_buffer + 0x00}] 1
|
|
rtl8710_flasher_wait
|
|
|
|
set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]]
|
|
|
|
set manufacturer_id [format "0x%02X" [expr {$id & 0xFF}]]
|
|
set memory_type [format "0x%02X" [expr {($id >> 8) & 0xFF}]]
|
|
set memory_capacity [expr {2 ** (($id >> 16) & 0xFF)}]
|
|
|
|
echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes"
|
|
}
|
|
|
|
proc rtl8710_flash_erase {type {offset 0}} {
|
|
global rtl8710_flasher_buffer
|
|
global rtl8710_flasher_command_mass_erase rtl8710_flasher_command_sector_erase
|
|
|
|
rtl8710_flasher_init
|
|
|
|
if {$type eq "mass"} {
|
|
set cmd $rtl8710_flasher_command_mass_erase
|
|
} elseif {$type eq "sector"} {
|
|
set cmd $rtl8710_flasher_command_sector_erase
|
|
mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset
|
|
} else {
|
|
error "Unknown erase type: $type"
|
|
}
|
|
|
|
mww [expr {$rtl8710_flasher_buffer + 0x04}] $cmd
|
|
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0
|
|
mww [expr {$rtl8710_flasher_buffer + 0x00}] 1
|
|
rtl8710_flasher_wait
|
|
}
|
|
|
|
proc rtl8710_flash_mass_erase {} {
|
|
rtl8710_flash_erase "mass"
|
|
}
|
|
|
|
proc rtl8710_flash_sector_erase {offset} {
|
|
rtl8710_flash_erase "sector" $offset
|
|
}
|
|
|
|
proc rtl8710_flash_read {local_filename loc size} {
|
|
global rtl8710_flasher_buffer rtl8710_flasher_buffer_size
|
|
rtl8710_flasher_init
|
|
|
|
set tmp "/tmp/_rtl8710_flasher.bin"
|
|
for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} {
|
|
set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}]
|
|
set flash_offset [expr {$loc + $offset}]
|
|
echo "read $flash_offset"
|
|
rtl8710_flasher_read_block $flash_offset $len
|
|
dump_image $tmp [expr {$rtl8710_flasher_buffer + 0x20}] $len
|
|
exec dd conv=notrunc if=$tmp of=$local_filename bs=1 seek=$offset
|
|
echo "read $len bytes"
|
|
}
|
|
file delete -force $tmp
|
|
}
|
|
|
|
proc rtl8710_flash_write {local_filename loc} {
|
|
global rtl8710_flasher_buffer_size rtl8710_flasher_sector_size
|
|
global rtl8710_flasher_auto_erase rtl8710_flasher_auto_verify
|
|
global rtl8710_flasher_auto_erase_sector
|
|
rtl8710_flasher_init
|
|
set size [file size $local_filename]
|
|
|
|
for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} {
|
|
set len [expr {($size - $offset) < $rtl8710_flasher_buffer_size ? ($size - $offset) : $rtl8710_flasher_buffer_size}]
|
|
set flash_offset [expr {$loc + $offset}]
|
|
echo "write offset $flash_offset"
|
|
rtl8710_flasher_load_block $local_filename $offset $len
|
|
|
|
if {$rtl8710_flasher_auto_erase} {
|
|
set start_sector [expr {$flash_offset / $rtl8710_flasher_sector_size}]
|
|
set end_sector [expr {($flash_offset + $len - 1) / $rtl8710_flasher_sector_size}]
|
|
# erase any new sectors we encounter
|
|
for {set sector $start_sector} {$sector <= $end_sector} {incr sector} {
|
|
set sector_addr [expr {$sector * $rtl8710_flasher_sector_size}]
|
|
if {$sector_addr >= $rtl8710_flasher_auto_erase_sector} {
|
|
rtl8710_flash_sector_erase $sector_addr
|
|
set rtl8710_flasher_auto_erase_sector [expr {$sector_addr + $rtl8710_flasher_sector_size}]
|
|
}
|
|
}
|
|
}
|
|
|
|
rtl8710_flasher_write_block $flash_offset $len
|
|
echo "wrote $len bytes"
|
|
|
|
if {$rtl8710_flasher_auto_verify} {
|
|
echo "verify offset $flash_offset"
|
|
rtl8710_flasher_verify_block $flash_offset $len
|
|
}
|
|
}
|
|
}
|
|
|
|
proc rtl8710_flash_verify {local_filename loc} {
|
|
global rtl8710_flasher_buffer_size
|
|
rtl8710_flasher_init
|
|
set size [file size $local_filename]
|
|
for {set offset 0} {$offset < $size} {set offset [expr {$offset + $rtl8710_flasher_buffer_size}]} {
|
|
set len [expr {$size - $offset}]
|
|
if {[expr {$len > $rtl8710_flasher_buffer_size}]} {
|
|
set len $rtl8710_flasher_buffer_size
|
|
}
|
|
set flash_offset [expr {$loc + $offset}]
|
|
echo "read offset $flash_offset"
|
|
rtl8710_flasher_load_block $local_filename $offset $len
|
|
echo "verify offset $flash_offset"
|
|
rtl8710_flasher_verify_block $flash_offset $len
|
|
}
|
|
}
|
|
|
|
|
|
proc rtl8710_flash_read_mac {} {
|
|
global rtl8710_flasher_mac_address_offset rtl8710_flasher_buffer
|
|
|
|
rtl8710_flasher_init
|
|
rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6
|
|
|
|
set mac [read_memory [expr {$rtl8710_flasher_buffer + 0x20}] 8 6]
|
|
set mac_str [join [lmap byte $mac {format %02X $byte}] ":"]
|
|
echo "MAC address: $mac_str"
|
|
}
|
|
|
|
proc rtl8710_flash_auto_erase {on} {
|
|
global rtl8710_flasher_auto_erase
|
|
set rtl8710_flasher_auto_erase [expr {$on != 0}]
|
|
echo "auto erase [expr {$on ? "on" : "off"}]"
|
|
}
|
|
|
|
proc rtl8710_flash_auto_verify {on} {
|
|
global rtl8710_flasher_auto_verify
|
|
set rtl8710_flasher_auto_verify [expr {$on != 0}]
|
|
echo "auto verify [expr {$on ? "on" : "off"}]"
|
|
}
|
|
|
|
proc rtl8710_reboot {} {
|
|
mww 0xE000ED0C 0x05FA0007
|
|
}
|
|
|