aboutsummaryrefslogtreecommitdiff
path: root/config/ddb-ether.exp
blob: 2a469ba3fa9923f0f5aaa2a120164b211152c711 (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
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 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.

# This file was written by Bob Manson (manson@cygnus.com)

# Reset the prompt to what GDB needs.
proc ${board}_init { dest } {
    global doing_ddb_init

    if ![info exists doing_ddb_init] {
	set doing_ddb_init 1

	remote_close $dest
	for { set x 0 } { $x < 3 } { incr x } {
	    set shell_id [remote_open $dest]
	    if { $shell_id == "" || $shell_id < 0 } {
		remote_reboot $dest
	    } else {
		break
	    }
	}

	set shell_prompt [board_info $dest shell_prompt]

	remote_send $dest "\n"
	remote_expect $dest 10 {
	    -re ".*PMON> $" {
		remote_send $dest "set prompt \"$shell_prompt\"\n"
		exp_continue
	    }
	    -re ".*${shell_prompt}$" { }
	}
	remote_close $dest
	unset doing_ddb_init
    } else {
	return
    }
}

proc ddb_ether_load { dest prog args } {
    for { set x 0 } { $x < 3 } { incr x } {
	set result [eval remote_spawn \{$dest\} \{$prog\} $args]
	if { $result < 0 } {
	    remote_reboot $dest
	} else {
	    set result [remote_wait $dest 300]
	    set status [lindex $result 0]
	    set output [lindex $result 1]
	    if { $status >= 0 } {
		if { $status > 0 } {
		    return [list "fail" $output]
		} else {
		    return [list "pass" $output]
		}
	    }
	}
    }
    return [list "fail" ""]
}

proc ddb_ether_ld { dest prog } {
    if ![board_info $dest exists tftpdir] {
	perror "Must set_board_info tftpdir for [board_info $dest name]"
	return "fail"
    }

    if ![board_info $dest exists fileid] {
	set spawn_id [remote_open $dest]
	if { $spawn_id == "" || $spawn_id < 0 } {
	    return "retry"
	}
	remote_binary $dest
    }

    set shell_prompt [board_info $dest shell_prompt]

    remote_send $dest "\n"
    remote_expect $dest 10 {
	-re ".*${shell_prompt}$" { }
	default {
	    return "retry"
	}
    }
    set basename "a.out.[pid]"
    set file "[board_info $dest tftpdir]/$basename"
    set file [remote_download build $prog $file]
    if { $file == "" } {
	perror "download to tftp area failed"
	return "fail"
    }
    set state "pass"

    remote_send $dest "boot /$basename\n"
    set tries 0
    remote_expect $dest 30 {
	-re "Loading.*Entry address is.*${shell_prompt}$" { }
	-re "invalid executable.*${shell_prompt}$" {
	    incr tries
	    if { $tries < 3 } {
		sleep 2
		remote_send $dest "boot /$basename\n"
		exp_continue
	    }
	}
	-re ".*${shell_prompt}$" {
	    set state "fail"
	}
	default {
	    set state "fail"
	}
    }
    remote_file build delete $file
    if { $state == "fail" } {
	return $state
    }
    return "pass"
}

proc ddb_ether_spawn { dest prog args } {
    set state [ddb_ether_ld $dest $prog]

    if { $state != "pass" } {
	return -1
    }
    remote_send $dest "g\n"
    remote_expect $dest 5 {
	-re "g\[\r\n\]\[\r\n\]?" { }
	default { }
    }

    return [board_info $dest fileid]
}

proc ddb_ether_wait { dest timeout } {
    set output ""
    set shell_prompt [board_info $dest shell_prompt]

    remote_expect $dest $timeout {
	-re "^g\[\r\n\]\[\r\n\]?" {
	    if { $output != "" } {
		append output $expect_out(buffer)
	    }
	    exp_continue
	}
	-re "(.*)$shell_prompt" {
	    append output $expect_out(1,string)
	    set status [check_for_board_status output]
	    if { $status > 0 } {
		return [list $status $output]
	    } else {
		if [regexp "Exception Cause=" $output] {
		    remote_reboot $dest
		    return [list -1 $output]
		}
		return [list 0 $output]
	    }
	}
	-re "\[\r\n\]+" {
	    append output $expect_out(buffer)
	    if { [string length $output] < 512000 } {
		exp_continue
	    } else {
		return [list -1 ""]
	    }
	}
	default {
	    return [list -1 ""]
	}
    }
}

set_board_info send_initial_cr 1
set_board_info protocol "ddb_ether"
set_board_info shell_prompt "NEC010> "