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 554

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

powered by: WebSVN 2.1.0

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