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 552

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