23 |
# getting a valid prompt. |
# getting a valid prompt. |
24 |
# |
# |
25 |
proc ${board}_init { dest } { |
proc ${board}_init { dest } { |
26 |
global i960_try_count; |
global i960_try_count |
27 |
|
|
28 |
set prompt [board_info $dest shell_prompt]; |
set prompt [board_info $dest shell_prompt] |
29 |
set done 0; |
set done 0 |
30 |
|
|
31 |
if ![info exists i960_try_count] { |
if ![info exists i960_try_count] { |
32 |
set i960_try_count 1; |
set i960_try_count 1 |
33 |
} |
} |
34 |
|
|
35 |
remote_close $dest; |
remote_close $dest |
36 |
if { [remote_open $dest] != "" } { |
if { [remote_open $dest] != "" } { |
37 |
for { set tries 0; } { $tries < 7 && ! $done } { incr tries } { |
for { set tries 0; } { $tries < 7 && ! $done } { incr tries } { |
38 |
remote_send $dest "\n"; |
remote_send $dest "\n" |
39 |
remote_expect $dest 1 { |
remote_expect $dest 1 { |
40 |
-re "${prompt}" { |
-re "${prompt}" { |
41 |
set done 1; |
set done 1 |
42 |
} |
} |
43 |
-re ".+" { exp_continue } |
-re ".+" { exp_continue } |
44 |
timeout { } |
timeout { } |
46 |
} |
} |
47 |
} |
} |
48 |
|
|
49 |
remote_close $dest; |
remote_close $dest |
50 |
if { ! $done } { |
if { ! $done } { |
51 |
if { $i960_try_count == 3 } { |
if { $i960_try_count == 3 } { |
52 |
perror "Couldn't connect to board."; |
perror "Couldn't connect to board." |
53 |
} else { |
} else { |
54 |
incr i960_try_count; |
incr i960_try_count |
55 |
remote_close $dest; |
remote_close $dest |
56 |
remote_reboot $dest; |
remote_reboot $dest |
57 |
} |
} |
58 |
} |
} |
59 |
if [info exists i960_try_count] { |
if [info exists i960_try_count] { |
60 |
unset i960_try_count; |
unset i960_try_count |
61 |
} |
} |
62 |
} |
} |
63 |
|
|
66 |
perror "$prog does not exist." |
perror "$prog does not exist." |
67 |
return "untested" |
return "untested" |
68 |
} |
} |
69 |
set shell_prompt [board_info $dest shell_prompt]; |
set shell_prompt [board_info $dest shell_prompt] |
70 |
set strip [board_info $dest strip]; |
set strip [board_info $dest strip] |
71 |
set rprog [remote_download host $prog a.out]; |
set rprog [remote_download host $prog a.out] |
72 |
if { $strip != "" } { |
if { $strip != "" } { |
73 |
remote_exec host $strip $rprog; |
remote_exec host $strip $rprog |
74 |
} |
} |
75 |
remote_upload host $rprog a.out; |
remote_upload host $rprog a.out |
76 |
|
|
77 |
set id [remote_open $dest]; |
set id [remote_open $dest] |
78 |
if { $id < 0 } { |
if { $id < 0 } { |
79 |
return -1; |
return -1 |
80 |
} |
} |
81 |
remote_binary $dest; |
remote_binary $dest |
82 |
remote_send $dest "\n"; |
remote_send $dest "\n" |
83 |
remote_expect $dest 5 { |
remote_expect $dest 5 { |
84 |
-re $shell_prompt { } |
-re $shell_prompt { } |
85 |
} |
} |
86 |
remote_send $dest "do\n"; |
remote_send $dest "do\n" |
87 |
remote_expect $dest 5 { |
remote_expect $dest 5 { |
88 |
-re "Downloading" { } |
-re "Downloading" { } |
89 |
} |
} |
90 |
# Nasty. |
# Nasty. |
91 |
if { [board_info $dest connect] == "telnet" } { |
if { [board_info $dest connect] == "telnet" } { |
92 |
global board_info; |
global board_info |
93 |
|
|
94 |
remote_close $dest; |
remote_close $dest |
95 |
set hp [split [board_info $dest netport] ":"]; |
set hp [split [board_info $dest netport] ":"] |
96 |
set host [lindex $hp 0]; |
set host [lindex $hp 0] |
97 |
set port [lindex $hp 1]; |
set port [lindex $hp 1] |
98 |
set status -1; |
set status -1 |
99 |
while { $status != 0 } { |
while { $status != 0 } { |
100 |
set status [catch "socket $host $port" id2]; |
set status [catch "socket $host $port" id2] |
101 |
if { $status != 0 } { |
if { $status != 0 } { |
102 |
sleep 5; |
sleep 5 |
103 |
} |
} |
104 |
} |
} |
105 |
} else { |
} else { |
106 |
set id2 [exp_open -leaveopen -i $id]; |
set id2 [exp_open -leaveopen -i $id] |
107 |
} |
} |
108 |
if [catch "exec sx -bX a.out <@$id2 >@$id2 2>/dev/null" error] { |
if [catch "exec sx -bX a.out <@$id2 >@$id2 2>/dev/null" error] { |
109 |
perror "exec sx failed: $error" |
perror "exec sx failed: $error" |
110 |
} |
} |
111 |
if { [board_info $dest connect] == "telnet" } { |
if { [board_info $dest connect] == "telnet" } { |
112 |
close $id2; |
close $id2 |
113 |
sleep 2; |
sleep 2 |
114 |
remote_open $dest; |
remote_open $dest |
115 |
remote_binary $dest; |
remote_binary $dest |
116 |
} |
} |
117 |
set result 1; |
set result 1 |
118 |
remote_send $dest "\n"; |
remote_send $dest "\n" |
119 |
remote_expect $dest 1 { |
remote_expect $dest 1 { |
120 |
-re "$shell_prompt" { |
-re "$shell_prompt" { |
121 |
set result 0; |
set result 0 |
122 |
exp_continue; |
exp_continue |
123 |
} |
} |
124 |
timeout { } |
timeout { } |
125 |
} |
} |
126 |
return $result; |
return $result |
127 |
} |
} |
128 |
|
|
129 |
proc i960_spawn { dest prog args } { |
proc i960_spawn { dest prog args } { |
130 |
set shell_prompt [board_info $dest shell_prompt]; |
set shell_prompt [board_info $dest shell_prompt] |
131 |
|
|
132 |
for { set tries 0 ; } { $tries < 3 } { incr tries } { |
for { set tries 0 ; } { $tries < 3 } { incr tries } { |
133 |
set result [remote_ld $dest $prog]; |
set result [remote_ld $dest $prog] |
134 |
if { $result == 0 } { |
if { $result == 0 } { |
135 |
set comm "go [board_info $dest start_addr]"; |
set comm "go [board_info $dest start_addr]" |
136 |
remote_send $dest "$comm\n"; |
remote_send $dest "$comm\n" |
137 |
remote_expect $dest 10 { |
remote_expect $dest 10 { |
138 |
-re "$comm\[\r\n\]\[\r\n\]?" { } |
-re "$comm\[\r\n\]\[\r\n\]?" { } |
139 |
default { } |
default { } |
140 |
} |
} |
141 |
return [board_info $dest fileid]; |
return [board_info $dest fileid] |
142 |
} else { |
} else { |
143 |
remote_reboot $dest; |
remote_reboot $dest |
144 |
} |
} |
145 |
} |
} |
146 |
return -1; |
return -1 |
147 |
} |
} |
148 |
|
|
149 |
proc i960_wait { dest timeout } { |
proc i960_wait { dest timeout } { |
150 |
set output ""; |
set output "" |
151 |
set shell_prompt [board_info $dest shell_prompt]; |
set shell_prompt [board_info $dest shell_prompt] |
152 |
|
|
153 |
remote_expect $dest $timeout { |
remote_expect $dest $timeout { |
154 |
-re " fault at \[0-9a-h\]+, subtype \[0-9a-h\]+" { |
-re " fault at \[0-9a-h\]+, subtype \[0-9a-h\]+" { |
155 |
set status -1; |
set status -1 |
156 |
exp_continue; |
exp_continue |
157 |
} |
} |
158 |
-re "(.*)(\[\r\n\]|^)Program Exit: (\[0-9\]+)\[\r\n\]" { |
-re "(.*)(\[\r\n\]|^)Program Exit: (\[0-9\]+)\[\r\n\]" { |
159 |
append output $expect_out(1,string); |
append output $expect_out(1,string) |
160 |
set status $expect_out(3,string); |
set status $expect_out(3,string) |
161 |
exp_continue; |
exp_continue |
162 |
} |
} |
163 |
-re "(.*)$shell_prompt" { |
-re "(.*)$shell_prompt" { |
164 |
append output $expect_out(1,string); |
append output $expect_out(1,string) |
165 |
set bstatus [check_for_board_status output]; |
set bstatus [check_for_board_status output] |
166 |
if { $bstatus >= 0 } { |
if { $bstatus >= 0 } { |
167 |
set status $bstatus; |
set status $bstatus |
168 |
} |
} |
169 |
} |
} |
170 |
-re "\[\r\n\]+" { |
-re "\[\r\n\]+" { |
171 |
# Sometimes the board goes wacky in the head, and we have |
# Sometimes the board goes wacky in the head, and we have |
172 |
# to shoot it. |
# to shoot it. |
173 |
append output $expect_out(buffer); |
append output $expect_out(buffer) |
174 |
if { [string length $output] < 512000 } { |
if { [string length $output] < 512000 } { |
175 |
exp_continue; |
exp_continue |
176 |
} else { |
} else { |
177 |
set status -1; |
set status -1 |
178 |
} |
} |
179 |
} |
} |
180 |
default { |
default { |
181 |
set status -1; |
set status -1 |
182 |
} |
} |
183 |
} |
} |
184 |
return [list $status $output]; |
return [list $status $output] |
185 |
} |
} |
186 |
|
|
187 |
proc i960_load { dest prog args } { |
proc i960_load { dest prog args } { |
188 |
for { set x 0; } { $x < 3 } { incr x; } { |
for { set x 0; } { $x < 3 } { incr x; } { |
189 |
set id [eval remote_spawn \{$dest\} \{$prog\} $args]; |
set id [eval remote_spawn \{$dest\} \{$prog\} $args] |
190 |
if { $id < 0 } { |
if { $id < 0 } { |
191 |
return [list "fail" ""]; |
return [list "fail" ""] |
192 |
} |
} |
193 |
set result [remote_wait $dest 120]; |
set result [remote_wait $dest 120] |
194 |
set status [lindex $result 0]; |
set status [lindex $result 0] |
195 |
set output [lindex $result 1]; |
set output [lindex $result 1] |
196 |
|
|
197 |
if { $status == 0 } { |
if { $status == 0 } { |
198 |
return [list "pass" $output]; |
return [list "pass" $output] |
199 |
} else { |
} else { |
200 |
global i960_retry; |
global i960_retry |
201 |
|
|
202 |
if { [board_info $dest exists unreliable] && ![info exists i960_retry] } { |
if { [board_info $dest exists unreliable] && ![info exists i960_retry] } { |
203 |
set i960_retry 1; |
set i960_retry 1 |
204 |
remote_reboot $dest; |
remote_reboot $dest |
205 |
set result [eval i960_load \{$dest\} \{$prog\} $args]; |
set result [eval i960_load \{$dest\} \{$prog\} $args] |
206 |
unset i960_retry; |
unset i960_retry |
207 |
return $result; |
return $result |
208 |
} else { |
} else { |
209 |
if { $status < 0 } { |
if { $status < 0 } { |
210 |
remote_reboot $dest; |
remote_reboot $dest |
211 |
} |
} |
212 |
return [list "fail" $output]; |
return [list "fail" $output] |
213 |
} |
} |
214 |
} |
} |
215 |
} |
} |
216 |
} |
} |
217 |
|
|
218 |
set_board_info shell_prompt "=>"; |
set_board_info shell_prompt "=>" |
219 |
set_board_info send_initial_cr 1; |
set_board_info send_initial_cr 1 |
220 |
# We take care of getting a prompt in ${board}_init. |
# We take care of getting a prompt in ${board}_init. |
221 |
set_board_info dont_wait_for_prompt 1; |
set_board_info dont_wait_for_prompt 1 |