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 556

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 553 jeremybenn
# @param[in] connhost  The connected host being closed.
31
# -----------------------------------------------------------------------------
32
proc telnet_close {connhost} {
33
 
34
    verbose "telnet_close: connhost $connhost" 3
35
 
36
    # Use the standard close proc from remote.exp
37
    standard_close $connhost
38
}
39
 
40
 
41
# -----------------------------------------------------------------------------
42
# Custom proc to check if we have had too many failures
43
 
44 473 jeremybenn
# @param[in] boardname  The board being closed.
45
# -----------------------------------------------------------------------------
46 553 jeremybenn
proc telnet_failure_check { connhost errmess } {
47 555 jeremybenn
    global board_info
48 453 jeremybenn
 
49 553 jeremybenn
    # Get the maximum failure count
50
    set max_fc 10
51 548 jeremybenn
 
52 553 jeremybenn
    if [board_info $connhost exists max_failure_count] {
53
        set max_fc [board_info $connhost max_failure_count]
54 490 jeremybenn
    }
55 553 jeremybenn
    verbose "telnet_failure_check: Max failure count $max_fc"
56 453 jeremybenn
 
57 553 jeremybenn
    # Increment the current failure count
58
    set fc 1
59
    if [board_info $connhost exists failure_count] {
60
        verbose "telnet_failure_check: Incrementing failure count"
61
        set fc [expr [board_info $connhost failure_count] + 1]
62 548 jeremybenn
    }
63 553 jeremybenn
    set board_info($connhost,failure_count) $fc
64 554 jeremybenn
    verbose "telnet_failure_check: current failure count is $fc"
65 548 jeremybenn
 
66 553 jeremybenn
    # Die if we are over the limit
67
    if {$fc >= $max_fc} {
68
        error "Too many failures: $errmess"
69
    }
70 453 jeremybenn
}
71
 
72
 
73 473 jeremybenn
# -----------------------------------------------------------------------------
74 453 jeremybenn
# Custom proc to exec programs using telnet
75 473 jeremybenn
 
76
# We seem to only pass in the first of the arguments supplied to the command.
77
 
78 522 jeremybenn
# The timeout is a mess. It seems to always be 10, not the timeout needed to
79 555 jeremybenn
# execute a regression test (typicall 300 seconds). Fixed by not making it
80
# global and using our own timeout data.
81 473 jeremybenn
 
82 553 jeremybenn
# It also seems that only the first argument is passed.
83
 
84 490 jeremybenn
# @param[in] hostname  The board we are telnetting to
85 473 jeremybenn
# @param[in] cmd        The command to run
86
# @param[in] args       Arguments to the command
87
 
88
# @return  A list of the return code (-1 on failure) and any error message.
89
# -----------------------------------------------------------------------------
90 490 jeremybenn
proc telnet_exec {hostname cmd args} {
91 453 jeremybenn
    global timeout
92 555 jeremybenn
    global board_info
93 553 jeremybenn
    global verbose
94
    global spawn_id
95 453 jeremybenn
 
96 553 jeremybenn
    # Get the connected host name, if it exists. This code matches
97
    # telnet_open.
98
    verbose "telnet_exec: original hostname is $hostname"
99 522 jeremybenn
 
100 553 jeremybenn
    if {[board_info $hostname exists name]} {
101
        set connhost [board_info $hostname name]
102
    } else {
103
        set connhost $hostname
104
    }
105
    verbose "telnet_exec: connhost is $connhost"
106 453 jeremybenn
 
107 553 jeremybenn
    if [board_info $connhost exists hostname] {
108
        set hostname [board_info $connhost hostname]
109
    }
110
    verbose "telnet_exec: hostname is $hostname"
111
 
112 473 jeremybenn
    # Get the first argument, if any.
113 453 jeremybenn
    if { [llength $args] > 0 } {
114
        set pargs [lindex $args 0];
115
    } else {
116
        set pargs ""
117
    }
118
 
119 553 jeremybenn
    verbose "telnet_exec: executing on $connhost, command \"$cmd\", pargs \"$pargs\""
120
 
121
    # Just check if we have more args. Potentially a second arg is an input
122
    # file.
123
    if { [llength $args] > 1 } {
124
        set tinp [lindex $args 1]
125
        if {$tinp != {}} {
126
            verbose "telnet_exec: long args: $args"
127
        }
128
    }
129
 
130 473 jeremybenn
    # Set the shell prompt
131 553 jeremybenn
    if [board_info $connhost exists shell_prompt] {
132
        set shell_prompt [board_info $connhost shell_prompt]
133
    } elseif ![info exists shell_prompt] {
134
        # if no prompt, then set it to something generic
135
        set shell_prompt "\[^\r\n\]*\[$#\] "
136 453 jeremybenn
    }
137
 
138 473 jeremybenn
    # Start a new telnet session if one doesn't already exist. If sucessful
139 553 jeremybenn
    # the fileid field associated with $connhost will be set to the spawn_id
140 473 jeremybenn
    # of the new telnet process.
141 553 jeremybenn
    if ![board_info $connhost exists fileid] {
142
        if {[telnet_open $connhost] == -1} {
143
            return [list -1 "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
144 453 jeremybenn
        }
145
    }
146
 
147 555 jeremybenn
    # Save the timeout. It's a global, which we shall mess about with, and
148
    # restore on exit.
149
    set timeout_orig timeout
150
 
151 522 jeremybenn
    # Make the telnet session the current process. Short timeout for this.
152 553 jeremybenn
    set spawn_id [board_info $connhost fileid]
153
    set timeout 30
154 453 jeremybenn
 
155
    #Hit enter to make sure you get a shell prompt
156 553 jeremybenn
    send "\r"
157 453 jeremybenn
 
158
    expect {
159 473 jeremybenn
        # A prompt indicates the current session is alive
160 553 jeremybenn
        -re "$shell_prompt" {
161
            verbose "telnet_exec: got prompt at start"
162 453 jeremybenn
        }
163
        default {
164 553 jeremybenn
            # Timeout or EOF. Die if we have had too many failures
165
            telnet_failure_check $connhost "no prompt at telnet start"
166
 
167
            # Try closing the connection and reopening.
168
            telnet_close $connhost
169
            if {[telnet_open $connhost] != -1} {
170
                set spawn_id [board_info $connhost fileid]
171
                verbose "telnet_exec: new telnet session, spawn_id: $spawn_id"
172
                send "\r"
173 453 jeremybenn
                exp_continue
174
            } else {
175 555 jeremybenn
                set timeout timeout_orig
176 553 jeremybenn
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get a shell prompt"]
177 453 jeremybenn
            }
178
        }
179
    }
180 473 jeremybenn
 
181 553 jeremybenn
    # Send the command. We can't cope with any input, so only the first
182
    # argument (group) is sent.
183
    send "$cmd $pargs\r"
184
 
185
    # We really should get the command echoed back immediately. This is a good
186
    # way of slurping up unexpected prompts. We first swap out any characters
187
    # from the command and args that might cause us grief.
188
    regsub -all "\\+" "$cmd $pargs" "." cmdpargs
189 555 jeremybenn
    verbose "telnet_exec: command match string is \"$cmdpargs\""
190 553 jeremybenn
 
191
    expect {
192 555 jeremybenn
        -re "$cmdpargs" {
193 553 jeremybenn
            verbose "telnet_exec: got command echoed back"
194
        }
195 555 jeremybenn
        default {
196
            verbose "telnet_exec: command not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
197
        }
198 553 jeremybenn
    }
199
 
200 555 jeremybenn
    # Set the telnet command custom timeout to wait for the command to
201
    # complete executing.
202 553 jeremybenn
    if [board_info $connhost exists telnet_exec_timeout] {
203
        set timeout [board_info $connhost telnet_exec_timeout]
204
        verbose "telnet_exec: command timeout set to $timeout"
205 522 jeremybenn
    } else {
206
        # Appropriate default
207
        set timeout 300
208 553 jeremybenn
        verbose "telnet_exec: command timeout set to default value $timeout"
209 522 jeremybenn
    }
210
 
211 453 jeremybenn
    expect {
212 553 jeremybenn
        -re "$shell_prompt" {
213
            verbose "telnet_exec: got prompt after command"
214 453 jeremybenn
        }
215 553 jeremybenn
        default {
216
            # Give up on timeout or EOF
217
            telnet_close $connhost
218 555 jeremybenn
            set timeout timeout_orig
219 490 jeremybenn
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
220
        }
221 453 jeremybenn
    }
222 473 jeremybenn
 
223 553 jeremybenn
    # Remove unnecessary strings from the output string
224
    verbose "telnet_exec: command expect_out(buffer): \"$expect_out(buffer)\""
225
    regsub -all $cmdpargs "$expect_out(buffer)" {} output
226
    regsub "$shell_prompt" $output {} output
227 453 jeremybenn
    regsub -all "\[\r\n\]" $output {} output
228
 
229 553 jeremybenn
    if {$output == ""} {
230
        set output "(no output)"
231
    } else {
232
        set output "\"$output\""
233
    }
234
 
235
    verbose "telnet_exec: command output $output"
236
 
237 555 jeremybenn
    # Check the return status. Use a short timeout for this and following
238
    # commands.
239 453 jeremybenn
    set timeout 30
240 553 jeremybenn
    send "echo \$?\r"
241 453 jeremybenn
 
242 553 jeremybenn
    # Once again, look for the "echo" reflected back as a way of slurping up
243
    # unexpected prompts. We don't worry about timeout here - we'll sort that
244 555 jeremybenn
    # out later.
245 553 jeremybenn
    expect {
246
        -re "echo \\$\\?" {
247
            verbose "telnet_exec: got \"echo\" echoed back"
248
        }
249 555 jeremybenn
        default {
250
            verbose "telnet_exec: echo not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
251
        }
252 553 jeremybenn
    }
253
 
254 555 jeremybenn
    # Look for the shell prompt. Don't worry about timeout for now. It only
255
    # really matters if we don't get a valid status, which we'll discover
256
    # below.
257 553 jeremybenn
    expect {
258
        -re "$shell_prompt" {
259
            verbose "telnet_exec: got status shell prompt"
260
        }
261
        default {
262 555 jeremybenn
            verbose "telnet_exec: no status shell prompt: command expect_out(buffer): \"$expect_out(buffer)\""
263 553 jeremybenn
        }
264
    }
265
 
266
    # Regsub the output to get the status number
267
    verbose "telnet_exec: status expect_out(buffer): \"$expect_out(buffer)\""
268 453 jeremybenn
    regsub -all {echo \$\?} $expect_out(buffer) {} status
269 553 jeremybenn
    regsub "$shell_prompt" $status {} status
270 453 jeremybenn
    regsub -all "\[\r\n \]" $status {} status
271 553 jeremybenn
    verbose "telnet_exec: status \"$status\""
272 453 jeremybenn
 
273 553 jeremybenn
    # This shouldn't be neccessary...
274 453 jeremybenn
    if {[regexp {[0123456789]+} $status] != 1} {
275 553 jeremybenn
        warning "status not a number (\"$status\"), setting to 1"
276
        verbose "telnet_exec: status (\"$status\"), expect_out(buffer): \"$expect_out(buffer)\""
277 453 jeremybenn
        set status 1
278 553 jeremybenn
 
279
        # Die if we have had too many failures like this.
280
        telnet_failure_check $connhost "bad status"
281 453 jeremybenn
    }
282
 
283 555 jeremybenn
    set timeout timeout_orig
284 453 jeremybenn
    if {$status == 0} {
285
        return [list "0" "$output"]
286
    } else {
287
        return [list "1" "$output"]
288
    }
289
}
290
 
291 490 jeremybenn
 
292
# -----------------------------------------------------------------------------
293
# For FTP we need to redefine some existing functions to add additional
294
# features.
295
 
296
# -----------------------------------------------------------------------------
297 522 jeremybenn
# Upload REMOTEFILE from HOST as LOCALFILE by FTP
298
 
299
# This version swaps the argument order, which is what the regression test
300
# seems to expect.
301
 
302
# Also allows a custom timeout to be set.
303
 
304
# @param[in] host        The host we are connected to.
305
# @param[in] localfile   The local file to send
306
# @param[in] remotefile  Name of file at remote end.
307
# -----------------------------------------------------------------------------
308
proc ftp_upload {host localfile remotefile} {
309 555 jeremybenn
    global board_info
310
 
311 522 jeremybenn
    set prompt "ftp>"
312
    verbose "ftping $remotefile from $host to $localfile"
313
 
314
    # JPB to set custom timeout (not marked global, so we don't need to save
315
    # and restore)
316
    if [board_info $host exists ftp_upload_timeout] {
317
        set timeout [board_info $host ftp_upload_timeout]
318
        verbose "FTP upload timeout set to $timeout"
319
    } else {
320
        # Appropriate default
321
        set timeout 15
322
        verbose "FTP upload timeout set to default value $timeout"
323
    }
324
 
325
    set spawn_id [ftp_open $host]
326
    if {$spawn_id < 0} {
327
        return ""
328
    }
329
    set loop 1
330
 
331
    while {$loop} {
332
        send -i $spawn_id "get $remotefile $localfile\n"
333
        expect {
334
            -i $spawn_id -re ".*Too many open files.*$prompt" {
335
                ftp_close $host
336
            }
337
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
338
                set loop 0
339
                set remotefile ""
340
            }
341
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {set loop 0}
342
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
343
                set loop 0
344
                set remotefile ""
345
            }
346
            -i $spawn_id default {
347
                ftp_close $host
348
            }
349
        }
350
        if {$loop} {
351
            set spawn_id [ftp_open $host]
352
            if {$spawn_id < 0} {
353
                return ""
354
            }
355
        }
356
    }
357
    return $localfile
358
}
359
 
360
 
361
# -----------------------------------------------------------------------------
362 490 jeremybenn
# Download LOCALFILE to HOST as REMOTEFILE by FTP
363 522 jeremybenn
 
364 490 jeremybenn
# This version takes a user specified timeout, which we need for our slow
365
# simulated connection.
366
 
367
# @param[in] host        The host we are connected to.
368
# @param[in] localfile   The local file to send
369
# @param[in] remotefile  Name of file at remote end.
370
# -----------------------------------------------------------------------------
371
proc ftp_download {host localfile remotefile} {
372 555 jeremybenn
    global board_info
373
 
374 490 jeremybenn
    set prompt "ftp>"
375
 
376
    verbose "putting $localfile $remotefile"
377
 
378
    if [board_info $host exists hostname] {
379
        set remotehost [board_info $host hostname]
380
    } else {
381
        set remotehost $host
382
    }
383
 
384
    set spawn_id [ftp_open $host]
385
    if {$spawn_id < 0} {
386
        return ""
387
    }
388
    set loop 1
389
 
390
    # JPB to set custom timeout (not marked global, so we don't need to save
391
    # and restore)
392
    if [board_info $host exists ftp_download_timeout] {
393
        set timeout [board_info $host ftp_download_timeout]
394
        verbose "FTP download timeout set to $timeout"
395 522 jeremybenn
    } else {
396
        # Appropriate default
397
        set timeout 15
398
        verbose "FTP download timeout set to default value $timeout"
399 490 jeremybenn
    }
400
 
401
    while {$loop} {
402
        send -i $spawn_id "put $localfile $remotefile\n"
403
        expect {
404
            -i $spawn_id -re ".*Too many open files.*$prompt" {
405
                ftp_close $host
406
            }
407
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
408
                set loop 0
409
                set remotefile ""
410
            }
411
            -re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" {
412
                set remotefile $expect_out(2,string)
413
                exp_continue
414
            }
415
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
416
                set loop 0
417
            }
418
            -i $spawn_id -re "Timeout.*$prompt" {
419
                ftp_close $host
420
            }
421
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
422
                set loop 0
423
                set remotefile ""
424
            }
425
            -i $spawn_id default {
426
                ftp_close $host
427
            }
428
        }
429
        if {$loop} {
430
            set spawn_id [ftp_open $host]
431
            if {$spawn_id < 0} {
432
                return ""
433
            }
434
        }
435
    }
436
    return $remotefile
437
}
438
 
439
 
440 473 jeremybenn
# This is a list of toolchains that are supported on this board.
441
set_board_info target_install {or32-linux}
442
 
443
# No multilib options needed by default.
444
process_multilib_options ""
445
 
446
# Load the generic configuration for this board. This will define a basic set
447
# of routines needed by the tool to communicate with the board.
448
load_generic_config "unix"
449
 
450 490 jeremybenn
# Set up remote target info. We select the IP address using an external
451
# program which knows about all available Linuxes.
452 522 jeremybenn
set linux_hostname [exec [file dirname $env(DEJAGNU)]/get-ip.sh --rotate]
453 490 jeremybenn
set_board_info hostname $linux_hostname
454 522 jeremybenn
send_user "OR32 target hostname is $linux_hostname\n"
455 490 jeremybenn
 
456 473 jeremybenn
set_board_info username root
457
 
458
# Use the installed compilers to ensure we get search paths that will find
459
# uClibc.
460
send_user "set_board_info compiler /opt/or32-new/bin/or32-linux-gcc\n"
461
global GCC_UNDER_TEST
462
set GCC_UNDER_TEST "/opt/or32-new/bin/or32-linux-gcc"
463
global GXX_UNDER_TEST
464
set GXX_UNDER_TEST "/opt/or32-new/bin/or32-linux-g++"
465
set_board_info compiler /opt/or32-new/bin/or32-linux-gcc
466
set_board_info c++compiler /opt/or32-new/bin/or32-linux-g++
467
set target_alias "or32-linux"
468
 
469
set_board_info connect telnet
470 553 jeremybenn
set_board_info shell_prompt          "\[^\r\n\]*# "
471 522 jeremybenn
set_board_info telnet_username       "root"
472
set_board_info telnet_password       ""
473 524 jeremybenn
set_board_info telnet_exec_timeout   1200
474 473 jeremybenn
 
475 490 jeremybenn
set_board_info file_transfer         ftp
476
set_board_info ftp_username          root
477
set_board_info ftp_password          ""
478
set_board_info ftp_download_timeout  120
479 522 jeremybenn
set_board_info ftp_upload_timeout    120
480 473 jeremybenn
 
481 453 jeremybenn
# Options for the simulator
482
# set cfg_file [lookfor_file ${srcdir} libgloss/or32/sim.cfg]
483 490 jeremybenn
#set_board_info sim,options "-a \"-f ${cfg_file}\""
484 453 jeremybenn
 
485
# We only support uClibc on this target.  We assume that all multilib options
486
# have been specified before we get here.
487 490 jeremybenn
#set_board_info compiler  "[find_gcc]"
488 453 jeremybenn
 
489 522 jeremybenn
# We need to define this flag to generate default .gcda files if we are using
490
# a stock compiler, without the profopt.exp changes. No problem with doubling
491
# up the argument in normal circumstances.
492
set_board_info cflags    "-fprofile-dir=."
493
set_board_info cxxflags  "-fprofile-dir=."
494 473 jeremybenn
 
495 453 jeremybenn
# No linker script needed.
496
set_board_info ldscript ""
497
 
498
# This simulator isn't slow.
499
set_board_info slow_simulator 0
500
 
501
# Can't pass arguments to programs on this target..
502
set_board_info noargs  1
503
 
504
# Used by a few gcc.c-torture testcases to delimit how large the stack can
505
# be.
506
set_board_info gcc,stack_size 65536
507
 
508
# GDB options
509
 
510
# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
511
set_board_info gdb,noinferiorio 1
512
# Or pass arguments.
513
set_board_info gdb,noargs  1
514
set_board_info noargs 1
515
# And there's no support for signals.
516
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.