OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [dejagnu/] [config/] [base68k.exp] - Blame information for rev 1780

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 1994, 1996, 1997 Free Software Foundation, Inc.
2
 
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.
12
#
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.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# DejaGnu@cygnus.com
19
 
20
# This file was written by Bob Manson (manson@cygnus.com)
21
# based on earlier work by JT Conklin (jtc@cygnus.com)
22
 
23
#
24
# base68k_load -- load the program and execute it
25
#
26
 
27
proc base68k_ld { dest prog } {
28
    global tmpdir
29
 
30
    set shell_prompt [board_info $dest shell_prompt]
31
 
32
    if ![file exists $prog] then {
33
        verbose -log "$prog does not exist."
34
        return "untested"
35
    }
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";
41
        }
42
    }
43
 
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]";
50
        }
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
61
        }
62
    } else {
63
        set exec_file $prog
64
    }
65
 
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"
74
                }
75
                incr value;
76
            } else {
77
                break;
78
            }
79
        }
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;
84
        }
85
    }
86
 
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"];
92
    }
93
 
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;
102
            }
103
            timeout {
104
                warning "Never got prompt."
105
            }
106
        }
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"
113
                }
114
            }
115
        }
116
    }
117
 
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 { }
131
        }
132
    }
133
 
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."
142
            }
143
            timeout {
144
                warning "Never got prompt."
145
            }
146
        }
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";
154
                }
155
            }
156
        }
157
    }
158
 
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
163
    }
164
    if { $status != 0 } {
165
        remote_close $dest;
166
        verbose -log "Transmission of $exec_file to the target failed." 3
167
        return "unresolved"
168
    }
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;
176
        }
177
        timeout { }
178
    }
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 { }
185
        }
186
        return "pass";
187
    } else {
188
        remote_close $dest;
189
        remote_reboot $dest;
190
        return "unresolved";
191
    }
192
 
193
}
194
 
195
 
196
proc base68k_spawn { dest prog args } {
197
    set shell_prompt [board_info $dest shell_prompt];
198
 
199
    set result [remote_ld $dest $prog];
200
    if { $result != "pass" } {
201
        return [list $result ""];
202
    }
203
 
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]";
208
    }
209
 
210
    verbose "Sending $go_command, waiting for results.";
211
    remote_send $dest "${go_command}\n";
212
    return { "pass" "" };
213
}
214
 
215
proc base68k_wait { dest timeout } {
216
    set shell_prompt [board_info $dest shell_prompt];
217
    set noappend 0;
218
    set result -1;
219
 
220
    set output "";
221
 
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;
228
        }
229
        -re "$shell_prompt$" {
230
            verbose "Got prompt.";
231
            set result 0;
232
        }
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;
240
                }
241
            }
242
        }
243
        timeout {
244
            warning "Nothing ever came back.";
245
            set result -1;
246
        }
247
    }
248
 
249
    if [board_info $dest exists output_end] {
250
        regsub "[board_info $dest output_end]" "$output" "\n" output;
251
    }
252
 
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]";
259
    }
260
 
261
    regsub "^.*$go_command\[\r\n\]*" "$output" "" output;
262
    regsub "^.*$go_command\[\r\n\]*" "$output" "" output;
263
 
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";
270
    }
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"];
274
}
275
 
276
proc base68k_load { dest prog args } {
277
    global base68k_retry
278
 
279
    set shell_prompt [board_info $dest shell_prompt];
280
 
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" ""];
286
            }
287
        }
288
    }
289
 
290
    set result [remote_spawn $dest $prog];
291
    if { [lindex $result 0] != "pass" } {
292
        return $result;
293
    }
294
 
295
    # FIXME: The value 360 below should be a parameter.
296
 
297
    set result [remote_wait $dest 360];
298
    set output [lindex $result 1];
299
    set status [lindex $result 0];
300
 
301
    verbose "output from board is $output"
302
 
303
    # Make sure there's a newline before the PASS/FAIL/whatever for the log.
304
    send_log "\n"
305
 
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];
313
        }
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;
319
    }
320
}
321
 
322
set_board_info protocol "base68k";
323
set_board_info send_initial_cr 1

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.