yes
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
#
|
||||
# OpenOCD script for RTL8710
|
||||
# Copyright (C) 2016 Rebane, rebane@alkohol.ee
|
||||
#
|
||||
|
||||
source [find target/swj-dp.tcl]
|
||||
|
||||
if { [info exists CHIPNAME] } {
|
||||
@@ -29,70 +24,29 @@ if { [info exists CPUTAPID] } {
|
||||
set _CPUTAPID 0x2ba01477
|
||||
}
|
||||
|
||||
swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
|
||||
swd newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID
|
||||
|
||||
set _TARGETNAME $_CHIPNAME.cpu
|
||||
target create $_TARGETNAME cortex_m -endian $_ENDIAN -chain-position $_TARGETNAME
|
||||
dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu
|
||||
target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap
|
||||
|
||||
$_TARGETNAME configure -work-area-phys 0x10001000 -work-area-size $_WORKAREASIZE -work-area-backup 0
|
||||
# todo: get work area from makefile
|
||||
$_TARGETNAME configure -work-area-phys 0x10001500 -work-area-size $_WORKAREASIZE -work-area-backup 0
|
||||
|
||||
adapter_khz 500
|
||||
adapter_nsrst_delay 100
|
||||
adapter speed 4000
|
||||
adapter srst delay 100
|
||||
|
||||
if {![using_hla]} {
|
||||
cortex_m reset_config sysresetreq
|
||||
}
|
||||
|
||||
set rtl8710_flasher_firmware_ptr 0x10001000
|
||||
$_TARGETNAME configure -event reset-init {amebaz_init}
|
||||
set rtl8710_flasher_firmware_ptr 0x10001500
|
||||
set rtl8710_flasher_buffer 0x10008000
|
||||
set rtl8710_flasher_buffer_size 262144
|
||||
set rtl8710_flasher_buffer_size 204800
|
||||
set rtl8710_flasher_sector_size 4096
|
||||
|
||||
array set rtl8710_flasher_code {
|
||||
0 0xB671B57F 1 0x25FF4B58 2 0x6B196B1A 3 0x7040F042 4 0x69D96318 5 0xF4414E55
|
||||
6 0x69D97480 7 0xF8D361DC 8 0xF8C32120 9 0xF8D35120 10 0xF8C31124 11 0x47B05124
|
||||
12 0x47B04E4F 13 0x47984B4F 14 0x60104A4F 15 0x484F47B0 16 0x60012100 17 0x2C006804
|
||||
18 0x4D4DD0FC 19 0xB93E682E 20 0x60264C49 21 0x47B04E46 22 0x47984B46 23 0xE7ED6020
|
||||
24 0x2B01682B 25 0x4E42D109 26 0x4C4647B0 27 0x47A02006 28 0x47904A45 29 0x47A020C7
|
||||
30 0x682AE00D 31 0xD10E2A02 32 0x47B04E3B 33 0x20064C3F 34 0x483F47A0 35 0x493F4780
|
||||
36 0x68084D3F 37 0x47B047A8 38 0x47A02004 39 0x6828E7CE 40 0xD1132803 41 0x47A04C32
|
||||
42 0x24004838 43 0x4E396805 44 0x68311960 45 0xD206428C 46 0x4B384A37 47 0x221018A1
|
||||
48 0x34104798 49 0x4D2AE7F3 50 0xE7B847A8 51 0x29046829 52 0x2400D11B 53 0x6806482F
|
||||
54 0xD2B042B4 55 0x47A84D24 56 0x20064E28 57 0x4B2847B0 58 0x49284798 59 0x680A4B2A
|
||||
60 0x18A018E1 61 0xF44F4B2A 62 0x47987280 63 0x200447A8 64 0xF50447B0 65 0x47A87480
|
||||
66 0x682CE7E4 67 0xD1232C05 68 0x47984B17 69 0x4D1F2400 70 0x4294682A 71 0x481BD28F
|
||||
72 0x68012210 73 0x18604E1D 74 0x47B04669 75 0x1B19682B 76 0xBF282910 77 0x23002110
|
||||
78 0xD011428B 79 0xF81D4A16 80 0x18A05003 81 0x42B55CC6 82 0x3301D101 83 0x4A15E7F4
|
||||
84 0x60112101 85 0xE7726054 86 0x25014E12 87 0xE76E6035 88 0x47A84D03 89 0xE7D63410
|
||||
90 0x40000200 91 0x100011BD 92 0x100013DD 93 0x10001289 94 0x1000800C 95 0x10008000
|
||||
96 0x10008004 97 0x1000130D 98 0x100013ED 99 0x10008010 100 0x10001335 101 0x10008014
|
||||
102 0x10008020 103 0x10001221 104 0x10001375 105 0x10008008 106 0x6A5A4B03 107 0xD0FB0512
|
||||
108 0x0060F893 109 0xBF004770 110 0x40006000 111 0x6B194B17 112 0xF4416B1A 113 0x63187040
|
||||
114 0x69186919 115 0x0110F041 116 0xF8D36119 117 0x220000C0 118 0x0106F020 119 0x00C0F8D3
|
||||
120 0x10C0F8C3 121 0x00C0F8D3 122 0x0101F040 123 0x00C0F8D3 124 0x10C0F8C3 125 0x43BCF503
|
||||
126 0x609A6899 127 0x20016AD9 128 0x691962DA 129 0x69596118 130 0x61592102 131 0x619A6999
|
||||
132 0x61DA69D9 133 0x64DA6CD9 134 0xBF004770 135 0x40000200 136 0x460EB570 137 0xB34A4614
|
||||
138 0xF3C04B15 139 0x681A4507 140 0x7240F44F 141 0x685A601A 142 0xF3C02103 143 0x2C102207
|
||||
144 0x2410BF28 145 0x605CB2C0 146 0x1060F883 147 0x5060F883 148 0xF8832101 149 0xF8832060
|
||||
150 0x689A0060 151 0x60992500 152 0x47984B08 153 0x35015570 154 0x42A2B2AA 155 0x4804D3F8
|
||||
156 0xF0116A81 157 0xD1FA0301 158 0x60836881 159 0xBD704620 160 0x40006000 161 0x100011A9
|
||||
162 0x4C10B5F8 163 0x68232003 164 0x7340F44F 165 0x68636023 166 0x60602101 167 0x68A3229F
|
||||
168 0x60A14D0B 169 0x2060F884 170 0x460647A8 171 0x460747A8 172 0x040347A8 173 0x2707EA43
|
||||
174 0x0006EA47 175 0x4B036AA1 176 0x0201F011 177 0x6899D1FA 178 0xBDF8609A 179 0x40006000
|
||||
180 0x100011A9 181 0x4C0BB510 182 0x68232001 183 0x7340F44F 184 0x68636023 185 0x60602105
|
||||
186 0x60A068A2 187 0xF8844A06 188 0x47901060 189 0x4B036AA1 190 0x0201F011 191 0x6899D1FA
|
||||
192 0xBD10609A 193 0x40006000 194 0x100011A9 195 0x21014B08 196 0xF44F681A 197 0x601A7280
|
||||
198 0x6099689A 199 0x0060F883 200 0x48036A9A 201 0x0101F012 202 0x6883D1FA 203 0x47706081
|
||||
204 0x40006000 205 0x21014B0E 206 0xF44F681A 207 0x601A7280 208 0x2220689A 209 0xF8836099
|
||||
210 0xF3C02060 211 0xF3C04107 212 0xB2C02207 213 0x1060F883 214 0x2060F883 215 0x0060F883
|
||||
216 0x4A036A99 217 0x0001F011 218 0x6893D1FA 219 0x47706090 220 0x40006000 221 0xB36AB530
|
||||
222 0x25014B17 223 0xF44F681C 224 0x601C7480 225 0x2402689C 226 0xF883609D 227 0xF3C04060
|
||||
228 0xF3C04507 229 0xB2C02407 230 0x5060F883 231 0x7F80F5B2 232 0xF44FBF28 233 0xF8837280
|
||||
234 0xF8834060 235 0x20000060 236 0x4C095C0D 237 0xF8843001 238 0xB2855060 239 0xD3F74295
|
||||
240 0x07496A99 241 0x6AA0D5FC 242 0xF0104B03 243 0xD1FA0101 244 0x60996898 245 0xBD304610
|
||||
246 0x40006000 247 0x4B02B508 248 0x07C04798 249 0xBD08D4FB 250 0x100012D5 251 0x4B04B508
|
||||
252 0xF0004798 253 0xB2C10002 254 0xD0F82900 255 0xBF00BD08 256 0x100012D5
|
||||
}
|
||||
set rtl8710_flasher_code [list \n0x489fe92d 0x2300b673 0xf04f9303 0x4e604380 0x3210f8d3 0x0f10f013 0x485ed001 0x4c5e47b0 0x4f5f4d5e 0xf44f2200 0x20107180 0x4b5d47a0 0x47982000 0xf44f2201 0x20107180 0x220147a0 0x4b592100 0x200a4c59 0x4b594798 0x47984628 0x20024b58 0xf8954798 0xaa030049 0x47a02103 0x300ef89d 0x200df89d 0x100cf89d 0x47b04852 0x48526829 0x68ab47b0 0x7929796a 0x47b04850 0x7f6a7feb 0x93007f29 0x7fab484e 0x4b4e47b0 0x201c2100 0x484d4798 0x46a147b0 0xf04f4c4c 0xf8c40a00 0x6823a000 0x6863b193 0xd86c2b05 0xf852a201 0xbf00f023 0x100015d5 0x100015e5 0x100015f3 0x10001619 0x1000161d 0x10001685 0xe7e8bf00 0x0049f895 0x2104aa03 0x9b0347c8 0xe7de60e3 0x46082100 0x47984b3a 0x47b0483a 0x6921e7d7 0x20024b37 0xe7d24798 0xf1026922 0x58d16200 0x5280f103 0x4200f502 0x62113304 0x429a6962 0xe7c4d8f2 0xe7f92300 0x482f6961 0xf8df6922 0x47b0b0bc 0x0800f04f 0x45436963 0x482cd801 0x6920e7db 0x0207eb08 0x21044440 0xf10847d8 0xe7f10804 0x0820f108 0x45436963 0x6963d9a7 0x0308eba3 0xbf982b04 0x69206962 0xf1004b21 0xbf946000 0x0208eba2 0xeb082204 0x44400107 0x28004798 0x2301d0e6 0xf8c460a3 0xe78e800c 0x0800f04f 0x2301e7e0 0xe78860a3 0x000004dd 0x10001748 0x00009b65 0x10000dec 0x10008020 0x00007d15 0x000042fd 0x00007465 0x00007b81 0x00007ca1 0x10001778 0x1000179b 0x100017b3 0x100017e6 0x0000784d 0x1000181e 0x10008000 0x00007755 0x10001840 0x10001865 0x00007661 0x1000189c 0x100016ed 0xb4302a03 0xea41d912 0x07a40400 0x460b4684 0x4619d121 0xf8534660 0xf85c4b04 0x42a55b04 0x3a04d119 0xd8f42a03 0x46194660 0xb17a1e54 0x39011e43 0xe0011902 0xd009429a 0x0f01f813 0xcf01f811 0xd0f74560 0x000ceba0 0x4770bc30 0xbc302000 0x1e544770 0xbf00e7ea 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 ]
|
||||
|
||||
set rtl8710_flasher_command_read_id 0
|
||||
set rtl8710_flasher_command_mass_erase 1
|
||||
@@ -110,183 +64,195 @@ set rtl8710_flasher_auto_verify 0
|
||||
set rtl8710_flasher_auto_erase_sector 0xFFFFFFFF
|
||||
|
||||
proc rtl8710_flasher_init {} {
|
||||
global rtl8710_flasher_firmware_ptr
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_capacity
|
||||
global rtl8710_flasher_ready
|
||||
global rtl8710_flasher_code
|
||||
global rtl8710_flasher_ready rtl8710_flasher_firmware_ptr
|
||||
global rtl8710_flasher_buffer rtl8710_flasher_capacity
|
||||
global rtl8710_flasher_code
|
||||
|
||||
if {[expr {$rtl8710_flasher_ready == 0}]} {
|
||||
echo "initializing RTL8710 flasher"
|
||||
halt
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001
|
||||
array2mem rtl8710_flasher_code 32 $rtl8710_flasher_firmware_ptr [array size rtl8710_flasher_code]
|
||||
reg faultmask 0x01
|
||||
reg sp 0x20000000
|
||||
reg pc $rtl8710_flasher_firmware_ptr
|
||||
resume
|
||||
rtl8710_flasher_wait
|
||||
set id [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]]
|
||||
set rtl8710_flasher_capacity [expr {2 ** [expr {($id >> 16) & 0xFF}]}]
|
||||
set rtl8710_flasher_ready 1
|
||||
echo "RTL8710 flasher initialized"
|
||||
}
|
||||
return ""
|
||||
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} {
|
||||
set value ""
|
||||
mem2array value 32 $reg 1
|
||||
return $value(0)
|
||||
read_memory $reg 32 1
|
||||
}
|
||||
|
||||
proc rtl8710_flasher_wait {} {
|
||||
global rtl8710_flasher_buffer
|
||||
while {[rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x00}]]} { }
|
||||
global rtl8710_flasher_buffer
|
||||
set addr [expr {$rtl8710_flasher_buffer + 0x00}]
|
||||
while {[rtl8710_flasher_mrw $addr]} {}
|
||||
}
|
||||
|
||||
proc rtl8710_flasher_load_block {local_filename offset len} {
|
||||
global rtl8710_flasher_buffer
|
||||
load_image $local_filename [expr {$rtl8710_flasher_buffer + 0x20 - $offset}] bin [expr {$rtl8710_flasher_buffer + 0x20}] $len
|
||||
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} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_command_read
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read
|
||||
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}]} {
|
||||
error "read error, offset $offset"
|
||||
}
|
||||
rtl8710_flasher_block "read" $offset $len
|
||||
}
|
||||
|
||||
proc rtl8710_flasher_write_block {offset len} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_command_write
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_write
|
||||
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}]} {
|
||||
error "write error, offset $offset"
|
||||
}
|
||||
rtl8710_flasher_block "write" $offset $len
|
||||
}
|
||||
|
||||
proc rtl8710_flasher_verify_block {offset len} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_command_verify
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_verify
|
||||
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}]} {
|
||||
set status [rtl8710_flasher_mrw [expr {$rtl8710_flasher_buffer + 0x0C}]]
|
||||
set status [expr {$status + $offset}]
|
||||
error "verify error, offset $status"
|
||||
}
|
||||
rtl8710_flasher_block "verify" $offset $len
|
||||
}
|
||||
|
||||
proc rtl8710_flash_read_id {} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_capacity
|
||||
global rtl8710_flasher_command_read_id
|
||||
rtl8710_flasher_init
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_read_id
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001
|
||||
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 ** [expr {($id >> 16) & 0xFF}]}]
|
||||
echo "manufacturer ID: $manufacturer_id, memory type: $memory_type, memory capacity: $memory_capacity bytes"
|
||||
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 {} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_command_mass_erase
|
||||
rtl8710_flasher_init
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_mass_erase
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001
|
||||
rtl8710_flasher_wait
|
||||
rtl8710_flash_erase "mass"
|
||||
}
|
||||
|
||||
proc rtl8710_flash_sector_erase {offset} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_command_sector_erase
|
||||
rtl8710_flasher_init
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x04}] $rtl8710_flasher_command_sector_erase
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x08}] 0x00000000
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x10}] $offset
|
||||
mww [expr {$rtl8710_flasher_buffer + 0x00}] 0x00000001
|
||||
rtl8710_flasher_wait
|
||||
rtl8710_flash_erase "sector" $offset
|
||||
}
|
||||
|
||||
proc rtl8710_flash_read {local_filename loc size} {
|
||||
global rtl8710_flasher_buffer
|
||||
global rtl8710_flasher_buffer_size
|
||||
rtl8710_flasher_init
|
||||
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_read_block $flash_offset $len
|
||||
dump_image /tmp/_rtl8710_flasher.bin [expr {$rtl8710_flasher_buffer + 0x20}] $len
|
||||
exec dd conv=notrunc if=/tmp/_rtl8710_flasher.bin "of=$local_filename" bs=1 "seek=$offset"
|
||||
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
|
||||
global rtl8710_flasher_sector_size
|
||||
global rtl8710_flasher_auto_erase
|
||||
global rtl8710_flasher_auto_verify
|
||||
global rtl8710_flasher_auto_erase_sector
|
||||
rtl8710_flasher_init
|
||||
set sector 0
|
||||
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 "write offset $flash_offset"
|
||||
rtl8710_flasher_load_block $local_filename $offset $len
|
||||
if {[expr {$rtl8710_flasher_auto_erase != 0}]} {
|
||||
for {set i $flash_offset} {$i < [expr {$flash_offset + $len}]} {incr i} {
|
||||
set sector [expr {$i / $rtl8710_flasher_sector_size}]
|
||||
if {[expr {$rtl8710_flasher_auto_erase_sector != $sector}]} {
|
||||
echo "erase sector $sector"
|
||||
rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}]
|
||||
set rtl8710_flasher_auto_erase_sector $sector
|
||||
}
|
||||
}
|
||||
}
|
||||
rtl8710_flasher_write_block $flash_offset $len
|
||||
echo "wrote $len bytes"
|
||||
if {[expr {$rtl8710_flasher_auto_verify != 0}]} {
|
||||
echo "verify offset $flash_offset"
|
||||
rtl8710_flasher_verify_block $flash_offset $len
|
||||
}
|
||||
}
|
||||
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} {
|
||||
if {$rtl8710_flasher_auto_erase_sector != $sector} {
|
||||
echo "erase sector $sector"
|
||||
rtl8710_flash_sector_erase [expr {$sector * $rtl8710_flasher_sector_size}]
|
||||
set rtl8710_flasher_auto_erase_sector $sector
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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} {
|
||||
@@ -306,43 +272,28 @@ proc rtl8710_flash_verify {local_filename loc} {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
proc rtl8710_flash_read_mac {} {
|
||||
global rtl8710_flasher_mac_address_offset
|
||||
global rtl8710_flasher_buffer
|
||||
rtl8710_flasher_init
|
||||
rtl8710_flasher_read_block $rtl8710_flasher_mac_address_offset 6
|
||||
set mac ""
|
||||
mem2array mac 8 [expr {$rtl8710_flasher_buffer + 0x20}] 6
|
||||
set res "MAC address: "
|
||||
append res [format %02X $mac(0)]
|
||||
append res ":" [format %02X $mac(1)]
|
||||
append res ":" [format %02X $mac(2)]
|
||||
append res ":" [format %02X $mac(3)]
|
||||
append res ":" [format %02X $mac(4)]
|
||||
append res ":" [format %02X $mac(5)]
|
||||
echo $res
|
||||
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
|
||||
if {[expr {$on != 0}]} {
|
||||
set rtl8710_flasher_auto_erase 1
|
||||
echo "auto erase on"
|
||||
} else {
|
||||
set rtl8710_flasher_auto_erase 0
|
||||
echo "auto erase off"
|
||||
}
|
||||
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
|
||||
if {[expr {$on != 0}]} {
|
||||
set rtl8710_flasher_auto_verify 1
|
||||
echo "auto verify on"
|
||||
} else {
|
||||
set rtl8710_flasher_auto_verify 0
|
||||
echo "auto verify off"
|
||||
}
|
||||
global rtl8710_flasher_auto_verify
|
||||
set rtl8710_flasher_auto_verify [expr {$on != 0}]
|
||||
echo "auto verify [expr {$on ? "on" : "off"}]"
|
||||
}
|
||||
|
||||
proc rtl8710_reboot {} {
|
||||
|
||||
Reference in New Issue
Block a user