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.
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
:
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
} {
30 set shell_prompt
[board_info $dest shell_prompt
]
32 if ![file
exists $prog
] then {
33 verbose
-log "$prog does not exist."
37 set prog
[remote_download host $prog
];
39 verbose
-log "Unable to download $prog to host.";
44 if [board_info $dest
exists objcopy
] {
45 set OBJCOPY
[board_info $dest objcopy
];
46 set exec_file
"${prog}.srec"
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"
60 verbose
"Converted $prog to an srecord." 2
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."
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
] {
87 #
if we built the srecord
on a remote host
, copy it
back here so we
91 set exec_file
[remote_upload host $
{exec_file
} "${objdir}/a.out"];
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}$" {
104 warning
"Never got prompt."
109 if { $tries
== 3 } then {
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
126 # Flush out
any remaining cruft.
127 remote_expect $dest
2 {
129 -re
".+" { exp_continue }
134 if [board_info $dest
exists download_command
] {
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."
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
] { }
152 perror
"Download command never responded."
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 } {
166 verbose
-log "Transmission of $exec_file to the target failed." 3
169 verbose
"Wrote records to target...waiting for prompt."
170 remote_send $dest
"\n"
172 remote_expect $dest
50 {
173 -re
"$shell_prompt$" {
174 verbose
"Got prompt."
180 # Flush
any remaining cruft.
2 seconds may be too long
, dunno.
181 remote_expect $dest
2 {
183 -re
".+" { exp_continue }
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]";
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
];
222 remote_expect $dest $timeout
{
223 -re
[board_info $dest go_response
] {
224 append output $expect_out
(buffer
);
227 exp_continue
-continue_timer
;
229 -re
"$shell_prompt$" {
230 verbose
"Got prompt.";
235 append output $expect_out
(buffer
);
236 if { [string length $output
] < 512000 } {
237 exp_continue
-continue_timer
;
244 warning
"Nothing ever came back.";
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]";
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
266 set status [check_for_board_status output
];
267 if { $result
== 0 } {
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 } {
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" } {
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.
307 return [list "fail" $output];
308 } elseif { $status == 0 } {
309 return [list "pass" $output];
311 if [info exists base68k_retry] {
312 return [list "fail" $output];
316 set status [eval base68k_load \{$dest\} \{$prog\} $args];
322 set_board_info protocol "base68k";
323 set_board_info send_initial_cr 1