OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [boards/] [or32-linux-sim.exp] - Blame information for rev 493

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

Line No. Rev Author Line
1 453 jeremybenn
#!/bin/bash
2
 
3
# Copyright (C) 2010 Embecosm Limited
4
 
5
# Contributor Jeremy Bennett 
6
# Contributor Joern Rennecke 
7
 
8
# This file is a board description for testing OpenRISC with uClibc and
9
# Or1ksim running Linux.
10
 
11
# This program is free software; you can redistribute it and/or modify it
12
# under the terms of the GNU General Public License as published by the Free
13
# Software Foundation; either version 3 of the License, or (at your option)
14
# any later version.
15
 
16
# This program is distributed in the hope that it will be useful, but WITHOUT
17
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
# more details.
20
 
21
# You should have received a copy of the GNU General Public License along
22
# with this program.  If not, see .
23
 
24 473 jeremybenn
# -----------------------------------------------------------------------------
25
# For telnet targets we need to define some functions.
26 453 jeremybenn
 
27 473 jeremybenn
# -----------------------------------------------------------------------------
28
# Custom proc to close a telnet session
29 453 jeremybenn
 
30 473 jeremybenn
# @param[in] boardname  The board being closed.
31
# -----------------------------------------------------------------------------
32 490 jeremybenn
proc telnet_close {hostname} {
33 453 jeremybenn
 
34 490 jeremybenn
    # Get the connected host name, if it exists (actually, we think this can
35
    # never be set, but it is for consistency with telnet_open
36
    if {[board_info $hostname exists name]} {
37
        set connhost [board_info $hostname name]
38
    } else {
39
        set connhost $hostname
40
    }
41 453 jeremybenn
 
42 490 jeremybenn
    # Use the standard close proc from remote.exp
43
    standard_close $hostname
44 453 jeremybenn
}
45
 
46
 
47 473 jeremybenn
# -----------------------------------------------------------------------------
48 453 jeremybenn
# Custom proc to exec programs using telnet
49 473 jeremybenn
 
50
# We seem to only pass in the first of the arguments supplied to the command.
51
 
52
# We seem to set the timeout to 30, no matter what. Not sure that is right
53
# here.
54
 
55 490 jeremybenn
# @param[in] hostname  The board we are telnetting to
56 473 jeremybenn
# @param[in] cmd        The command to run
57
# @param[in] args       Arguments to the command
58
 
59
# @return  A list of the return code (-1 on failure) and any error message.
60
# -----------------------------------------------------------------------------
61 490 jeremybenn
proc telnet_exec {hostname cmd args} {
62 453 jeremybenn
    global timeout
63
    global verbose
64
    set output "(no output)"
65
 
66 490 jeremybenn
    verbose "Executing $hostname $cmd $args"
67 453 jeremybenn
 
68 473 jeremybenn
    # Get the first argument, if any.
69 453 jeremybenn
    if { [llength $args] > 0 } {
70
        set pargs [lindex $args 0];
71
    } else {
72
        set pargs ""
73
    }
74
 
75 473 jeremybenn
    # Set the shell prompt
76 490 jeremybenn
    if [board_info $hostname exists shell_prompt] {
77
        set shell_prompt [board_info $hostname shell_prompt]
78 453 jeremybenn
    }
79
    if ![info exists shell_prompt] { # if no prompt, then set it to
80
        something generic
81
        set shell_prompt ".*> "
82
    }
83
 
84 473 jeremybenn
    # Start a new telnet session if one doesn't already exist. If sucessful
85 490 jeremybenn
    # the fileid field associated with $hostname will be set to the spawn_id
86 473 jeremybenn
    # of the new telnet process.
87 490 jeremybenn
    if ![board_info $hostname exists fileid] {
88
        if {[telnet_open $hostname] == -1} {
89 453 jeremybenn
            return [list -1
90 490 jeremybenn
                    "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
91 453 jeremybenn
        }
92
    }
93
 
94 473 jeremybenn
    # Make the telnet session the current process.
95 490 jeremybenn
    set spawn_id [board_info $hostname fileid]
96 473 jeremybenn
    set old_timeout $timeout
97 453 jeremybenn
    set timeout 30
98
 
99
    #Hit enter to make sure you get a shell prompt
100
    send -- "\r"
101
 
102
    expect {
103 473 jeremybenn
        # A prompt indicates the current session is alive
104 453 jeremybenn
        -re "$shell_prompt.*$" {
105
            verbose "Got a prompt"
106
        }
107
        default {
108 473 jeremybenn
            # No response try closing the connection and reopening.
109 490 jeremybenn
            telnet_close $hostname
110
            if {[telnet_open $hostname] != -1} {
111 453 jeremybenn
                verbose "started new telnet session, spawn_id is [board_info
112 490 jeremybenn
$hostname fileid]"
113 453 jeremybenn
                send -- "\r"
114
                exp_continue
115
            } else {
116 473 jeremybenn
                set timeout $old_timeout
117 490 jeremybenn
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get
118 453 jeremybenn
a shell prompt"]
119
            }
120 473 jeremybenn
            # I don't think we can get here. Comment out the old code and
121
            # trigger an error
122
            # send -- "\r"
123
            # exp_continue
124
            set timeout $old_timeout
125
            error "Problem reconnecting to telnet."
126 453 jeremybenn
        }
127
    }
128 473 jeremybenn
 
129 490 jeremybenn
    # Restore timeout for commands. Not sure why we only use the first of the
130 473 jeremybenn
    # arguments.
131 490 jeremybenn
    set timeout $old_timeout
132 453 jeremybenn
    send "$cmd $pargs\r"
133
 
134
    expect {
135
        -re "$shell_prompt.*$" {
136
        }
137
        timeout {
138
            if [info exists expect_out(buffer)] {
139
                set execute_output_string $expect_out(buffer)
140
            }
141 490 jeremybenn
            telnet_close $hostname
142
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
143
        }
144 453 jeremybenn
    }
145 473 jeremybenn
 
146
    #Remove unnecessary strings from the output string
147
 
148 453 jeremybenn
    #If the file path contains any "+" signs, it will mess things up when $cmd
149
    #is used as a regsub pattern (2 lines down), so we replace all "+"s with "."
150
    regsub -all "\\+" $cmd "." cmd
151
    regsub -all $cmd "$expect_out(buffer)" {} output
152
    regsub $shell_prompt $output {} output
153
    regsub -all "\[\r\n\]" $output {} output
154
 
155 490 jeremybenn
    #Check the return status. Use a short timeout for this.
156 453 jeremybenn
    set timeout 30
157
    send -- "echo \$?\r"
158
    expect -re "$shell_prompt.*$"
159
 
160
    #Regsub the output to get the status number
161
    regsub -all {echo \$\?} $expect_out(buffer) {} status
162
    regsub $shell_prompt $status {} status
163
    regsub -all "\[\r\n \]" $status {} status
164
 
165
    #This probably isn't neccessary..
166
    if {[regexp {[0123456789]+} $status] != 1} {
167
        warning "status not a number, it is <$status>, setting it to 1"
168
        set status 1
169
    }
170
 
171 490 jeremybenn
    # Restore timeout
172 473 jeremybenn
    set timeout $old_timeout
173 453 jeremybenn
    if {$status == 0} {
174
        return [list "0" "$output"]
175
    } else {
176
        return [list "1" "$output"]
177
    }
178
}
179
 
180 490 jeremybenn
 
181
# -----------------------------------------------------------------------------
182
# For FTP we need to redefine some existing functions to add additional
183
# features.
184
 
185
# -----------------------------------------------------------------------------
186
# Download LOCALFILE to HOST as REMOTEFILE by FTP
187
#
188
# This version takes a user specified timeout, which we need for our slow
189
# simulated connection.
190
 
191
# @param[in] host        The host we are connected to.
192
# @param[in] localfile   The local file to send
193
# @param[in] remotefile  Name of file at remote end.
194
# -----------------------------------------------------------------------------
195
proc ftp_download {host localfile remotefile} {
196
    set prompt "ftp>"
197
 
198
    verbose "putting $localfile $remotefile"
199
 
200
    if [board_info $host exists hostname] {
201
        set remotehost [board_info $host hostname]
202
    } else {
203
        set remotehost $host
204
    }
205
 
206
    set spawn_id [ftp_open $host]
207
    if {$spawn_id < 0} {
208
        return ""
209
    }
210
    set loop 1
211
 
212
    # JPB to set custom timeout (not marked global, so we don't need to save
213
    # and restore)
214
    if [board_info $host exists ftp_download_timeout] {
215
        set timeout [board_info $host ftp_download_timeout]
216
        verbose "FTP download timeout set to $timeout"
217
    }
218
 
219
    while {$loop} {
220
        send -i $spawn_id "put $localfile $remotefile\n"
221
        expect {
222
            -i $spawn_id -re ".*Too many open files.*$prompt" {
223
                ftp_close $host
224
            }
225
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
226
                set loop 0
227
                set remotefile ""
228
            }
229
            -re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" {
230
                set remotefile $expect_out(2,string)
231
                exp_continue
232
            }
233
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
234
                set loop 0
235
            }
236
            -i $spawn_id -re "Timeout.*$prompt" {
237
                ftp_close $host
238
            }
239
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
240
                set loop 0
241
                set remotefile ""
242
            }
243
            -i $spawn_id default {
244
                ftp_close $host
245
            }
246
        }
247
        if {$loop} {
248
            set spawn_id [ftp_open $host]
249
            if {$spawn_id < 0} {
250
                return ""
251
            }
252
        }
253
    }
254
    return $remotefile
255
}
256
 
257
 
258 473 jeremybenn
# This is a list of toolchains that are supported on this board.
259
set_board_info target_install {or32-linux}
260
 
261
# No multilib options needed by default.
262
process_multilib_options ""
263
 
264
# Load the generic configuration for this board. This will define a basic set
265
# of routines needed by the tool to communicate with the board.
266
load_generic_config "unix"
267
 
268 490 jeremybenn
# Set up remote target info. We select the IP address using an external
269
# program which knows about all available Linuxes.
270
set linux_hostname [exec [file dirname $env(DEJAGNU)]/get-ip.sh]
271
set_board_info hostname $linux_hostname
272
send_user "OR32 target hostname is $linux_hostname"
273
 
274 473 jeremybenn
set_board_info username root
275
 
276
# Use the installed compilers to ensure we get search paths that will find
277
# uClibc.
278
send_user "set_board_info compiler /opt/or32-new/bin/or32-linux-gcc\n"
279
global GCC_UNDER_TEST
280
set GCC_UNDER_TEST "/opt/or32-new/bin/or32-linux-gcc"
281
global GXX_UNDER_TEST
282
set GXX_UNDER_TEST "/opt/or32-new/bin/or32-linux-g++"
283
set_board_info compiler /opt/or32-new/bin/or32-linux-gcc
284
set_board_info c++compiler /opt/or32-new/bin/or32-linux-g++
285
set target_alias "or32-linux"
286
 
287
set_board_info connect telnet
288 490 jeremybenn
set_board_info shell_prompt    "# "
289 473 jeremybenn
set_board_info telnet_username "root"
290
set_board_info telnet_password ""
291
 
292 490 jeremybenn
set_board_info file_transfer         ftp
293
set_board_info ftp_username          root
294
set_board_info ftp_password          ""
295
set_board_info ftp_download_timeout  120
296 473 jeremybenn
 
297 453 jeremybenn
# Options for the simulator
298
# set cfg_file [lookfor_file ${srcdir} libgloss/or32/sim.cfg]
299 490 jeremybenn
#set_board_info sim,options "-a \"-f ${cfg_file}\""
300 453 jeremybenn
 
301
# We only support uClibc on this target.  We assume that all multilib options
302
# have been specified before we get here.
303 490 jeremybenn
#set_board_info compiler  "[find_gcc]"
304 453 jeremybenn
 
305 473 jeremybenn
# We need to define the right flags if pthreads is to work.
306 490 jeremybenn
# set_board_info cflags    "-D_XOPEN_SOURCE=600"
307
# set_board_info cxxflags  "-D_XOPEN_SOURCE=600"
308 473 jeremybenn
 
309 453 jeremybenn
# No linker script needed.
310
set_board_info ldscript ""
311
 
312
# This simulator isn't slow.
313
set_board_info slow_simulator 0
314
 
315
# Can't pass arguments to programs on this target..
316
set_board_info noargs  1
317
 
318
# Used by a few gcc.c-torture testcases to delimit how large the stack can
319
# be.
320
set_board_info gcc,stack_size 65536
321
 
322
# GDB options
323
 
324
# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
325
set_board_info gdb,noinferiorio 1
326
# Or pass arguments.
327
set_board_info gdb,noargs  1
328
set_board_info noargs 1
329
# And there's no support for signals.
330
set_board_info gdb,nosignals  1

powered by: WebSVN 2.1.0

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