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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [dejagnu/] [config/] [i960.exp] - Blame information for rev 1765

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

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

powered by: WebSVN 2.1.0

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