* Makefile.am: Add an empty check-DEJAGNU target, cause we only
[dejagnu.git] / config / base68k.exp
blobca0afb22f184ab64bf5cf507107ba73ffba1ca19
1 # Copyright (C) 1994 - 2001 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@gnu.org
20 # This file was written by Bob Manson (manson@cygnus.com)
21 # based on earlier work by JT Conklin (jtc@cygnus.com)
24 # base68k_load -- load the program and execute it
27 proc base68k_ld { dest prog } {
28 global tmpdir
30 set shell_prompt [board_info $dest shell_prompt]
32 if ![file exists $prog] then {
33 verbose -log "$prog does not exist."
34 return "untested"
36 if [is_remote host] {
37 set prog [remote_download host $prog];
38 if { $prog == "" } {
39 verbose -log "Unable to download $prog to host.";
40 return "untested";
44 if [board_info $dest exists objcopy] {
45 set OBJCOPY [board_info $dest objcopy];
46 set exec_file "${prog}.srec"
47 set objcopy_args ""
48 if [board_info $dest exists use_vma_offset] {
49 set objcopy_args "--adjust-vma=[board_info $dest hex_startaddr]";
51 set status [remote_exec host "$OBJCOPY $objcopy_args -O srec $prog ${prog}.srec"]
52 set result [lindex $status 1];
53 regsub -all -- "\[\r\n\]*" $result "" result
54 if { $result != "" || [lindex $status 0] != 0 } {
55 warning "Got \"$result\" from $OBJCOPY"
56 verbose -log "Couldn't convert to srecord for downloading"
57 remote_close $dest;
58 return "untested"
59 } else {
60 verbose "Converted $prog to an srecord." 2
62 } else {
63 set exec_file $prog
66 set value 0;
67 if ![board_info $dest exists fileid] {
68 while { $value < 2 } {
69 set rom68k_shell_id [remote_open $dest]
70 if { $rom68k_shell_id < 0 } {
71 if { $value > 0 || ![remote_reboot $dest] } {
72 verbose -log "$prog not executed, couldn't connect to target."
73 return "untested"
75 incr value;
76 } else {
77 break;
80 # dbug has problems if we go into binary mode, so this allows us to
81 # disable entry into binary mode.
82 if ![board_info $dest exists no_binary_mode] {
83 remote_binary $dest;
87 # if we built the srecord on a remote host, copy it back here so we
88 # can load it
89 if [is_remote host] {
90 global objdir
91 set exec_file [remote_upload host ${exec_file} "${objdir}/a.out"];
94 set got_p 0;
95 for { set tries 0; } { (! $got_p) && $tries < 5 } { incr tries } {
96 remote_send $dest "\r\n\r\n"
97 remote_expect $dest 5 {
98 -re "${shell_prompt}$" {
99 verbose "Got prompt."
100 set result 0
101 set got_p 1;
103 timeout {
104 warning "Never got prompt."
107 if { ! $got_p } {
108 if $tries<=4 then {
109 if { $tries == 3 } then {
110 remote_reboot $dest;
111 } else {
112 remote_send $dest "\r\n"
118 # We need to do this in case the connection to the remote side is
119 # scrogged -- the remote_expect above will fail in a lot of
120 # non-clean ways.
121 if { ! $got_p } {
122 remote_close $dest;
123 remote_reboot $dest;
124 return "unresolved";
125 } else {
126 # Flush out any remaining cruft.
127 remote_expect $dest 2 {
128 timeout { }
129 -re ".+" { exp_continue }
130 default { }
134 if [board_info $dest exists download_command] {
135 # Load the program.
136 remote_send $dest "\r\n";
137 # dbug has problems sending download command immediately after a
138 # newline, so we wait for the prompt to come back first.
139 remote_expect $dest 5 {
140 -re "${shell_prompt}$" {
141 verbose -log "Got prompt."
143 timeout {
144 warning "Never got prompt."
147 remote_send $dest [board_info $dest download_command]
148 if [board_info $dest exists download_response] {
149 remote_expect $dest 5 {
150 [board_info $dest download_response] { }
151 timeout {
152 perror "Download command never responded."
153 return "unresolved";
159 verbose "Writing records to target..."
160 set status [remote_transmit $dest $exec_file];
161 if { $exec_file != $prog } {
162 remote_file build delete $exec_file
164 if { $status != 0 } {
165 remote_close $dest;
166 verbose -log "Transmission of $exec_file to the target failed." 3
167 return "unresolved"
169 verbose "Wrote records to target...waiting for prompt."
170 remote_send $dest "\n"
171 set got_p 0;
172 remote_expect $dest 50 {
173 -re "$shell_prompt$" {
174 verbose "Got prompt."
175 set got_p 1;
177 timeout { }
179 if { $got_p } {
180 # Flush any remaining cruft. 2 seconds may be too long, dunno.
181 remote_expect $dest 2 {
182 timeout { }
183 -re ".+" { exp_continue }
184 default { }
186 return "pass";
187 } else {
188 remote_close $dest;
189 remote_reboot $dest;
190 return "unresolved";
196 proc base68k_spawn { dest prog args } {
197 set shell_prompt [board_info $dest shell_prompt];
199 set result [remote_ld $dest $prog];
200 if { $result != "pass" } {
201 return [list $result ""];
204 if [board_info $dest exists startaddr] {
205 set go_command "[board_info $dest go_command] [board_info $dest startaddr]";
206 } else {
207 set go_command "[board_info $dest go_command]";
210 verbose "Sending $go_command, waiting for results.";
211 remote_send $dest "${go_command}\n";
212 return { "pass" "" };
215 proc base68k_wait { dest timeout } {
216 set shell_prompt [board_info $dest shell_prompt];
217 set noappend 0;
218 set result -1;
220 set output "";
222 remote_expect $dest $timeout {
223 -re [board_info $dest go_response] {
224 append output $expect_out(buffer);
225 set noappend 1;
226 set result 0;
227 exp_continue -continue_timer;
229 -re "$shell_prompt$" {
230 verbose "Got prompt.";
231 set result 0;
233 -re "\[\r\n\]+" {
234 if { ! $noappend } {
235 append output $expect_out(buffer);
236 if { [string length $output] < 512000 } {
237 exp_continue -continue_timer;
238 } else {
239 set result -1;
243 timeout {
244 warning "Nothing ever came back.";
245 set result -1;
249 if [board_info $dest exists output_end] {
250 regsub "[board_info $dest output_end]" "$output" "\n" output;
253 # There has got to be a better way. (We need to do this in order to remove
254 # the echoed "go command".
255 if [board_info $dest exists startaddr] {
256 set go_command "[board_info $dest go_command] [board_info $dest startaddr]";
257 } else {
258 set go_command "[board_info $dest go_command]";
261 regsub "^.*$go_command\[\r\n\]*" "$output" "" output;
262 regsub "^.*$go_command\[\r\n\]*" "$output" "" output;
264 # We always want to check for a status, even if there was a funky weird
265 # failure above.
266 set status [check_for_board_status output];
267 if { $result == 0 } {
268 set result $status;
269 verbose -log "exit status was $status";
271 # A negative value indicates that we should reboot. Otherwise, return
272 # the exit status from the program if we got one (and we should have).
273 return [list $result "$output"];
276 proc base68k_load { dest prog args } {
277 global base68k_retry
279 set shell_prompt [board_info $dest shell_prompt];
281 if { [llength $args] > 0 } {
282 for { set x 0; } { $x < [llength $args] } { incr x ; } {
283 if { [lindex $args $x] != "" } {
284 verbose -log "Cannot pass parameters or input file to this target";
285 return [list "unsupported" ""];
290 set result [remote_spawn $dest $prog];
291 if { [lindex $result 0] != "pass" } {
292 return $result;
295 # FIXME: The value 360 below should be a parameter.
297 set result [remote_wait $dest 360];
298 set output [lindex $result 1];
299 set status [lindex $result 0];
301 verbose "output from board is $output"
303 # Make sure there's a newline before the PASS/FAIL/whatever for the log.
304 send_log "\n"
306 if { $status > 0 } {
307 return [list "fail" $output];
308 } elseif { $status == 0 } {
309 return [list "pass" $output];
310 } else {
311 if [info exists base68k_retry] {
312 return [list "fail" $output];
314 set base68k_retry 1;
315 remote_reboot $dest;
316 set status [eval base68k_load \{$dest\} \{$prog\} $args];
317 unset base68k_retry;
318 return $status;
322 set_board_info protocol "base68k";
323 set_board_info send_initial_cr 1