summaryrefslogtreecommitdiff
path: root/config/i960.exp
blob: a743e506e3e4de308c073bbe0bfd5b9a5cae80cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# DejaGnu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

#
# Initialize the board on initial connection or after rebooting.
# Since the board autobauds, we have to be a bit aggressive about
# getting a valid prompt.
#
proc ${board}_init { dest } {
    global i960_try_count

    set prompt [board_info $dest shell_prompt]
    set done 0

    if {![info exists i960_try_count]} {
	set i960_try_count 1
    }

    remote_close $dest
    if { [remote_open $dest] != "" } {
	for { set tries 0 } { $tries < 7 && ! $done } { incr tries } {
	    remote_send $dest "\n"
	    remote_expect $dest 1 {
		-re "${prompt}" {
		    set done 1
		}
		-re ".+" { exp_continue }
		timeout { }
	    }
	}
    }

    remote_close $dest
    if { ! $done } {
	if { $i960_try_count == 3 } {
	    perror "Couldn't connect to board."
	} else {
	    incr i960_try_count
	    remote_close $dest
	    remote_reboot $dest
	}
    }
    if {[info exists i960_try_count]} {
	unset i960_try_count
    }
}

proc i960_ld { dest prog } {
    if {![file exists $prog]} {
	perror "$prog does not exist."
        return "untested"
    }
    set shell_prompt [board_info $dest shell_prompt]
    set strip [board_info $dest strip]
    set rprog [remote_download host $prog a.out]
    if { $strip != "" } {
	remote_exec host $strip $rprog
    }
    remote_upload host $rprog a.out

    set id [remote_open $dest]
    if { $id < 0 } {
	return -1
    }
    remote_binary $dest
    remote_send $dest "\n"
    remote_expect $dest 5 {
	-re $shell_prompt { }
    }
    remote_send $dest "do\n"
    remote_expect $dest 5 {
	-re "Downloading" { }
    }
    # Nasty.
    if { [board_info $dest connect] == "telnet" } {
	global board_info

	remote_close $dest
	set hp [split [board_info $dest netport] ":"]
	set host [lindex $hp 0]
	set port [lindex $hp 1]
	set status -1
	while { $status != 0 } {
	    set status [catch "socket $host $port" id2]
	    if { $status != 0 } {
		sleep 5
	    }
	}
    } else {
	set id2 [exp_open -leaveopen -i $id]
    }
    if {[catch "exec sx -bX a.out <@$id2 >@$id2 2>/dev/null" error]} {
	perror "exec sx failed: $error"
    }
    if { [board_info $dest connect] == "telnet" } {
	close $id2
	sleep 2
	remote_open $dest
	remote_binary $dest
    }
    set result 1
    remote_send $dest "\n"
    remote_expect $dest 1 {
	-re "$shell_prompt" {
	    set result 0
	    exp_continue
	}
	timeout { }
    }
    return $result
}

proc i960_spawn { dest prog args } {
    set shell_prompt [board_info $dest shell_prompt]

    for { set tries 0 } { $tries < 3 } { incr tries } {
	set result [remote_ld $dest $prog]
	if { $result == 0 } {
	    set comm "go [board_info $dest start_addr]"
	    remote_send $dest "$comm\n"
	    remote_expect $dest 10 {
		-re "$comm\[\r\n\]\[\r\n\]?" { }
		default { }
	    }
	    return [board_info $dest fileid]
	} else {
	    remote_reboot $dest
	}
    }
    return -1
}

proc i960_wait { dest timeout } {
    set output ""
    set shell_prompt [board_info $dest shell_prompt]
    set status -1

    remote_expect $dest $timeout {
	-re " fault at \[0-9a-h\]+, subtype \[0-9a-h\]+" {
	    set status -1
	    exp_continue
	}
	-re "(.*)(\[\r\n\]|^)Program Exit: (\[0-9\]+)\[\r\n\]" {
	    append output $expect_out(1,string)
	    set status $expect_out(3,string)
	    exp_continue
	}
	-re "(.*)$shell_prompt" {
	    append output $expect_out(1,string)
	    set bstatus [check_for_board_status output]
	    if { $bstatus >= 0 } {
		set status $bstatus
	    }
	}
	-re "\[\r\n\]+" {
	    # Sometimes the board goes wacky in the head, and we have
	    # to shoot it.
	    append output $expect_out(buffer)
	    if { [string length $output] < 512000 } {
		exp_continue
	    } else {
		set status -1
	    }
	}
	default {
	    set status -1
	}
    }
    return [list $status $output]
}

proc i960_load { dest prog args } {
    for { set x 0 } { $x < 3 } { incr x } {
	set id [eval remote_spawn \{$dest\} \{$prog\} $args]
	if { $id < 0 } {
	    return [list "fail" ""]
	}
	set result [remote_wait $dest 120]
	set status [lindex $result 0]
	set output [lindex $result 1]

	if { $status == 0 } {
	    return [list "pass" $output]
	} else {
	    global i960_retry

	    if { [board_info $dest exists unreliable] && ![info exists i960_retry] } {
		set i960_retry 1
		remote_reboot $dest
		set result [eval i960_load \{$dest\} \{$prog\} $args]
		unset i960_retry
		return $result
	    } else {
		if { $status < 0 } {
		    remote_reboot $dest
		}
		return [list "fail" $output]
	    }
	}
    }
}

set_board_info shell_prompt "=>"
set_board_info send_initial_cr 1
# We take care of getting a prompt in ${board}_init.
set_board_info dont_wait_for_prompt 1