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 526

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 522 jeremybenn
# The timeout is a mess. It seems to always be 10, not the timeout needed to
53
# execute a regression test (typicall 300 seconds). Fixed by using our onw
54
# timeout data.
55 473 jeremybenn
 
56 490 jeremybenn
# @param[in] hostname  The board we are telnetting to
57 473 jeremybenn
# @param[in] cmd        The command to run
58
# @param[in] args       Arguments to the command
59
 
60
# @return  A list of the return code (-1 on failure) and any error message.
61
# -----------------------------------------------------------------------------
62 490 jeremybenn
proc telnet_exec {hostname cmd args} {
63 453 jeremybenn
    global timeout
64 522 jeremybenn
    global verbos
65 453 jeremybenn
    set output "(no output)"
66
 
67 522 jeremybenn
    # Save the old timeout, since its global, and we'll want to restore it.
68
    set old_timeout $timeout
69
 
70 490 jeremybenn
    verbose "Executing $hostname $cmd $args"
71 453 jeremybenn
 
72 473 jeremybenn
    # Get the first argument, if any.
73 453 jeremybenn
    if { [llength $args] > 0 } {
74
        set pargs [lindex $args 0];
75
    } else {
76
        set pargs ""
77
    }
78
 
79 473 jeremybenn
    # Set the shell prompt
80 490 jeremybenn
    if [board_info $hostname exists shell_prompt] {
81
        set shell_prompt [board_info $hostname shell_prompt]
82 453 jeremybenn
    }
83
    if ![info exists shell_prompt] { # if no prompt, then set it to
84
        something generic
85
        set shell_prompt ".*> "
86
    }
87
 
88 473 jeremybenn
    # Start a new telnet session if one doesn't already exist. If sucessful
89 490 jeremybenn
    # the fileid field associated with $hostname will be set to the spawn_id
90 473 jeremybenn
    # of the new telnet process.
91 490 jeremybenn
    if ![board_info $hostname exists fileid] {
92
        if {[telnet_open $hostname] == -1} {
93 453 jeremybenn
            return [list -1
94 490 jeremybenn
                    "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
95 453 jeremybenn
        }
96
    }
97
 
98 522 jeremybenn
    # Make the telnet session the current process. Short timeout for this.
99 490 jeremybenn
    set spawn_id [board_info $hostname fileid]
100 522 jeremybenn
    set timeout 10
101 453 jeremybenn
 
102
    #Hit enter to make sure you get a shell prompt
103
    send -- "\r"
104
 
105
    expect {
106 473 jeremybenn
        # A prompt indicates the current session is alive
107 453 jeremybenn
        -re "$shell_prompt.*$" {
108
            verbose "Got a prompt"
109
        }
110
        default {
111 473 jeremybenn
            # No response try closing the connection and reopening.
112 490 jeremybenn
            telnet_close $hostname
113
            if {[telnet_open $hostname] != -1} {
114 453 jeremybenn
                verbose "started new telnet session, spawn_id is [board_info
115 490 jeremybenn
$hostname fileid]"
116 453 jeremybenn
                send -- "\r"
117
                exp_continue
118
            } else {
119 473 jeremybenn
                set timeout $old_timeout
120 490 jeremybenn
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get
121 453 jeremybenn
a shell prompt"]
122
            }
123 473 jeremybenn
            # I don't think we can get here. Comment out the old code and
124
            # trigger an error
125
            # send -- "\r"
126
            # exp_continue
127
            set timeout $old_timeout
128
            error "Problem reconnecting to telnet."
129 453 jeremybenn
        }
130
    }
131 473 jeremybenn
 
132 522 jeremybenn
    # JPB to set custom timeout. Old timeout saved, so we can restore it,
133
    # since it's global. Not sure why we only use the first of the arguments.
134
    if [board_info $hostname exists telnet_exec_timeout] {
135
        set timeout [board_info $hostname telnet_exec_timeout]
136
        verbose "Telnet exec timeout set to $timeout"
137
    } else {
138
        # Appropriate default
139
        set timeout 300
140
        verbose "Telnet exec timeout set to default value $timeout"
141
    }
142
 
143 453 jeremybenn
    send "$cmd $pargs\r"
144
 
145
    expect {
146
        -re "$shell_prompt.*$" {
147
        }
148
        timeout {
149
            if [info exists expect_out(buffer)] {
150
                set execute_output_string $expect_out(buffer)
151
            }
152 522 jeremybenn
            set timeout $old_timeout
153 490 jeremybenn
            telnet_close $hostname
154
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
155
        }
156 453 jeremybenn
    }
157 473 jeremybenn
 
158
    #Remove unnecessary strings from the output string
159
 
160 453 jeremybenn
    #If the file path contains any "+" signs, it will mess things up when $cmd
161
    #is used as a regsub pattern (2 lines down), so we replace all "+"s with "."
162
    regsub -all "\\+" $cmd "." cmd
163
    regsub -all $cmd "$expect_out(buffer)" {} output
164 524 jeremybenn
    regsub "\(~ \)?$shell_prompt" $output {} output
165 453 jeremybenn
    regsub -all "\[\r\n\]" $output {} output
166
 
167 490 jeremybenn
    #Check the return status. Use a short timeout for this.
168 453 jeremybenn
    set timeout 30
169
    send -- "echo \$?\r"
170
    expect -re "$shell_prompt.*$"
171
 
172
    #Regsub the output to get the status number
173
    regsub -all {echo \$\?} $expect_out(buffer) {} status
174 524 jeremybenn
    regsub "\(~ \)?$shell_prompt" $status {} status
175 453 jeremybenn
    regsub -all "\[\r\n \]" $status {} status
176
 
177
    #This probably isn't neccessary..
178
    if {[regexp {[0123456789]+} $status] != 1} {
179
        warning "status not a number, it is <$status>, setting it to 1"
180
        set status 1
181
    }
182
 
183 490 jeremybenn
    # Restore timeout
184 473 jeremybenn
    set timeout $old_timeout
185 453 jeremybenn
    if {$status == 0} {
186
        return [list "0" "$output"]
187
    } else {
188
        return [list "1" "$output"]
189
    }
190
}
191
 
192 490 jeremybenn
 
193
# -----------------------------------------------------------------------------
194
# For FTP we need to redefine some existing functions to add additional
195
# features.
196
 
197
# -----------------------------------------------------------------------------
198 522 jeremybenn
# Upload REMOTEFILE from HOST as LOCALFILE by FTP
199
 
200
# This version swaps the argument order, which is what the regression test
201
# seems to expect.
202
 
203
# Also allows a custom timeout to be set.
204
 
205
# @param[in] host        The host we are connected to.
206
# @param[in] localfile   The local file to send
207
# @param[in] remotefile  Name of file at remote end.
208
# -----------------------------------------------------------------------------
209
proc ftp_upload {host localfile remotefile} {
210
    set prompt "ftp>"
211
 
212
    verbose "ftping $remotefile from $host to $localfile"
213
 
214
    # JPB to set custom timeout (not marked global, so we don't need to save
215
    # and restore)
216
    if [board_info $host exists ftp_upload_timeout] {
217
        set timeout [board_info $host ftp_upload_timeout]
218
        verbose "FTP upload timeout set to $timeout"
219
    } else {
220
        # Appropriate default
221
        set timeout 15
222
        verbose "FTP upload timeout set to default value $timeout"
223
    }
224
 
225
    set spawn_id [ftp_open $host]
226
    if {$spawn_id < 0} {
227
        return ""
228
    }
229
    set loop 1
230
 
231
    while {$loop} {
232
        send -i $spawn_id "get $remotefile $localfile\n"
233
        expect {
234
            -i $spawn_id -re ".*Too many open files.*$prompt" {
235
                ftp_close $host
236
            }
237
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
238
                set loop 0
239
                set remotefile ""
240
            }
241
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {set loop 0}
242
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
243
                set loop 0
244
                set remotefile ""
245
            }
246
            -i $spawn_id default {
247
                ftp_close $host
248
            }
249
        }
250
        if {$loop} {
251
            set spawn_id [ftp_open $host]
252
            if {$spawn_id < 0} {
253
                return ""
254
            }
255
        }
256
    }
257
    return $localfile
258
}
259
 
260
 
261
# -----------------------------------------------------------------------------
262 490 jeremybenn
# Download LOCALFILE to HOST as REMOTEFILE by FTP
263 522 jeremybenn
 
264 490 jeremybenn
# This version takes a user specified timeout, which we need for our slow
265
# simulated connection.
266
 
267
# @param[in] host        The host we are connected to.
268
# @param[in] localfile   The local file to send
269
# @param[in] remotefile  Name of file at remote end.
270
# -----------------------------------------------------------------------------
271
proc ftp_download {host localfile remotefile} {
272
    set prompt "ftp>"
273
 
274
    verbose "putting $localfile $remotefile"
275
 
276
    if [board_info $host exists hostname] {
277
        set remotehost [board_info $host hostname]
278
    } else {
279
        set remotehost $host
280
    }
281
 
282
    set spawn_id [ftp_open $host]
283
    if {$spawn_id < 0} {
284
        return ""
285
    }
286
    set loop 1
287
 
288
    # JPB to set custom timeout (not marked global, so we don't need to save
289
    # and restore)
290
    if [board_info $host exists ftp_download_timeout] {
291
        set timeout [board_info $host ftp_download_timeout]
292
        verbose "FTP download timeout set to $timeout"
293 522 jeremybenn
    } else {
294
        # Appropriate default
295
        set timeout 15
296
        verbose "FTP download timeout set to default value $timeout"
297 490 jeremybenn
    }
298
 
299
    while {$loop} {
300
        send -i $spawn_id "put $localfile $remotefile\n"
301
        expect {
302
            -i $spawn_id -re ".*Too many open files.*$prompt" {
303
                ftp_close $host
304
            }
305
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
306
                set loop 0
307
                set remotefile ""
308
            }
309
            -re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" {
310
                set remotefile $expect_out(2,string)
311
                exp_continue
312
            }
313
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
314
                set loop 0
315
            }
316
            -i $spawn_id -re "Timeout.*$prompt" {
317
                ftp_close $host
318
            }
319
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
320
                set loop 0
321
                set remotefile ""
322
            }
323
            -i $spawn_id default {
324
                ftp_close $host
325
            }
326
        }
327
        if {$loop} {
328
            set spawn_id [ftp_open $host]
329
            if {$spawn_id < 0} {
330
                return ""
331
            }
332
        }
333
    }
334
    return $remotefile
335
}
336
 
337
 
338 473 jeremybenn
# This is a list of toolchains that are supported on this board.
339
set_board_info target_install {or32-linux}
340
 
341
# No multilib options needed by default.
342
process_multilib_options ""
343
 
344
# Load the generic configuration for this board. This will define a basic set
345
# of routines needed by the tool to communicate with the board.
346
load_generic_config "unix"
347
 
348 490 jeremybenn
# Set up remote target info. We select the IP address using an external
349
# program which knows about all available Linuxes.
350 522 jeremybenn
set linux_hostname [exec [file dirname $env(DEJAGNU)]/get-ip.sh --rotate]
351 490 jeremybenn
set_board_info hostname $linux_hostname
352 522 jeremybenn
send_user "OR32 target hostname is $linux_hostname\n"
353 490 jeremybenn
 
354 473 jeremybenn
set_board_info username root
355
 
356
# Use the installed compilers to ensure we get search paths that will find
357
# uClibc.
358
send_user "set_board_info compiler /opt/or32-new/bin/or32-linux-gcc\n"
359
global GCC_UNDER_TEST
360
set GCC_UNDER_TEST "/opt/or32-new/bin/or32-linux-gcc"
361
global GXX_UNDER_TEST
362
set GXX_UNDER_TEST "/opt/or32-new/bin/or32-linux-g++"
363
set_board_info compiler /opt/or32-new/bin/or32-linux-gcc
364
set_board_info c++compiler /opt/or32-new/bin/or32-linux-g++
365
set target_alias "or32-linux"
366
 
367
set_board_info connect telnet
368 522 jeremybenn
set_board_info shell_prompt          "# "
369
set_board_info telnet_username       "root"
370
set_board_info telnet_password       ""
371 524 jeremybenn
set_board_info telnet_exec_timeout   1200
372 473 jeremybenn
 
373 490 jeremybenn
set_board_info file_transfer         ftp
374
set_board_info ftp_username          root
375
set_board_info ftp_password          ""
376
set_board_info ftp_download_timeout  120
377 522 jeremybenn
set_board_info ftp_upload_timeout    120
378 473 jeremybenn
 
379 453 jeremybenn
# Options for the simulator
380
# set cfg_file [lookfor_file ${srcdir} libgloss/or32/sim.cfg]
381 490 jeremybenn
#set_board_info sim,options "-a \"-f ${cfg_file}\""
382 453 jeremybenn
 
383
# We only support uClibc on this target.  We assume that all multilib options
384
# have been specified before we get here.
385 490 jeremybenn
#set_board_info compiler  "[find_gcc]"
386 453 jeremybenn
 
387 522 jeremybenn
# We need to define this flag to generate default .gcda files if we are using
388
# a stock compiler, without the profopt.exp changes. No problem with doubling
389
# up the argument in normal circumstances.
390
set_board_info cflags    "-fprofile-dir=."
391
set_board_info cxxflags  "-fprofile-dir=."
392 473 jeremybenn
 
393 453 jeremybenn
# No linker script needed.
394
set_board_info ldscript ""
395
 
396
# This simulator isn't slow.
397
set_board_info slow_simulator 0
398
 
399
# Can't pass arguments to programs on this target..
400
set_board_info noargs  1
401
 
402
# Used by a few gcc.c-torture testcases to delimit how large the stack can
403
# be.
404
set_board_info gcc,stack_size 65536
405
 
406
# GDB options
407
 
408
# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
409
set_board_info gdb,noinferiorio 1
410
# Or pass arguments.
411
set_board_info gdb,noargs  1
412
set_board_info noargs 1
413
# And there's no support for signals.
414
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.