-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash-loader.exp
executable file
·64 lines (50 loc) · 1.13 KB
/
flash-loader.exp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/expect
source vars.exp
log_user 0
set spawned [spawn -open [open $port w+]]
exec stty -f $port $baud raw -clocal -echo
set file [lindex $argv 0]
proc ledDisplayPrint {string} {
expect ">" {
send "m BA202070\r";
}
expect "BA202070" {
for {set i 0} {$i < 8} {incr i} {
sleep .01
send [format %4.4X [scan [string index $string $i] %c]]
send "\rFF\r"
}
send ".\r"
}
}
proc sendFile {filename} {
source vars.exp
scan $bootloader_addr %x offset
set addr 0
set len [file size $filename]
set start [clock milliseconds]
set fp [open $filename r]
chan configure $fp -translation binary
while {$addr < $len} {
send [scan [read $fp 1] %c]
incr addr
set now [clock milliseconds]
set percent [expr 100 * $addr / $len]
set rate [format %.2f [expr $addr / (($now - $start) / 1000.0)]]
send_user "$addr/$len bytes - $rate bytes/sec - $percent%\r"
}
close $fp
send ".\r"
send_user "\n"
}
send_user "Waiting for remote side…\n"
send "\r"
ledDisplayPrint "Flashing"
send_user "Sending $file…\n"
expect ">" {
send "lf\r"
}
sendFile $file
ledDisplayPrint " "
send_user "Done flashing."
#interact